[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <6bba2182-5229-627e-11e4-347e12c21bd1@huawei.com>
Date: Sat, 19 Sep 2020 19:38:32 +0800
From: "Leizhen (ThunderTown)" <thunder.leizhen@...wei.com>
To: Oliver O'Halloran <oohall@...il.com>,
Dan Williams <dan.j.williams@...el.com>,
Vishal Verma <vishal.l.verma@...el.com>,
"Dave Jiang" <dave.jiang@...el.com>,
Ira Weiny <ira.weiny@...el.com>,
Markus Elfring <Markus.Elfring@....de>,
linux-nvdimm <linux-nvdimm@...ts.01.org>,
linux-kernel <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH v4 1/1] libnvdimm: fix memory leaks in of_pmem.c
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@...wei.com>
> Reviewed-by: Oliver O'Halloran <oohall@...il.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;
>
Powered by blists - more mailing lists