linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] media: em28xx: Fix possible memory leak of em28xx struct
@ 2021-05-04 18:32 Igor Matheus Andrade Torrente
  2021-05-05 15:54 ` Shuah Khan
  0 siblings, 1 reply; 3+ messages in thread
From: Igor Matheus Andrade Torrente @ 2021-05-04 18:32 UTC (permalink / raw)
  To: mchehab, skhan
  Cc: Igor Matheus Andrade Torrente, linux-media, linux-kernel, hverkuil-cisco

The em28xx struct kref isn't being decreased after an error in the
em28xx_ir_init, leading to a possible memory leak.

A kref_put and em28xx_shutdown_buttons is added to the error handler code.

Signed-off-by: Igor Matheus Andrade Torrente <igormtorrente@gmail.com>
---
 drivers/media/usb/em28xx/em28xx-input.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/media/usb/em28xx/em28xx-input.c b/drivers/media/usb/em28xx/em28xx-input.c
index 5aa15a7a49de..59529cbf9cd0 100644
--- a/drivers/media/usb/em28xx/em28xx-input.c
+++ b/drivers/media/usb/em28xx/em28xx-input.c
@@ -720,7 +720,8 @@ static int em28xx_ir_init(struct em28xx *dev)
 			dev->board.has_ir_i2c = 0;
 			dev_warn(&dev->intf->dev,
 				 "No i2c IR remote control device found.\n");
-			return -ENODEV;
+			err = -ENODEV;
+			goto ref_put;
 		}
 	}
 
@@ -735,7 +736,7 @@ static int em28xx_ir_init(struct em28xx *dev)
 
 	ir = kzalloc(sizeof(*ir), GFP_KERNEL);
 	if (!ir)
-		return -ENOMEM;
+		goto ref_put;
 	rc = rc_allocate_device(RC_DRIVER_SCANCODE);
 	if (!rc)
 		goto error;
@@ -839,6 +840,9 @@ static int em28xx_ir_init(struct em28xx *dev)
 	dev->ir = NULL;
 	rc_free_device(rc);
 	kfree(ir);
+ref_put:
+	em28xx_shutdown_buttons(dev);
+	kref_put(&dev->ref, em28xx_free_device);
 	return err;
 }
 
-- 
2.20.1


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

* Re: [PATCH v2] media: em28xx: Fix possible memory leak of em28xx struct
  2021-05-04 18:32 [PATCH v2] media: em28xx: Fix possible memory leak of em28xx struct Igor Matheus Andrade Torrente
@ 2021-05-05 15:54 ` Shuah Khan
  2021-05-06  7:43   ` Hans Verkuil
  0 siblings, 1 reply; 3+ messages in thread
From: Shuah Khan @ 2021-05-05 15:54 UTC (permalink / raw)
  To: Igor Matheus Andrade Torrente, mchehab, hverkuil-cisco
  Cc: linux-media, linux-kernel, Shuah Khan

On 5/4/21 2:32 PM, Igor Matheus Andrade Torrente wrote:
> The em28xx struct kref isn't being decreased after an error in the
> em28xx_ir_init, leading to a possible memory leak.
> 
> A kref_put and em28xx_shutdown_buttons is added to the error handler code.
> 
> Signed-off-by: Igor Matheus Andrade Torrente <igormtorrente@gmail.com>
> ---

Hi Igor,

Please look at Hans's response and comments to your v1 patch. v4l core
addresses the lifetime issues now and this driver could be updated to
use them instead if fixing the problems in this driver's resource
lifetime mgmt code.

Please follow his review comments to address the issue based on his 
suggestions.

thanks,
-- Shuah

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

* Re: [PATCH v2] media: em28xx: Fix possible memory leak of em28xx struct
  2021-05-05 15:54 ` Shuah Khan
@ 2021-05-06  7:43   ` Hans Verkuil
  0 siblings, 0 replies; 3+ messages in thread
From: Hans Verkuil @ 2021-05-06  7:43 UTC (permalink / raw)
  To: Shuah Khan, Igor Matheus Andrade Torrente, mchehab
  Cc: linux-media, linux-kernel

On 05/05/2021 17:54, Shuah Khan wrote:
> On 5/4/21 2:32 PM, Igor Matheus Andrade Torrente wrote:
>> The em28xx struct kref isn't being decreased after an error in the
>> em28xx_ir_init, leading to a possible memory leak.
>>
>> A kref_put and em28xx_shutdown_buttons is added to the error handler code.
>>
>> Signed-off-by: Igor Matheus Andrade Torrente <igormtorrente@gmail.com>
>> ---
> 
> Hi Igor,
> 
> Please look at Hans's response and comments to your v1 patch. v4l core
> addresses the lifetime issues now and this driver could be updated to
> use them instead if fixing the problems in this driver's resource
> lifetime mgmt code.

Actually, this patch is fine (I think, still need to review it). This is
related to the input part, not v4l2.

Regards,

	Hans

> 
> Please follow his review comments to address the issue based on his 
> suggestions.
> 
> thanks,
> -- Shuah
> 


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

end of thread, other threads:[~2021-05-06  7:43 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-04 18:32 [PATCH v2] media: em28xx: Fix possible memory leak of em28xx struct Igor Matheus Andrade Torrente
2021-05-05 15:54 ` Shuah Khan
2021-05-06  7:43   ` Hans Verkuil

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).