From patchwork Sat May 26 13:20:22 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Vorontsov X-Patchwork-Id: 8994 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 CCBFC23EB5 for ; Sat, 26 May 2012 13:22:27 +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 87396A18A3B for ; Sat, 26 May 2012 13:22:27 +0000 (UTC) Received: by yenq6 with SMTP id q6so1075309yen.11 for ; Sat, 26 May 2012 06:22:27 -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=y3h/hALnSHT693w6xGLFWhRNkcSTZKBs4t6mAvIEBEY=; b=WAwJWzIRpXP8DjT//B89ufHRY2kbpJYOCRJA25Jb4aROWUNsCse7Cu8CXbVGB2kTMX oPphfzeZwfd0bjvwsX1yCB/L7JsltUNZQdDM/6x7zf8FvJjb/T7W9fryN0Xs18DKsopv 4wCBIde3YQ5JCEYnGG/F9h3gmd46Wfzou0Hd97nXAIi14z+/tDweUgRky6dBO3gZbwfD WwwY9hMqfYE1ntPZl48/Zw1prN4jI/kC57NSXQj9+su+bLaNnjtyEYqMF/GM1G0OZG3q awTzgPb6RYJleC6ehfuh7g6RyIROVAsLpA3wDxtF30cGk/Zrh1afk6M47+gPI/hnDgU9 G9ww== Received: by 10.50.40.193 with SMTP id z1mr1009305igk.0.1338038546844; Sat, 26 May 2012 06:22:26 -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.24.148 with SMTP id v20csp86324ibb; Sat, 26 May 2012 06:22:26 -0700 (PDT) Received: by 10.68.213.104 with SMTP id nr8mr7887661pbc.26.1338038546249; Sat, 26 May 2012 06:22:26 -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 ku9si1513973pbc.115.2012.05.26.06.22.26 (version=TLSv1/SSLv3 cipher=OTHER); Sat, 26 May 2012 06:22:26 -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 h15so2722900dan.37 for ; Sat, 26 May 2012 06:22:26 -0700 (PDT) Received: by 10.68.202.99 with SMTP id kh3mr7433539pbc.157.1338038545950; Sat, 26 May 2012 06:22:25 -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 rj4sm12540438pbc.30.2012.05.26.06.22.23 (version=TLSv1/SSLv3 cipher=OTHER); Sat, 26 May 2012 06:22:25 -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 04/11] pstore/ram: Factor ramoops_get_next_prz() out of ramoops_pstore_read() Date: Sat, 26 May 2012 06:20:22 -0700 Message-Id: <1338038429-21945-4-git-send-email-anton.vorontsov@linaro.org> X-Mailer: git-send-email 1.7.9.2 In-Reply-To: <20120526131747.GA15054@lizard> References: <20120526131747.GA15054@lizard> X-Gm-Message-State: ALoCoQl6W0/pD/6O+QVX2Smd1yAU4Arck+SfXoUy4LBmwf9IqAFeFYDlS96hp4Oqrve8K6K2FqNu 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 | 41 ++++++++++++++++++++++++++++++++--------- 1 file changed, 32 insertions(+), 9 deletions(-) diff --git a/fs/pstore/ram.c b/fs/pstore/ram.c index 6b76767..d770d72 100644 --- a/fs/pstore/ram.c +++ b/fs/pstore/ram.c @@ -85,6 +85,33 @@ static int ramoops_pstore_open(struct pstore_info *psi) return 0; } +static struct persistent_ram_zone * +ramoops_get_next_prz(struct persistent_ram_zone *przs[], uint *c, uint max, + u64 *id, + enum pstore_type_id *typep, enum pstore_type_id type, + bool update) +{ + struct persistent_ram_zone *prz; + int i = (*c)++; + + if (i >= max) + return NULL; + + prz = przs[i]; + + if (update) { + /* Update old/shadowed buffer. */ + persistent_ram_save_old(prz); + if (!persistent_ram_old_size(prz)) + return NULL; + } + + *typep = type; + *id = i; + + return prz; +} + static ssize_t ramoops_pstore_read(u64 *id, enum pstore_type_id *type, struct timespec *time, char **buf, @@ -94,20 +121,16 @@ 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->dump_read_cnt >= cxt->max_dump_cnt) - return -EINVAL; - - *id = cxt->dump_read_cnt++; - prz = cxt->przs[*id]; + prz = ramoops_get_next_prz(cxt->przs, &cxt->dump_read_cnt, + cxt->max_dump_cnt, id, type, + PSTORE_TYPE_DMESG, 1); + if (!prz) + return 0; - /* Only supports dmesg output so far. */ - *type = PSTORE_TYPE_DMESG; /* TODO(kees): Bogus time for the moment. */ time->tv_sec = 0; time->tv_nsec = 0; - /* Update old/shadowed buffer. */ - persistent_ram_save_old(prz); size = persistent_ram_old_size(prz); *buf = kmalloc(size, GFP_KERNEL); if (*buf == NULL)