mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] ALSA: scarlett2: Fix a potential memory leak in scarlett2_init_notify()
@ 2023-09-03 12:41 Christophe JAILLET
  2023-09-03 14:27 ` Takashi Iwai
  0 siblings, 1 reply; 3+ messages in thread
From: Christophe JAILLET @ 2023-09-03 12:41 UTC (permalink / raw)
  To: Geoffrey D. Bennett, Jaroslav Kysela, Takashi Iwai
  Cc: linux-kernel, kernel-janitors, Christophe JAILLET, Takashi Iwai,
	alsa-devel

If kmalloc() fails, we should release 'mixer->urb'.

Fixes: 9e4d5c1be21f ("ALSA: usb-audio: Scarlett Gen 2 mixer interface")
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
 sound/usb/mixer_scarlett_gen2.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/sound/usb/mixer_scarlett_gen2.c b/sound/usb/mixer_scarlett_gen2.c
index 9d11bb08667e..a439c7f64b2e 100644
--- a/sound/usb/mixer_scarlett_gen2.c
+++ b/sound/usb/mixer_scarlett_gen2.c
@@ -4060,8 +4060,10 @@ static int scarlett2_init_notify(struct usb_mixer_interface *mixer)
 		return -ENOMEM;
 
 	transfer_buffer = kmalloc(private->wMaxPacketSize, GFP_KERNEL);
-	if (!transfer_buffer)
+	if (!transfer_buffer) {
+		usb_free_urb(mixer->urb);
 		return -ENOMEM;
+	}
 
 	usb_fill_int_urb(mixer->urb, dev, pipe,
 			 transfer_buffer, private->wMaxPacketSize,
-- 
2.34.1


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

* Re: [PATCH] ALSA: scarlett2: Fix a potential memory leak in scarlett2_init_notify()
  2023-09-03 12:41 [PATCH] ALSA: scarlett2: Fix a potential memory leak in scarlett2_init_notify() Christophe JAILLET
@ 2023-09-03 14:27 ` Takashi Iwai
  2023-09-03 15:08   ` Christophe JAILLET
  0 siblings, 1 reply; 3+ messages in thread
From: Takashi Iwai @ 2023-09-03 14:27 UTC (permalink / raw)
  To: Christophe JAILLET
  Cc: Geoffrey D. Bennett, Jaroslav Kysela, Takashi Iwai, linux-kernel,
	kernel-janitors, alsa-devel

On Sun, 03 Sep 2023 14:41:45 +0200,
Christophe JAILLET wrote:
> 
> If kmalloc() fails, we should release 'mixer->urb'.

This is released at the common error path in mixer.c,
snd_usb_mixer_free(), hence it's not needed.

And, even if freeing here, you must NULL-clear mixer->urb, too;
otherwise it'll lead to double-free.


thanks,

Takashi

> 
> Fixes: 9e4d5c1be21f ("ALSA: usb-audio: Scarlett Gen 2 mixer interface")
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> ---
>  sound/usb/mixer_scarlett_gen2.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/sound/usb/mixer_scarlett_gen2.c b/sound/usb/mixer_scarlett_gen2.c
> index 9d11bb08667e..a439c7f64b2e 100644
> --- a/sound/usb/mixer_scarlett_gen2.c
> +++ b/sound/usb/mixer_scarlett_gen2.c
> @@ -4060,8 +4060,10 @@ static int scarlett2_init_notify(struct usb_mixer_interface *mixer)
>  		return -ENOMEM;
>  
>  	transfer_buffer = kmalloc(private->wMaxPacketSize, GFP_KERNEL);
> -	if (!transfer_buffer)
> +	if (!transfer_buffer) {
> +		usb_free_urb(mixer->urb);
>  		return -ENOMEM;
> +	}
>  
>  	usb_fill_int_urb(mixer->urb, dev, pipe,
>  			 transfer_buffer, private->wMaxPacketSize,
> -- 
> 2.34.1
> 

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

* Re: [PATCH] ALSA: scarlett2: Fix a potential memory leak in scarlett2_init_notify()
  2023-09-03 14:27 ` Takashi Iwai
@ 2023-09-03 15:08   ` Christophe JAILLET
  0 siblings, 0 replies; 3+ messages in thread
From: Christophe JAILLET @ 2023-09-03 15:08 UTC (permalink / raw)
  To: Takashi Iwai
  Cc: Geoffrey D. Bennett, Jaroslav Kysela, Takashi Iwai, linux-kernel,
	kernel-janitors, alsa-devel

Le 03/09/2023 à 16:27, Takashi Iwai a écrit :
> On Sun, 03 Sep 2023 14:41:45 +0200,
> Christophe JAILLET wrote:
>>
>> If kmalloc() fails, we should release 'mixer->urb'.
> 
> This is released at the common error path in mixer.c,
> snd_usb_mixer_free(), hence it's not needed.

Agreed, sorry for the noise.

CJ

> 
> And, even if freeing here, you must NULL-clear mixer->urb, too;
> otherwise it'll lead to double-free.
> 
> 
> thanks,
> 
> Takashi
> 
>>
>> Fixes: 9e4d5c1be21f ("ALSA: usb-audio: Scarlett Gen 2 mixer interface")
>> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
>> ---
>>   sound/usb/mixer_scarlett_gen2.c | 4 +++-
>>   1 file changed, 3 insertions(+), 1 deletion(-)
>>
>> diff --git a/sound/usb/mixer_scarlett_gen2.c b/sound/usb/mixer_scarlett_gen2.c
>> index 9d11bb08667e..a439c7f64b2e 100644
>> --- a/sound/usb/mixer_scarlett_gen2.c
>> +++ b/sound/usb/mixer_scarlett_gen2.c
>> @@ -4060,8 +4060,10 @@ static int scarlett2_init_notify(struct usb_mixer_interface *mixer)
>>   		return -ENOMEM;
>>   
>>   	transfer_buffer = kmalloc(private->wMaxPacketSize, GFP_KERNEL);
>> -	if (!transfer_buffer)
>> +	if (!transfer_buffer) {
>> +		usb_free_urb(mixer->urb);
>>   		return -ENOMEM;
>> +	}
>>   
>>   	usb_fill_int_urb(mixer->urb, dev, pipe,
>>   			 transfer_buffer, private->wMaxPacketSize,
>> -- 
>> 2.34.1
>>
> 


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

end of thread, other threads:[~2023-09-03 15:08 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-03 12:41 [PATCH] ALSA: scarlett2: Fix a potential memory leak in scarlett2_init_notify() Christophe JAILLET
2023-09-03 14:27 ` Takashi Iwai
2023-09-03 15:08   ` Christophe JAILLET

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®