Skip to content

Commit 6fd4ebf

Browse files
Chen Niweiny2
authored andcommitted
libnvdimm/of_pmem: Use devm_kstrdup instead of kstrdup and check its return value
Use devm_kstrdup() instead of kstrdup() and check its return value to avoid memory leak. Fixes: 49bddc7 ("libnvdimm/of_pmem: Provide a unique name for bus provider") Signed-off-by: Chen Ni <nichen@iscas.ac.cn> Reviewed-by: Ira Weiny <ira.weiny@intel.com> Reviewed-by: Dave Jiang <dave.jiang@intel.com> Signed-off-by: Ira Weiny <ira.weiny@intel.com>
1 parent 75b3d5d commit 6fd4ebf

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

drivers/nvdimm/of_pmem.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,13 @@ static int of_pmem_region_probe(struct platform_device *pdev)
3030
if (!priv)
3131
return -ENOMEM;
3232

33-
priv->bus_desc.provider_name = kstrdup(pdev->name, GFP_KERNEL);
33+
priv->bus_desc.provider_name = devm_kstrdup(&pdev->dev, pdev->name,
34+
GFP_KERNEL);
35+
if (!priv->bus_desc.provider_name) {
36+
kfree(priv);
37+
return -ENOMEM;
38+
}
39+
3440
priv->bus_desc.module = THIS_MODULE;
3541
priv->bus_desc.of_node = np;
3642

0 commit comments

Comments
 (0)