All of lore.kernel.org
 help / color / mirror / Atom feed
From: Nobuhiro Iwamatsu <nobuhiro.iwamatsu.kw@hitachi.com>
To: Anton Vorontsov <anton@enomsg.org>,
	Colin Cross <ccross@android.com>,
	Kees Cook <keescook@chromium.org>,
	Tony Luck <tony.luck@intel.com>
Cc: linux-kernel@vger.kernel.org,
	cti.systems-productivity-manager.ts@hitachi.com,
	Nobuhiro Iwamatsu <nobuhiro.iwamatsu.kw@hitachi.com>,
	Hiraku Toyooka <hiraku.toyooka.gu@hitachi.com>,
	Mark Salyzyn <salyzyn@android.com>,
	Seiji Aguchi <seiji.aguchi.tr@hitachi.com>,
	Shuah Khan <shuahkh@osg.samsung.com>
Subject: [PATCH v3 3/8] ramoops: Add __ramoops_init_prz() as generic function
Date: Tue, 18 Oct 2016 16:13:29 +0900	[thread overview]
Message-ID: <1476774814-6840-4-git-send-email-nobuhiro.iwamatsu.kw@hitachi.com> (raw)
In-Reply-To: <1476774814-6840-1-git-send-email-nobuhiro.iwamatsu.kw@hitachi.com>

This commit adds generic function __ramoops_init_prz() to reduce redundancy
between ramoops_init_prz() and ramoops_init_przs().

Signed-off-by: Nobuhiro Iwamatsu <nobuhiro.iwamatsu.kw@hitachi.com>
Signed-off-by: Hiraku Toyooka <hiraku.toyooka.gu@hitachi.com>
Cc: Anton Vorontsov <anton@enomsg.org>
Cc: Colin Cross <ccross@android.com>
Cc: Kees Cook <keescook@chromium.org>
Cc: Mark Salyzyn <salyzyn@android.com>
Cc: Seiji Aguchi <seiji.aguchi.tr@hitachi.com>
Cc: Shuah Khan <shuahkh@osg.samsung.com>
Cc: Tony Luck <tony.luck@intel.com>

V3:
   Rebase.
   Split patch.
---
 fs/pstore/ram.c | 69 ++++++++++++++++++++++++++++++---------------------------
 1 file changed, 36 insertions(+), 33 deletions(-)

diff --git a/fs/pstore/ram.c b/fs/pstore/ram.c
index 691680f..4fe27fb 100644
--- a/fs/pstore/ram.c
+++ b/fs/pstore/ram.c
@@ -404,6 +404,38 @@ static void ramoops_free_przs(struct persistent_ram_zone **przs, int cnt)
 	kfree(przs);
 }
 
