linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v4 0/1] libnvdimm: fix memory leaks in of_pmem.c
@ 2020-09-01  8:14 Zhen Lei
  2020-09-01  8:14 ` [PATCH v4 1/1] " Zhen Lei
       [not found] ` <9d82bd85-5d6c-b8fe-15c7-c87348aa7a3a@web.de>
  0 siblings, 2 replies; 4+ messages in thread
From: Zhen Lei @ 2020-09-01  8:14 UTC (permalink / raw)
  To: Oliver O'Halloran, Dan Williams, Vishal Verma, Dave Jiang,
	Ira Weiny, Markus Elfring, linux-nvdimm, linux-kernel
  Cc: Zhen Lei

v3 --> v4
1. Merge patch 1 and 2 into one:
   https://lkml.org/lkml/2020/8/19/1464		Patch 1
   https://lkml.org/lkml/2020/8/19/1468		Patch 2
2. The part from patch 1 was reviewed by Oliver O'Halloran <oohall@gmail.com>

Zhen Lei (1):
  libnvdimm: fix memory leaks in of_pmem.c

 drivers/nvdimm/of_pmem.c | 7 +++++++
 1 file changed, 7 insertions(+)

-- 
1.8.3



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

* [PATCH v4 1/1] libnvdimm: fix memory leaks in of_pmem.c
  2020-09-01  8:14 [PATCH v4 0/1] libnvdimm: fix memory leaks in of_pmem.c Zhen Lei
@ 2020-09-01  8:14 ` Zhen Lei
  2020-09-19 11:38   ` Leizhen (ThunderTown)
       [not found] ` <9d82bd85-5d6c-b8fe-15c7-c87348aa7a3a@web.de>
  1 sibling, 1 reply; 4+ messages in thread
From: Zhen Lei @ 2020-09-01  8:14 UTC (permalink / raw)
  To: Oliver O'Halloran, Dan Williams, Vishal Verma, Dave Jiang,
	Ira Weiny, Markus Elfring, linux-nvdimm, linux-kernel
  Cc: Zhen Lei

Currently, in the last error path of of_pmem_region_probe() and in
of_pmem_region_remove(), free the memory allocated by kstrdup() is
missing. Add kfree(priv->bus_desc.provider_name) to fix it.

In addition, add a sanity check to kstrdup() to prevent a
NULL-pointer dereference.

Fixes: 49bddc73d15c ("libnvdimm/of_pmem: Provide a unique name for bus provider")
Signed-off-by: Zhen Lei <thunder.leizhen@huawei.com>
Reviewed-by: Oliver O'Halloran <oohall@gmail.com>
---
 drivers/nvdimm/of_pmem.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/drivers/nvdimm/of_pmem.c b/drivers/nvdimm/of_pmem.c
index 10dbdcdfb9ce913..13c4c274ca6ea88 100644
--- a/drivers/nvdimm/of_pmem.c
+++ b/drivers/nvdimm/of_pmem.c
@@ -31,11 +31,17 @@ static int of_pmem_region_probe(struct platform_device *pdev)
 		return -ENOMEM;
 
 	priv->bus_desc.provider_name = kstrdup(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;
 
 	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 +89,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;
-- 
1.8.3



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

* Re: [PATCH v4 0/1] libnvdimm: fix memory leaks in of_pmem.c
       [not found] ` <9d82bd85-5d6c-b8fe-15c7-c87348aa7a3a@web.de>
@ 2020-09-01 11:11   ` Leizhen (ThunderTown)
  0 siblings, 0 replies; 4+ messages in thread
From: Leizhen (ThunderTown) @ 2020-09-01 11:11 UTC (permalink / raw)
  To: Markus Elfring, linux-nvdimm, linux-kernel
  Cc: Oliver O'Halloran, Dan Williams, Vishal Verma, Dave Jiang, Ira Weiny



On 2020/9/1 18:14, Markus Elfring wrote:
>> v3 --> v4
>> 1. Merge patch 1 and 2 into one:
> 
> How do you think about to omit a cover letter for a single patch?

After all, the code hasn't changed except this merge.

> 
> Regards,
> Markus
> 
> 


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

* Re: [PATCH v4 1/1] libnvdimm: fix memory leaks in of_pmem.c
  2020-09-01  8:14 ` [PATCH v4 1/1] " Zhen Lei
@ 2020-09-19 11:38   ` Leizhen (ThunderTown)
  0 siblings, 0 replies; 4+ messages in thread
From: Leizhen (ThunderTown) @ 2020-09-19 11:38 UTC (permalink / raw)
  To: Oliver O'Halloran, Dan Williams, Vishal Verma, Dave Jiang,
	Ira Weiny, Markus Elfring, linux-nvdimm, linux-kernel

Hi, all:
  Is this patch acceptable?


On 2020/9/1 16:14, Zhen Lei wrote:
> Currently, in the last error path of of_pmem_region_probe() and in
> of_pmem_region_remove(), free the memory allocated by kstrdup() is
> missing. Add kfree(priv->bus_desc.provider_name) to fix it.
> 
> In addition, add a sanity check to kstrdup() to prevent a
> NULL-pointer dereference.
> 
> Fixes: 49bddc73d15c ("libnvdimm/of_pmem: Provide a unique name for bus provider")
> Signed-off-by: Zhen Lei <thunder.leizhen@huawei.com>
> Reviewed-by: Oliver O'Halloran <oohall@gmail.com>
> ---
>  drivers/nvdimm/of_pmem.c | 7 +++++++
>  1 file changed, 7 insertions(+)
> 
> diff --git a/drivers/nvdimm/of_pmem.c b/drivers/nvdimm/of_pmem.c
> index 10dbdcdfb9ce913..13c4c274ca6ea88 100644
> --- a/drivers/nvdimm/of_pmem.c
> +++ b/drivers/nvdimm/of_pmem.c
> @@ -31,11 +31,17 @@ static int of_pmem_region_probe(struct platform_device *pdev)
>  		return -ENOMEM;
>  
>  	priv->bus_desc.provider_name = kstrdup(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;
>  
>  	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 +89,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;
> 


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

end of thread, other threads:[~2020-09-19 11:38 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-01  8:14 [PATCH v4 0/1] libnvdimm: fix memory leaks in of_pmem.c Zhen Lei
2020-09-01  8:14 ` [PATCH v4 1/1] " Zhen Lei
2020-09-19 11:38   ` Leizhen (ThunderTown)
     [not found] ` <9d82bd85-5d6c-b8fe-15c7-c87348aa7a3a@web.de>
2020-09-01 11:11   ` [PATCH v4 0/1] " Leizhen (ThunderTown)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).