From: Takashi Iwai <tiwai@suse.de>
To: Berk Cem Goksel <berkcgoksel@gmail.com>
Cc: Takashi Iwai <tiwai@suse.com>, Jaroslav Kysela <perex@perex.cz>,
linux-sound@vger.kernel.org, linux-kernel@vger.kernel.org,
Andrey Konovalov <andreyknvl@gmail.com>,
stable@vger.kernel.org
Subject: Re: [PATCH 2/2] ALSA: caiaq: take a reference on the USB device in create_card()
Date: Fri, 10 Apr 2026 08:31:24 +0200 [thread overview]
Message-ID: <87tstjgwcj.wl-tiwai@suse.de> (raw)
In-Reply-To: <20260410045904.1064020-3-berkcgoksel@gmail.com>
On Fri, 10 Apr 2026 06:59:04 +0200,
Berk Cem Goksel wrote:
>
> The caiaq driver stores a pointer to the parent USB device in
> cdev->chip.dev but never takes a reference on it. The card's
> private_free callback, snd_usb_caiaq_card_free(), can run
> asynchronously via snd_card_free_when_closed() after the USB
> device has already been disconnected and freed, so any access to
> cdev->chip.dev in that path dereferences a freed usb_device.
>
> On top of the refcounting issue, the current card_free implementation
> calls usb_reset_device(cdev->chip.dev). A reset in a free callback
> is inappropriate: the device is going away, the call takes the
> device lock in a teardown context, and the reset races with the
> disconnect path that the callback is already cleaning up after.
>
> Take a reference on the USB device in create_card() with
> usb_get_dev(), drop it with usb_put_dev() in the free callback,
> and remove the usb_reset_device() call.
>
> Fixes: 523f1dce7096 ("ALSA: snd-usb-caiaq: add support for NI Audio Kontrol 1")
> Cc: stable@vger.kernel.org
> Cc: Andrey Konovalov <andreyknvl@gmail.com>
> Signed-off-by: Berk Cem Goksel <berkcgoksel@gmail.com>
> ---
> sound/usb/caiaq/device.c | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/sound/usb/caiaq/device.c b/sound/usb/caiaq/device.c
> --- a/sound/usb/caiaq/device.c
> +++ b/sound/usb/caiaq/device.c
> @@ -385,7 +385,8 @@
> snd_usb_caiaq_input_free(cdev);
> #endif
> snd_usb_caiaq_audio_free(cdev);
> - usb_reset_device(cdev->chip.dev);
> + if (cdev->chip.dev)
> + usb_put_dev(cdev->chip.dev);
usb_put_dev() itself has a NULL check, so you can pass as is, too.
And, the Fixes tag is incorrect in this patch, too.
thanks,
Takashi
> }
>
> static int create_card(struct usb_device *usb_dev,
> @@ -411,7 +412,7 @@
> return err;
>
> cdev = caiaqdev(card);
> - cdev->chip.dev = usb_dev;
> + cdev->chip.dev = usb_get_dev(usb_dev);
> cdev->chip.card = card;
> cdev->chip.usb_id = USB_ID(le16_to_cpu(usb_dev->descriptor.idVendor),
> le16_to_cpu(usb_dev->descriptor.idProduct));
prev parent reply other threads:[~2026-04-10 6:31 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20260410045904.1064020-1-berkcgoksel@gmail.com>
2026-04-10 4:59 ` [PATCH 1/2] ALSA: caiaq: fix use-after-free and double-free in setup_card() Berk Cem Goksel
2026-04-10 6:26 ` Takashi Iwai
2026-04-10 4:59 ` [PATCH 2/2] ALSA: caiaq: take a reference on the USB device in create_card() Berk Cem Goksel
2026-04-10 6:31 ` Takashi Iwai [this message]
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=87tstjgwcj.wl-tiwai@suse.de \
--to=tiwai@suse.de \
--cc=andreyknvl@gmail.com \
--cc=berkcgoksel@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-sound@vger.kernel.org \
--cc=perex@perex.cz \
--cc=stable@vger.kernel.org \
--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