All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] libnvdimm, pfn: not allocate nd_pfn->pfn_sb if already allocated
@ 2019-01-18  3:35 Wei Yang
  2019-01-18  4:31 ` Dan Williams
  0 siblings, 1 reply; 10+ messages in thread
From: Wei Yang @ 2019-01-18  3:35 UTC (permalink / raw)
  To: linux-nvdimm; +Cc: zwisler

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

^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2019-01-21  3:28 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-01-18  3:35 [PATCH] libnvdimm, pfn: not allocate nd_pfn->pfn_sb if already allocated Wei Yang
2019-01-18  4:31 ` 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

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.