diff mbox series

[v2] PNP: fix name memory leak in pnp_alloc_dev()

Message ID 20221111012358.661210-1-yangyingliang@huawei.com
State Accepted
Commit 110d7b0325c55ff3620073ba4201845f59e22ebf
Headers show
Series [v2] PNP: fix name memory leak in pnp_alloc_dev() | expand

Commit Message

Yang Yingliang Nov. 11, 2022, 1:23 a.m. UTC
After commit 1fa5ae857bb1 ("driver core: get rid of struct device's
bus_id string array"), the name of device is allocated dynamically,
move dev_set_name() after pnp_add_id() to avoid memory leak.

Fixes: 1fa5ae857bb1 ("driver core: get rid of struct device's bus_id string array")
Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
---
v1 -> v2:
  Move dev_set_name() after pnp_add_id().
---
 drivers/pnp/core.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Hanjun Guo Nov. 22, 2022, 1:10 p.m. UTC | #1
On 2022/11/11 9:23, Yang Yingliang wrote:
> After commit 1fa5ae857bb1 ("driver core: get rid of struct device's
> bus_id string array"), the name of device is allocated dynamically,
> move dev_set_name() after pnp_add_id() to avoid memory leak.
> 
> Fixes: 1fa5ae857bb1 ("driver core: get rid of struct device's bus_id string array")
> Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
> ---
> v1 -> v2:
>    Move dev_set_name() after pnp_add_id().
> ---
>   drivers/pnp/core.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/pnp/core.c b/drivers/pnp/core.c
> index 4df5aa6a309c..6a60c5d83383 100644
> --- a/drivers/pnp/core.c
> +++ b/drivers/pnp/core.c
> @@ -148,14 +148,14 @@ struct pnp_dev *pnp_alloc_dev(struct pnp_protocol *protocol, int id,
>   	dev->dev.coherent_dma_mask = dev->dma_mask;
>   	dev->dev.release = &pnp_release_device;
>   
> -	dev_set_name(&dev->dev, "%02x:%02x", dev->protocol->number, dev->number);
> -
>   	dev_id = pnp_add_id(dev, pnpid);
>   	if (!dev_id) {
>   		kfree(dev);
>   		return NULL;
>   	}
>   
> +	dev_set_name(&dev->dev, "%02x:%02x", dev->protocol->number, dev->number);

Lots of places in the kernel didn't check the return value of
dev_set_name(), so it looks good to me,

Reviewed-by: Hanjun Guo <guohanjun@huawei.com>
Rafael J. Wysocki Nov. 22, 2022, 7:38 p.m. UTC | #2
On Tue, Nov 22, 2022 at 2:10 PM Hanjun Guo <guohanjun@huawei.com> wrote:
>
> On 2022/11/11 9:23, Yang Yingliang wrote:
> > After commit 1fa5ae857bb1 ("driver core: get rid of struct device's
> > bus_id string array"), the name of device is allocated dynamically,
> > move dev_set_name() after pnp_add_id() to avoid memory leak.
> >
> > Fixes: 1fa5ae857bb1 ("driver core: get rid of struct device's bus_id string array")
> > Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
> > ---
> > v1 -> v2:
> >    Move dev_set_name() after pnp_add_id().
> > ---
> >   drivers/pnp/core.c | 4 ++--
> >   1 file changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/pnp/core.c b/drivers/pnp/core.c
> > index 4df5aa6a309c..6a60c5d83383 100644
> > --- a/drivers/pnp/core.c
> > +++ b/drivers/pnp/core.c
> > @@ -148,14 +148,14 @@ struct pnp_dev *pnp_alloc_dev(struct pnp_protocol *protocol, int id,
> >       dev->dev.coherent_dma_mask = dev->dma_mask;
> >       dev->dev.release = &pnp_release_device;
> >
> > -     dev_set_name(&dev->dev, "%02x:%02x", dev->protocol->number, dev->number);
> > -
> >       dev_id = pnp_add_id(dev, pnpid);
> >       if (!dev_id) {
> >               kfree(dev);
> >               return NULL;
> >       }
> >
> > +     dev_set_name(&dev->dev, "%02x:%02x", dev->protocol->number, dev->number);
>
> Lots of places in the kernel didn't check the return value of
> dev_set_name(), so it looks good to me,
>
> Reviewed-by: Hanjun Guo <guohanjun@huawei.com>

Applied as 6.2 material, thanks!
diff mbox series

Patch

diff --git a/drivers/pnp/core.c b/drivers/pnp/core.c
index 4df5aa6a309c..6a60c5d83383 100644
--- a/drivers/pnp/core.c
+++ b/drivers/pnp/core.c
@@ -148,14 +148,14 @@  struct pnp_dev *pnp_alloc_dev(struct pnp_protocol *protocol, int id,
 	dev->dev.coherent_dma_mask = dev->dma_mask;
 	dev->dev.release = &pnp_release_device;
 
-	dev_set_name(&dev->dev, "%02x:%02x", dev->protocol->number, dev->number);
-
 	dev_id = pnp_add_id(dev, pnpid);
 	if (!dev_id) {
 		kfree(dev);
 		return NULL;
 	}
 
+	dev_set_name(&dev->dev, "%02x:%02x", dev->protocol->number, dev->number);
+
 	return dev;
 }