diff mbox series

ACPI: scan: Fix a memory leak in an error handling path

Message ID 63bf4e87eb42fa3fff2cd87eb605ebcc01f4b2f7.1620458525.git.christophe.jaillet@wanadoo.fr (mailing list archive)
State Mainlined, archived
Headers show
Series ACPI: scan: Fix a memory leak in an error handling path | expand

Commit Message

Christophe JAILLET May 8, 2021, 7:23 a.m. UTC
If 'acpi_device_set_name()' fails, we must free
'acpi_device_bus_id->bus_id' or there is a (potential) memory leak.

Fixes: eb50aaf960e3 ("ACPI: scan: Use unique number for instance_no")
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
 drivers/acpi/scan.c | 1 +
 1 file changed, 1 insertion(+)

Comments

Andy Shevchenko May 10, 2021, 12:18 p.m. UTC | #1
On Sat, May 08, 2021 at 09:23:09AM +0200, Christophe JAILLET wrote:
> If 'acpi_device_set_name()' fails, we must free
> 'acpi_device_bus_id->bus_id' or there is a (potential) memory leak.

Good catch!
I guess I have lost it somewhere in the middle of developing the mentioned fix.

Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

Thanks!

> Fixes: eb50aaf960e3 ("ACPI: scan: Use unique number for instance_no")
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> ---
>  drivers/acpi/scan.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c
> index a22778e880c2..651a431e2bbf 100644
> --- a/drivers/acpi/scan.c
> +++ b/drivers/acpi/scan.c
> @@ -700,6 +700,7 @@ int acpi_device_add(struct acpi_device *device,
>  
>  		result = acpi_device_set_name(device, acpi_device_bus_id);
>  		if (result) {
> +			kfree_const(acpi_device_bus_id->bus_id);
>  			kfree(acpi_device_bus_id);
>  			goto err_unlock;
>  		}
> -- 
> 2.30.2
>
Rafael J. Wysocki May 10, 2021, 5:04 p.m. UTC | #2
On Mon, May 10, 2021 at 3:17 PM Andy Shevchenko
<andriy.shevchenko@linux.intel.com> wrote:
>
> On Sat, May 08, 2021 at 09:23:09AM +0200, Christophe JAILLET wrote:
> > If 'acpi_device_set_name()' fails, we must free
> > 'acpi_device_bus_id->bus_id' or there is a (potential) memory leak.
>
> Good catch!
> I guess I have lost it somewhere in the middle of developing the mentioned fix.
>
> Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
>
> Thanks!
>
> > Fixes: eb50aaf960e3 ("ACPI: scan: Use unique number for instance_no")
> > Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> > ---
> >  drivers/acpi/scan.c | 1 +
> >  1 file changed, 1 insertion(+)
> >
> > diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c
> > index a22778e880c2..651a431e2bbf 100644
> > --- a/drivers/acpi/scan.c
> > +++ b/drivers/acpi/scan.c
> > @@ -700,6 +700,7 @@ int acpi_device_add(struct acpi_device *device,
> >
> >               result = acpi_device_set_name(device, acpi_device_bus_id);
> >               if (result) {
> > +                     kfree_const(acpi_device_bus_id->bus_id);
> >                       kfree(acpi_device_bus_id);
> >                       goto err_unlock;
> >               }
> > --

Applied as 5.13-rc material, thanks!
diff mbox series

Patch

diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c
index a22778e880c2..651a431e2bbf 100644
--- a/drivers/acpi/scan.c
+++ b/drivers/acpi/scan.c
@@ -700,6 +700,7 @@  int acpi_device_add(struct acpi_device *device,
 
 		result = acpi_device_set_name(device, acpi_device_bus_id);
 		if (result) {
+			kfree_const(acpi_device_bus_id->bus_id);
 			kfree(acpi_device_bus_id);
 			goto err_unlock;
 		}