diff options
author | Chen Ni | 2023-09-14 07:03:27 +0000 |
---|---|---|
committer | Ira Weiny | 2023-09-27 10:33:47 -0700 |
commit | 6fd4ebfc4d61e3097b595ab2725d513e3bbd6739 (patch) | |
tree | b44459d619f6c6722bf61d98a5a739319bb830d7 /drivers/nvdimm | |
parent | 75b3d5dc0846cfa54ea52d7d84215b761ecbf569 (diff) |
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: 49bddc73d15c ("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>
Diffstat (limited to 'drivers/nvdimm')
-rw-r--r-- | drivers/nvdimm/of_pmem.c | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/drivers/nvdimm/of_pmem.c b/drivers/nvdimm/of_pmem.c index 1b9f5b8a6167..d3fca0ab6290 100644 --- a/drivers/nvdimm/of_pmem.c +++ b/drivers/nvdimm/of_pmem.c @@ -30,7 +30,13 @@ static int of_pmem_region_probe(struct platform_device *pdev) if (!priv) return -ENOMEM; - priv->bus_desc.provider_name = kstrdup(pdev->name, GFP_KERNEL); + priv->bus_desc.provider_name = devm_kstrdup(&pdev->dev, pdev->name, + GFP_KERNEL); + if (!priv->bus_desc.provider_name) { + kfree(priv); + return -ENOMEM; + } + priv->bus_desc.module = THIS_MODULE; priv->bus_desc.of_node = np; |