diff mbox series

[5.10,48/76] platform/x86: intel_pmc_core: fix memleak on registration failure

Message ID 20211227151326.366957180@linuxfoundation.org
State New
Headers show
Series None | expand

Commit Message

Greg KH Dec. 27, 2021, 3:31 p.m. UTC
From: Johan Hovold <johan@kernel.org>

commit 26a8b09437804fabfb1db080d676b96c0de68e7c upstream.

In case device registration fails during module initialisation, the
platform device structure needs to be freed using platform_device_put()
to properly free all resources (e.g. the device name).

Fixes: 938835aa903a ("platform/x86: intel_pmc_core: do not create a static struct device")
Cc: stable@vger.kernel.org      # 5.9
Signed-off-by: Johan Hovold <johan@kernel.org>
Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Link: https://lore.kernel.org/r/20211222105023.6205-1-johan@kernel.org
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
 drivers/platform/x86/intel_pmc_core_pltdrv.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Pavel Machek Dec. 31, 2021, 10:04 a.m. UTC | #1
Hi!

On Mon 2021-12-27 16:31:03, Greg Kroah-Hartman wrote:
> From: Johan Hovold <johan@kernel.org>
> 
> commit 26a8b09437804fabfb1db080d676b96c0de68e7c upstream.
> 
> In case device registration fails during module initialisation, the
> platform device structure needs to be freed using platform_device_put()
> to properly free all resources (e.g. the device name).
>

Does it? What exactly was leaking here?

> +++ b/drivers/platform/x86/intel_pmc_core_pltdrv.c
> @@ -65,7 +65,7 @@ static int __init pmc_core_platform_init
>  
>  	retval = platform_device_register(pmc_core_device);
>  	if (retval)
> -		kfree(pmc_core_device);
> +		platform_device_put(pmc_core_device);
>  

This is strange. Failing registration should have no effects that need
to be undone.

Best regards,
								Pavel
Greg KH Dec. 31, 2021, 10:18 a.m. UTC | #2
On Fri, Dec 31, 2021 at 11:04:05AM +0100, Pavel Machek wrote:
> Hi!
> 
> On Mon 2021-12-27 16:31:03, Greg Kroah-Hartman wrote:
> > From: Johan Hovold <johan@kernel.org>
> > 
> > commit 26a8b09437804fabfb1db080d676b96c0de68e7c upstream.
> > 
> > In case device registration fails during module initialisation, the
> > platform device structure needs to be freed using platform_device_put()
> > to properly free all resources (e.g. the device name).
> >
> 
> Does it? What exactly was leaking here?
> 
> > +++ b/drivers/platform/x86/intel_pmc_core_pltdrv.c
> > @@ -65,7 +65,7 @@ static int __init pmc_core_platform_init
> >  
> >  	retval = platform_device_register(pmc_core_device);
> >  	if (retval)
> > -		kfree(pmc_core_device);
> > +		platform_device_put(pmc_core_device);
> >  
> 
> This is strange. Failing registration should have no effects that need
> to be undone.

Sadly, that is not how the driver model has ever worked for various
reasons.

greg k-h
diff mbox series

Patch

--- a/drivers/platform/x86/intel_pmc_core_pltdrv.c
+++ b/drivers/platform/x86/intel_pmc_core_pltdrv.c
@@ -65,7 +65,7 @@  static int __init pmc_core_platform_init
 
 	retval = platform_device_register(pmc_core_device);
 	if (retval)
-		kfree(pmc_core_device);
+		platform_device_put(pmc_core_device);
 
 	return retval;
 }