public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ALSA: scarlett2: Prevent leaking urb
@ 2024-05-21  1:03 Chen Ni
  2024-05-21 13:02 ` Takashi Iwai
  0 siblings, 1 reply; 2+ messages in thread
From: Chen Ni @ 2024-05-21  1:03 UTC (permalink / raw)
  To: g, perex, tiwai; +Cc: alsa-devel, linux-sound, linux-kernel, Chen Ni

In scarlett2_init_notify() if kmalloc() fails the allocated urb should
be released.

Signed-off-by: Chen Ni <nichen@iscas.ac.cn>
---
 sound/usb/mixer_scarlett2.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/sound/usb/mixer_scarlett2.c b/sound/usb/mixer_scarlett2.c
index 1150cf104985..4cad6b2a0292 100644
--- a/sound/usb/mixer_scarlett2.c
+++ b/sound/usb/mixer_scarlett2.c
@@ -8637,9 +8637,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,
 			 scarlett2_notify, mixer, private->bInterval);
-- 
2.25.1


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

* Re: [PATCH] ALSA: scarlett2: Prevent leaking urb
  2024-05-21  1:03 [PATCH] ALSA: scarlett2: Prevent leaking urb Chen Ni
@ 2024-05-21 13:02 ` Takashi Iwai
  0 siblings, 0 replies; 2+ messages in thread
From: Takashi Iwai @ 2024-05-21 13:02 UTC (permalink / raw)
  To: Chen Ni; +Cc: g, perex, tiwai, alsa-devel, linux-sound, linux-kernel

On Tue, 21 May 2024 03:03:52 +0200,
Chen Ni wrote:
> 
> In scarlett2_init_notify() if kmalloc() fails the allocated urb should
> be released.

It's freed in the common USB mixer destructor (snd_usb_mixer_free()),
hence your patch will lead to a double-free.


thanks,

Takashi

> 
> Signed-off-by: Chen Ni <nichen@iscas.ac.cn>
> ---
>  sound/usb/mixer_scarlett2.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/sound/usb/mixer_scarlett2.c b/sound/usb/mixer_scarlett2.c
> index 1150cf104985..4cad6b2a0292 100644
> --- a/sound/usb/mixer_scarlett2.c
> +++ b/sound/usb/mixer_scarlett2.c
> @@ -8637,9 +8637,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,
>  			 scarlett2_notify, mixer, private->bInterval);
> -- 
> 2.25.1
> 
> 

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

end of thread, other threads:[~2024-05-21 13:02 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-05-21  1:03 [PATCH] ALSA: scarlett2: Prevent leaking urb Chen Ni
2024-05-21 13:02 ` Takashi Iwai

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