From patchwork Tue May 22 14:17:52 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Vorontsov X-Patchwork-Id: 8879 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 07F7023F0A for ; Tue, 22 May 2012 14:20:39 +0000 (UTC) Received: from mail-yx0-f180.google.com (mail-yx0-f180.google.com [209.85.213.180]) by fiordland.canonical.com (Postfix) with ESMTP id CC1E0A18B74 for ; Tue, 22 May 2012 14:20:38 +0000 (UTC) Received: by mail-yx0-f180.google.com with SMTP id q6so6633932yen.11 for ; Tue, 22 May 2012 07:20:38 -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:from:to:cc :subject:date:message-id:x-mailer:in-reply-to:references :x-gm-message-state; bh=gzXXxCjy3/2ZWIpJ3TXxey3ldn6fVCSJXuXj0wk3z7M=; b=XZJJgah/Ah9boQ1dxJpAWu2oVMk/IEr8XyIli8K8w6neADJmEKPcBlrb0l3rOBYzf5 c2HcIT9tBGLZ7erA8hKkGT+FyA/bgd7gPN0V+cpNcnBrj5FNb5miYgvt9hfNMtXIK4aZ wIF1aXfZKrI8yCNNbpOvEj4gRfFvtkJJvPfFVPP15xCikpdGuZPW7JA3fOSFRlObwTRg LQZzxRb6ecanjCTgFkNd79YmktKmMH1N6WZZVxu1kGjmOeMJhyNp3qVPjODU7pdbka8F 9rqSBFPMM8TfL+KUmpgsktqoQ8ejCygIWGw7qzioDF/UGoHACsLZ7JQp9YU6xDlYPaq7 W+Ug== Received: by 10.50.154.169 with SMTP id vp9mr9594008igb.53.1337696438528; Tue, 22 May 2012 07:20:38 -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 o8csp369538ibd; Tue, 22 May 2012 07:20:38 -0700 (PDT) Received: by 10.68.240.4 with SMTP id vw4mr16386930pbc.14.1337696437668; Tue, 22 May 2012 07:20:37 -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 t9si31658112pbj.42.2012.05.22.07.20.37 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 22 May 2012 07:20:37 -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 h15so9932212dan.37 for ; Tue, 22 May 2012 07:20:37 -0700 (PDT) Received: by 10.68.232.135 with SMTP id to7mr9484186pbc.143.1337696437418; Tue, 22 May 2012 07:20:37 -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 qq2sm22503664pbc.27.2012.05.22.07.20.34 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 22 May 2012 07:20:36 -0700 (PDT) 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 09/16] pstore/ram: Factor ramoops_get_dump_prz() out of ramoops_pstore_read() Date: Tue, 22 May 2012 07:17:52 -0700 Message-Id: <1337696279-8994-9-git-send-email-anton.vorontsov@linaro.org> X-Mailer: git-send-email 1.7.9.2 In-Reply-To: <20120522141717.GA31574@lizard> References: <20120522141717.GA31574@lizard> X-Gm-Message-State: ALoCoQmnnNTKMPvycJB4tKxpF141th52eRt0Zdz0djzoB8eOTUWICdtiThvu6zLez1w3IBt0WSTG 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 Acked-by: Kees Cook --- 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 9785c84..6dc9e96 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;