+static int __ramoops_init_prz(struct device *dev, struct ramoops_context *cxt,
+			      struct persistent_ram_zone **prz,
+			      phys_addr_t *paddr, size_t sz, u32 sig, bool zap)
+{
+	if (!sz)
+		return 0;
+
+	if (*paddr + sz - cxt->phys_addr > cxt->size) {
+		dev_err(dev, "no room for mem region (0x%zx@0x%llx) in (0x%lx@0x%llx)\n",
+			sz, (unsigned long long)*paddr,
+			cxt->size, (unsigned long long)cxt->phys_addr);
+		return -ENOMEM;
+	}
+
+	*prz = persistent_ram_new(*paddr, sz, sig, &cxt->ecc_info,
+				  cxt->memtype);
+	if (IS_ERR(*prz)) {
+		int err = PTR_ERR(*prz);
+
+		dev_err(dev, "failed to request mem region (0x%zx@0x%llx): %d\n",
+			sz, (unsigned long long)*paddr, err);
+		return err;
+	}
+
+	if (zap)
+		persistent_ram_zap(*prz);
+
+	*paddr += sz;
+
+	return 0;
+}
+
 static int ramoops_init_przs(struct device *dev, struct ramoops_context *cxt,
 			     phys_addr_t *paddr, size_t dump_mem_sz)
 {
@@ -430,21 +462,15 @@ static int ramoops_init_przs(struct device *dev, struct ramoops_context *cxt,
 	}
 
 	for (i = 0; i < cxt->max_dump_cnt; i++) {
-		cxt->przs[i] = persistent_ram_new(*paddr, cxt->record_size, 0,
-						  &cxt->ecc_info,
-						  cxt->memtype);
-		if (IS_ERR(cxt->przs[i])) {
-			err = PTR_ERR(cxt->przs[i]);
-			dev_err(dev, "failed to request mem region (0x%zx@0x%llx): %d\n",
-				cxt->record_size, (unsigned long long)*paddr, err);
-
+		err = __ramoops_init_prz(dev, cxt, &cxt->przs[i], paddr,
+					 cxt->record_size, 0, false);
+		if (err) {
 			while (i > 0) {
 				i--;
 				persistent_ram_free(cxt->przs[i]);
 			}
 			goto fail_prz;
 		}
-		*paddr += cxt->record_size;
 	}
 
 	return 0;
@@ -459,30 +485,7 @@ static int ramoops_init_prz(struct device *dev, struct ramoops_context *cxt,
 			    struct persistent_ram_zone **prz,
 			    phys_addr_t *paddr, size_t sz, u32 sig)
 {
-	if (!sz)
-		return 0;
-
-	if (*paddr + sz - cxt->phys_addr > cxt->size) {
-		dev_err(dev, "no room for mem region (0x%zx@0x%llx) in (0x%lx@0x%llx)\n",
-			sz, (unsigned long long)*paddr,
-			cxt->size, (unsigned long long)cxt->phys_addr);
-		return -ENOMEM;
-	}
-
-	*prz = persistent_ram_new(*paddr, sz, sig, &cxt->ecc_info, cxt->memtype);
-	if (IS_ERR(*prz)) {
-		int err = PTR_ERR(*prz);
-
-		dev_err(dev, "failed to request mem region (0x%zx@0x%llx): %d\n",
-			sz, (unsigned long long)*paddr, err);
-		return err;
-	}
-
-	persistent_ram_zap(*prz);
-
-	*paddr += sz;
-
-	return 0;
+	return __ramoops_init_prz(dev, cxt, prz, paddr, sz, sig, true);
 }
 
 static int ramoops_parse_dt_size(struct platform_device *pdev,
-- 
2.9.3

  parent reply	other threads:[~2016-10-18  7:16 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-18  7:13 [PATCH v3 0/8] pstore: ramoops: support multiple pmsg instances Nobuhiro Iwamatsu
2016-10-18  7:13 ` [PATCH v3 1/8] pstore: Replace four kzalloc() calls by kcalloc() in ramoops_init_przs() Nobuhiro Iwamatsu
2016-10-18  7:13 ` [PATCH v3 2/8] pstore: Change parameter of ramoops_free_przs() Nobuhiro Iwamatsu
2016-10-18  7:13 ` Nobuhiro Iwamatsu [this message]
2016-10-18  7:13 ` [PATCH v3 4/8] pstore: Rename 'przs' to 'dprzs' in struct ramoops_context Nobuhiro Iwamatsu
2016-10-18  7:13 ` [PATCH v3 5/8] ramoops: Rename ramoops_init_prz() to ramoops_init_dprzs() Nobuhiro Iwamatsu
2016-10-18  7:13 ` [PATCH v3 6/8] pstore: support multiple pmsg instances Nobuhiro Iwamatsu
2016-10-18  7:13 ` [PATCH v3 7/8] ramoops: " Nobuhiro Iwamatsu
2016-10-18  7:13 ` [PATCH v3 8/8] selftests/pstore: add testcases for " Nobuhiro Iwamatsu
2016-11-11 22:24 ` [PATCH v3 0/8] pstore: ramoops: support " Kees Cook
2016-12-05  1:47   ` 岩松信洋 / IWAMATSU,NOBUHIRO
2016-12-27  0:48     ` 岩松信洋 / IWAMATSU,NOBUHIRO
2017-01-04  6:20       ` Kees Cook

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1476774814-6840-4-git-send-email-nobuhiro.iwamatsu.kw@hitachi.com \
    --to=nobuhiro.iwamatsu.kw@hitachi.com \
    --cc=anton@enomsg.org \
    --cc=ccross@android.com \
    --cc=cti.systems-productivity-manager.ts@hitachi.com \
    --cc=hiraku.toyooka.gu@hitachi.com \
    --cc=keescook@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=salyzyn@android.com \
    --cc=seiji.aguchi.tr@hitachi.com \
    --cc=shuahkh@osg.samsung.com \
    --cc=tony.luck@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.