public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Takashi Iwai <tiwai@suse.de>
To: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Cc: Jaroslav Kysela <perex@perex.cz>, Takashi Iwai <tiwai@suse.com>,
	linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org,
	alsa-devel@alsa-project.org
Subject: Re: [PATCH] ALSA: usb-audio: Fix a potential memory leak in scarlett2_init_notify()
Date: Sun, 03 Sep 2023 16:23:54 +0200	[thread overview]
Message-ID: <871qffmj2d.wl-tiwai@suse.de> (raw)
In-Reply-To: <fc275ed315b9157952dcf2744ee7bdb78defdb5f.1693746347.git.christophe.jaillet@wanadoo.fr>

On Sun, 03 Sep 2023 15:06:00 +0200,
Christophe JAILLET wrote:
> 
> If usb_alloc_coherent() or usb_urb_ep_type_check() fail, we should release
> the resources previously allocated.

Those are freed in the caller side, start_input_streams() instead.


thanks,

Takashi

> 
> Fixes: ff49d1df79ae ("ALSA: usb-audio: USB MIDI 2.0 UMP support")
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> ---
>  sound/usb/midi2.c | 17 ++++++++++++++---
>  1 file changed, 14 insertions(+), 3 deletions(-)
> 
> diff --git a/sound/usb/midi2.c b/sound/usb/midi2.c
> index a27e244650c8..4109c82adff6 100644
> --- a/sound/usb/midi2.c
> +++ b/sound/usb/midi2.c
> @@ -302,7 +302,8 @@ static int alloc_midi_urbs(struct snd_usb_midi2_endpoint *ep)
>  		ctx->urb = usb_alloc_urb(0, GFP_KERNEL);
>  		if (!ctx->urb) {
>  			dev_err(&ep->dev->dev, "URB alloc failed\n");
> -			return -ENOMEM;
> +			err = -ENOMEM;
> +			goto err_free_all;
>  		}
>  		ctx->ep = ep;
>  		buffer = usb_alloc_coherent(ep->dev, len, GFP_KERNEL,
> @@ -310,7 +311,8 @@ static int alloc_midi_urbs(struct snd_usb_midi2_endpoint *ep)
>  		if (!buffer) {
>  			dev_err(&ep->dev->dev,
>  				"URB buffer alloc failed (size %d)\n", len);
> -			return -ENOMEM;
> +			err = -ENOMEM;
> +			goto err_free_cur_urb;
>  		}
>  		if (ep->interval)
>  			usb_fill_int_urb(ctx->urb, ep->dev, ep->pipe,
> @@ -322,13 +324,22 @@ static int alloc_midi_urbs(struct snd_usb_midi2_endpoint *ep)
>  		if (err < 0) {
>  			dev_err(&ep->dev->dev, "invalid MIDI EP %x\n",
>  				endpoint);
> -			return err;
> +			goto err_free_cur_dma;
>  		}
>  		ctx->urb->transfer_flags = URB_NO_TRANSFER_DMA_MAP;
>  		ep->num_urbs++;
>  	}
>  	ep->urb_free = ep->urb_free_mask = GENMASK(ep->num_urbs - 1, 0);
>  	return 0;
> +
> +err_free_cur_dma:
> +	usb_free_coherent(ep->dev, len, buffer, ctx->urb->transfer_dma);
> +err_free_cur_urb:
> +	usb_free_urb(ctx->urb);
> +	ctx->urb = NULL;
> +err_free_all:
> +	free_midi_urbs(ep);
> +	return err;
>  }
>  
>  static struct snd_usb_midi2_endpoint *
> -- 
> 2.34.1
> 

  reply	other threads:[~2023-09-03 14:24 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-03 13:06 [PATCH] ALSA: usb-audio: Fix a potential memory leak in scarlett2_init_notify() Christophe JAILLET
2023-09-03 14:23 ` Takashi Iwai [this message]
2023-09-03 15:04   ` Christophe JAILLET
2023-09-03 16:37     ` Takashi Iwai
2023-09-03 19:42       ` Christophe JAILLET
2023-09-04 14:08         ` Takashi Iwai
2023-09-05  5:39           ` Takashi Iwai

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=871qffmj2d.wl-tiwai@suse.de \
    --to=tiwai@suse.de \
    --cc=alsa-devel@alsa-project.org \
    --cc=christophe.jaillet@wanadoo.fr \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=perex@perex.cz \
    --cc=tiwai@suse.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox