From patchwork Fri May 18 22:25:34 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Vorontsov X-Patchwork-Id: 8824 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 7171923EB5 for ; Fri, 18 May 2012 22:27:06 +0000 (UTC) Received: from mail-yw0-f52.google.com (mail-yw0-f52.google.com [209.85.213.52]) by fiordland.canonical.com (Postfix) with ESMTP id 3BA96A18340 for ; Fri, 18 May 2012 22:27:06 +0000 (UTC) Received: by mail-yw0-f52.google.com with SMTP id p61so4113203yhp.11 for ; Fri, 18 May 2012 15:27:06 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-forwarded-to:x-forwarded-for:delivered-to:received-spf:date:from :to:cc:subject:message-id:references:mime-version:content-type :content-disposition:in-reply-to:user-agent:x-gm-message-state; bh=1/A/SwA+rNpzpjBr5Z87dJPSrxD4bnCMRBuv85zxsgE=; b=E0SbUkIhCUHzFmggwRY/mvQYCtpQzDa5+xDBMLCGWpQ/6Ju6B9RGQUYiClMDFEwAuv PCHb0u7Fzb/7Eu5QNKVO89nYuHDATRpxheC/BUjd6N/A0/rRGLwesotUBxV9fDlTH/dQ u0T6kq8tPUTSFDHG4zpCQ72ZbWKAW3BAgXfTqUNb2Mdjtq/K4uZEK7NH6o8QpwcuaHB7 hrQCj/PnTn9QzPw3NQk15Bjw6mnOIx6XNdNkoR4AvD85Jvk6ctXm4/WXkdiM2dNlH+XL EOtJiZ7wNFCQEGb0XsC6Q8bfGnfCcmdDIpeJFi3LRGBc4/2K1DEmusyhrz0FvAXDaBLt fAzQ== Received: by 10.50.195.234 with SMTP id ih10mr2105788igc.0.1337380025731; Fri, 18 May 2012 15:27:05 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.231.35.72 with SMTP id o8csp135301ibd; Fri, 18 May 2012 15:27:05 -0700 (PDT) Received: by 10.68.125.199 with SMTP id ms7mr594981pbb.54.1337380025054; Fri, 18 May 2012 15:27:05 -0700 (PDT) Received: from mail-pz0-f50.google.com (mail-pz0-f50.google.com [209.85.210.50]) by mx.google.com with ESMTPS id pm1si9712546pbc.68.2012.05.18.15.27.04 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 18 May 2012 15:27:05 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.210.50 is neither permitted nor denied by best guess record for domain of anton.vorontsov@linaro.org) client-ip=209.85.210.50; Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.210.50 is neither permitted nor denied by best guess record for domain of anton.vorontsov@linaro.org) smtp.mail=anton.vorontsov@linaro.org Received: by mail-pz0-f50.google.com with SMTP id h15so5258947dan.37 for ; Fri, 18 May 2012 15:27:04 -0700 (PDT) Received: by 10.68.238.228 with SMTP id vn4mr42952705pbc.132.1337380023799; Fri, 18 May 2012 15:27:03 -0700 (PDT) Received: from localhost (c-71-204-165-222.hsd1.ca.comcast.net. [71.204.165.222]) by mx.google.com with ESMTPS id mt9sm14136247pbb.14.2012.05.18.15.27.01 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 18 May 2012 15:27:02 -0700 (PDT) Date: Fri, 18 May 2012 15:25:34 -0700 From: Anton Vorontsov To: Greg Kroah-Hartman , Kees Cook , Colin Cross , Tony Luck Cc: Arnd Bergmann , John Stultz , Shuah Khan , arve@android.com, Rebecca Schultz Zavin , Jesper Juhl , Randy Dunlap , Stephen Boyd , Thomas Meyer , Andrew Morton , Marco Stornelli , WANG Cong , linux-kernel@vger.kernel.org, devel@driverdev.osuosl.org, linaro-kernel@lists.linaro.org, patches@linaro.org, kernel-team@android.com Subject: [PATCH 08/14] pstore/ram: Factor ramoops_get_dump_prz() out of ramoops_pstore_read() Message-ID: <20120518222534.GH23089@lizard> References: <20120518222314.GA9425@lizard> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20120518222314.GA9425@lizard> User-Agent: Mutt/1.5.21 (2010-09-15) X-Gm-Message-State: ALoCoQknlB/9DPKivjMd8iSOUWiyfH7jJ+ALa68bC5zlqSp5PRTRiCQvTjtyWAnSZs9prg1WqF/+ This will help make code clearer when we'll add support for other message types. The patch also changes return value from -EINVAL to 0 in case of end-of-records. The exact value doesn't matter for pstore (it should be just <= 0), but 0 feels more correct. Signed-off-by: Anton Vorontsov --- fs/pstore/ram.c | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/fs/pstore/ram.c b/fs/pstore/ram.c index db0e118..54e0676 100644 --- a/fs/pstore/ram.c +++ b/fs/pstore/ram.c @@ -86,6 +86,24 @@ static int ramoops_pstore_open(struct pstore_info *psi) return 0; } +static struct persistent_ram_zone * +ramoops_get_dump_prz(u64 id, enum pstore_type_id *type, + struct ramoops_context *cxt) +{ + struct persistent_ram_zone *prz; + + if (id > cxt->max_dump_count) + return NULL; + + prz = cxt->przs[id]; + if (!persistent_ram_old_size(prz)) + return NULL; + + *type = PSTORE_TYPE_DMESG; + + return prz; +} + static ssize_t ramoops_pstore_read(u64 *id, enum pstore_type_id *type, struct timespec *time, char **buf, @@ -95,14 +113,12 @@ static ssize_t ramoops_pstore_read(u64 *id, enum pstore_type_id *type, struct ramoops_context *cxt = psi->data; struct persistent_ram_zone *prz; - if (cxt->read_count >= cxt->max_dump_count) - return -EINVAL; - *id = cxt->read_count++; - prz = cxt->przs[*id]; - /* Only supports dmesg output so far. */ - *type = PSTORE_TYPE_DMESG; + prz = ramoops_get_dump_prz(*id, type, cxt); + if (!prz) + return 0; + /* TODO(kees): Bogus time for the moment. */ time->tv_sec = 0; time->tv_nsec = 0;