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,
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 v5 2/5] ramoops: Add __ramoops_init_prz() as generic function
Date: Mon, 27 Feb 2017 10:53:56 +0900 [thread overview]
Message-ID: <1488160439-7140-3-git-send-email-nobuhiro.iwamatsu.kw@hitachi.com> (raw)
In-Reply-To: <1488160439-7140-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>
V5:
- No changes.
V4:
- Rebase.
V3:
- Rebase.
- Split patch.
---
fs/pstore/ram.c | 73 ++++++++++++++++++++++++++++++---------------------------
1 file changed, 38 insertions(+), 35 deletions(-)
diff --git a/fs/pstore/ram.c b/fs/pstore/ram.c
index 8ad2d6d8cec2..48cfeef42cb6 100644
--- a/fs/pstore/ram.c
+++ b/fs/pstore/ram.c
@@ -520,6 +520,40 @@ static void ramoops_free_przs(struct persistent_ram_zone **przs)
kfree(przs);
}
+static int __ramoops_init_prz(const char *name,
+ struct device *dev, struct ramoops_context *cxt,
+ struct persistent_ram_zone **prz,
+ phys_addr_t *paddr, size_t sz, u32 sig,
+ u32 flags, bool zap)
+{
+ if (!sz)
+ return 0;
+
+ if (zap && *paddr + sz - cxt->phys_addr > cxt->size) {
+ dev_err(dev, "no room for %s mem region (0x%zx@0x%llx) in (0x%lx@0x%llx)\n",
+ name, 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, flags);
+ if (IS_ERR(*prz)) {
+ int err = PTR_ERR(*prz);
+
+ dev_err(dev, "failed to request %s mem region (0x%zx@0x%llx): %d\n",
+ name, sz, (unsigned long long)*paddr, err);
+ return err;
+ }
+
+ if (zap)
+ persistent_ram_zap(*prz);
+
+ *paddr += sz;
+
+ return 0;
+}
+
static int ramoops_init_przs(const char *name,
struct device *dev, struct ramoops_context *cxt,
struct persistent_ram_zone ***przs,
@@ -580,15 +614,9 @@ static int ramoops_init_przs(const char *name,
goto fail;
for (i = 0; i < *cnt; i++) {
- prz_ar[i] = persistent_ram_new(*paddr, zone_sz, sig,
- &cxt->ecc_info,
- cxt->memtype, flags);
- if (IS_ERR(prz_ar[i])) {
- err = PTR_ERR(prz_ar[i]);
- dev_err(dev, "failed to request %s mem region (0x%zx@0x%llx): %d\n",
- name, record_size,
- (unsigned long long)*paddr, err);
-
+ err = __ramoops_init_prz(name, dev, cxt, &prz_ar[i], paddr,
+ zone_sz, sig, flags, false);
+ if (err) {
while (i > 0) {
i--;
persistent_ram_free(prz_ar[i]);
@@ -596,7 +624,6 @@ static int ramoops_init_przs(const char *name,
kfree(prz_ar);
goto fail;
}
- *paddr += zone_sz;
}
*przs = prz_ar;
@@ -612,31 +639,7 @@ static int ramoops_init_prz(const char *name,
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 %s mem region (0x%zx@0x%llx) in (0x%lx@0x%llx)\n",
- name, 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, 0);
- if (IS_ERR(*prz)) {
- int err = PTR_ERR(*prz);
-
- dev_err(dev, "failed to request %s mem region (0x%zx@0x%llx): %d\n",
- name, sz, (unsigned long long)*paddr, err);
- return err;
- }
-
- persistent_ram_zap(*prz);
-
- *paddr += sz;
-
- return 0;
+ return __ramoops_init_prz(name, dev, cxt, prz, paddr, sz, sig, 0, true);
}
static int ramoops_parse_dt_size(struct platform_device *pdev,
--
2.11.0
next prev parent reply other threads:[~2017-02-27 1:55 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-02-27 1:53 [PATCH v5 0/5] pstore: ramoops: support multiple pmsg instances Nobuhiro Iwamatsu
2017-02-27 1:53 ` [PATCH v5 1/5] pstore: Change parameter of ramoops_free_przs() Nobuhiro Iwamatsu
2017-02-27 1:53 ` Nobuhiro Iwamatsu [this message]
2017-02-27 1:53 ` [PATCH v5 3/5] pstore: support multiple pmsg instances Nobuhiro Iwamatsu
2017-02-27 1:53 ` [PATCH v5 4/5] ramoops: " Nobuhiro Iwamatsu
2017-02-27 1:53 ` [PATCH v5 5/5] selftests/pstore: add testcases for " Nobuhiro Iwamatsu
2018-11-29 23:33 ` [PATCH v5 0/5] pstore: ramoops: support " Kees Cook
2018-12-03 3:37 ` Nobuhiro Iwamatsu
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=1488160439-7140-3-git-send-email-nobuhiro.iwamatsu.kw@hitachi.com \
--to=nobuhiro.iwamatsu.kw@hitachi.com \
--cc=anton@enomsg.org \
--cc=ccross@android.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).