mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] libnvdimm/of_pmem: Fix memory leak in of_pmem_region_probe()
@ 2022-11-23 13:45 Xiu Jianfeng
  2022-11-23 14:53 ` Tarun Sahu
  0 siblings, 1 reply; 3+ messages in thread
From: Xiu Jianfeng @ 2022-11-23 13:45 UTC (permalink / raw)
  To: oohall, dan.j.williams, vishal.l.verma, dave.jiang, ira.weiny,
	aneesh.kumar
  Cc: nvdimm, linux-kernel

After changes in commit 49bddc73d15c ("libnvdimm/of_pmem: Provide a unique
name for bus provider"), @priv->bus_desc.provider_name is no longer a
const string, but a dynamic string allocated by kstrdup(), it should be
freed on the error path, and when driver is removed.

Fixes: 49bddc73d15c ("libnvdimm/of_pmem: Provide a unique name for bus provider")
Signed-off-by: Xiu Jianfeng <xiujianfeng@huawei.com>
---
 drivers/nvdimm/of_pmem.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/nvdimm/of_pmem.c b/drivers/nvdimm/of_pmem.c
index 10dbdcdfb9ce..1292ffca7b2e 100644
--- a/drivers/nvdimm/of_pmem.c
+++ b/drivers/nvdimm/of_pmem.c
@@ -36,6 +36,7 @@ static int of_pmem_region_probe(struct platform_device *pdev)
 
 	priv->bus = bus = nvdimm_bus_register(&pdev->dev, &priv->bus_desc);
 	if (!bus) {
+		kfree(priv->bus_desc.provider_name);
 		kfree(priv);
 		return -ENODEV;
 	}
@@ -83,6 +84,7 @@ static int of_pmem_region_remove(struct platform_device *pdev)
 	struct of_pmem_private *priv = platform_get_drvdata(pdev);
 
 	nvdimm_bus_unregister(priv->bus);
+	kfree(priv->bus_desc.provider_name);
 	kfree(priv);
 
 	return 0;
-- 
2.17.1


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

* Re: [PATCH] libnvdimm/of_pmem: Fix memory leak in of_pmem_region_probe()
  2022-11-23 13:45 [PATCH] libnvdimm/of_pmem: Fix memory leak in of_pmem_region_probe() Xiu Jianfeng
@ 2022-11-23 14:53 ` Tarun Sahu
  2022-11-23 15:09   ` xiujianfeng
  0 siblings, 1 reply; 3+ messages in thread
From: Tarun Sahu @ 2022-11-23 14:53 UTC (permalink / raw)
  To: Xiu Jianfeng
  Cc: oohall, dan.j.williams, vishal.l.verma, dave.jiang, ira.weiny,
	aneesh.kumar, nvdimm, linux-kernel

Hi,
Thanks for resolving it.

All looks good. Except a thing, there is no check for return status of
ksrdup too. that can also be part of this patch.

On Nov 23 2022, Xiu Jianfeng wrote:
> After changes in commit 49bddc73d15c ("libnvdimm/of_pmem: Provide a unique
> name for bus provider"), @priv->bus_desc.provider_name is no longer a
> const string, but a dynamic string allocated by kstrdup(), it should be
> freed on the error path, and when driver is removed.
> 
> Fixes: 49bddc73d15c ("libnvdimm/of_pmem: Provide a unique name for bus provider")
> Signed-off-by: Xiu Jianfeng <xiujianfeng@huawei.com>
> ---
>  drivers/nvdimm/of_pmem.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/nvdimm/of_pmem.c b/drivers/nvdimm/of_pmem.c
> index 10dbdcdfb9ce..1292ffca7b2e 100644
> --- a/drivers/nvdimm/of_pmem.c
> +++ b/drivers/nvdimm/of_pmem.c
> @@ -36,6 +36,7 @@ static int of_pmem_region_probe(struct platform_device *pdev)
>  
>  	priv->bus = bus = nvdimm_bus_register(&pdev->dev, &priv->bus_desc);
>  	if (!bus) {
> +		kfree(priv->bus_desc.provider_name);
>  		kfree(priv);
>  		return -ENODEV;
>  	}
> @@ -83,6 +84,7 @@ static int of_pmem_region_remove(struct platform_device *pdev)
>  	struct of_pmem_private *priv = platform_get_drvdata(pdev);
>  
>  	nvdimm_bus_unregister(priv->bus);
> +	kfree(priv->bus_desc.provider_name);
>  	kfree(priv);
>  
>  	return 0;
> -- 
> 2.17.1
> 

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

* Re: [PATCH] libnvdimm/of_pmem: Fix memory leak in of_pmem_region_probe()
  2022-11-23 14:53 ` Tarun Sahu
@ 2022-11-23 15:09   ` xiujianfeng
  0 siblings, 0 replies; 3+ messages in thread
From: xiujianfeng @ 2022-11-23 15:09 UTC (permalink / raw)
  To: Tarun Sahu
  Cc: oohall, dan.j.williams, vishal.l.verma, dave.jiang, ira.weiny,
	aneesh.kumar, nvdimm, linux-kernel

Hi,

在 2022/11/23 22:53, Tarun Sahu 写道:
> Hi,
> Thanks for resolving it.
> 
> All looks good. Except a thing, there is no check for return status of
> ksrdup too. that can also be part of this patch.

Thanks for review, already sent v2.

> 
> On Nov 23 2022, Xiu Jianfeng wrote:
>> After changes in commit 49bddc73d15c ("libnvdimm/of_pmem: Provide a unique
>> name for bus provider"), @priv->bus_desc.provider_name is no longer a
>> const string, but a dynamic string allocated by kstrdup(), it should be
>> freed on the error path, and when driver is removed.
>>
>> Fixes: 49bddc73d15c ("libnvdimm/of_pmem: Provide a unique name for bus provider")
>> Signed-off-by: Xiu Jianfeng <xiujianfeng@huawei.com>
>> ---
>>   drivers/nvdimm/of_pmem.c | 2 ++
>>   1 file changed, 2 insertions(+)
>>
>> diff --git a/drivers/nvdimm/of_pmem.c b/drivers/nvdimm/of_pmem.c
>> index 10dbdcdfb9ce..1292ffca7b2e 100644
>> --- a/drivers/nvdimm/of_pmem.c
>> +++ b/drivers/nvdimm/of_pmem.c
>> @@ -36,6 +36,7 @@ static int of_pmem_region_probe(struct platform_device *pdev)
>>   
>>   	priv->bus = bus = nvdimm_bus_register(&pdev->dev, &priv->bus_desc);
>>   	if (!bus) {
>> +		kfree(priv->bus_desc.provider_name);
>>   		kfree(priv);
>>   		return -ENODEV;
>>   	}
>> @@ -83,6 +84,7 @@ static int of_pmem_region_remove(struct platform_device *pdev)
>>   	struct of_pmem_private *priv = platform_get_drvdata(pdev);
>>   
>>   	nvdimm_bus_unregister(priv->bus);
>> +	kfree(priv->bus_desc.provider_name);
>>   	kfree(priv);
>>   
>>   	return 0;
>> -- 
>> 2.17.1
>>
> .
> 

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

end of thread, other threads:[~2022-11-23 15:10 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-23 13:45 [PATCH] libnvdimm/of_pmem: Fix memory leak in of_pmem_region_probe() Xiu Jianfeng
2022-11-23 14:53 ` Tarun Sahu
2022-11-23 15:09   ` xiujianfeng

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®