From: Wei Yang <richardw.yang@linux.intel.com>
To: linux-nvdimm@lists.01.org
Cc: zwisler@kernel.org
Subject: [PATCH] libnvdimm, pfn: not allocate nd_pfn->pfn_sb if already allocated
Date: Fri, 18 Jan 2019 11:35:44 +0800 [thread overview]
Message-ID: <20190118033544.3980-1-richardw.yang@linux.intel.com> (raw)
In current implementation, we might re-allocate nd_pfn->pfn_sb.
For example:
nd_dax_probe()
nd_pfn->pfn_sb = devm_kzalloc()
dax_pmem_probe()
nvdimm_setup_pfn()
nd_pfn_init()
nd_pfn->pfn_sb = devm_kzalloc()
This patch checks nd_pfn->pfn_sb before allocating it in nd_pfn_init().
Signed-off-by: Wei Yang <richardw.yang@linux.intel.com>
---
drivers/nvdimm/pfn_devs.c | 14 +++++++++-----
1 file changed, 9 insertions(+), 5 deletions(-)
diff --git a/drivers/nvdimm/pfn_devs.c b/drivers/nvdimm/pfn_devs.c
index 6f22272e8d80..1f4f07007483 100644
--- a/drivers/nvdimm/pfn_devs.c
+++ b/drivers/nvdimm/pfn_devs.c
@@ -687,21 +687,25 @@ static int nd_pfn_init(struct nd_pfn *nd_pfn)
u32 dax_label_reserve = is_nd_dax(&nd_pfn->dev) ? SZ_128K : 0;
struct nd_namespace_common *ndns = nd_pfn->ndns;
struct nd_namespace_io *nsio = to_nd_namespace_io(&ndns->dev);
+ struct nd_pfn_sb *pfn_sb = nd_pfn->pfn_sb;
resource_size_t start, size;
struct nd_region *nd_region;
u32 start_pad, end_trunc;
- struct nd_pfn_sb *pfn_sb;
unsigned long npfns;
phys_addr_t offset;
const char *sig;
u64 checksum;
int rc;
- pfn_sb = devm_kzalloc(&nd_pfn->dev, sizeof(*pfn_sb), GFP_KERNEL);
- if (!pfn_sb)
- return -ENOMEM;
+ if (!pfn_sb) {
+ pfn_sb = devm_kzalloc(&nd_pfn->dev,
+ sizeof(*pfn_sb), GFP_KERNEL);
+ if (!pfn_sb)
+ return -ENOMEM;
+
+ nd_pfn->pfn_sb = pfn_sb;
+ }
- nd_pfn->pfn_sb = pfn_sb;
if (is_nd_dax(&nd_pfn->dev))
sig = DAX_SIG;
else
--
2.19.1
_______________________________________________
Linux-nvdimm mailing list
Linux-nvdimm@lists.01.org
https://lists.01.org/mailman/listinfo/linux-nvdimm
next reply other threads:[~2019-01-18 3:36 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-01-18 3:35 Wei Yang [this message]
2019-01-18 4:31 ` [PATCH] libnvdimm, pfn: not allocate nd_pfn->pfn_sb if already allocated Dan Williams
2019-01-18 5:03 ` Wei Yang
2019-01-18 5:05 ` Dan Williams
2019-01-18 7:31 ` Wei Yang
2019-01-18 8:38 ` Dan Williams
2019-01-18 18:59 ` Dan Williams
2019-01-21 0:50 ` Wei Yang
2019-01-21 3:28 ` Dan Williams
2019-01-21 0:24 ` Wei Yang
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=20190118033544.3980-1-richardw.yang@linux.intel.com \
--to=richardw.yang@linux.intel.com \
--cc=linux-nvdimm@lists.01.org \
--cc=zwisler@kernel.org \
/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.