* [PATCH v3] ALSA: usb-audio: validate full match when resolving quirk aliases
@ 2026-03-18 14:08 Cássio Gabriel
2026-03-18 16:03 ` Takashi Iwai
0 siblings, 1 reply; 2+ messages in thread
From: Cássio Gabriel @ 2026-03-18 14:08 UTC (permalink / raw)
To: Takashi Iwai
Cc: Jaroslav Kysela, Greg Kroah-Hartman, linux-sound, linux-usb,
linux-kernel, Takashi Iwai, Cássio Gabriel
get_alias_quirk() resolves a quirk for an aliased USB ID by scanning
usb_audio_ids[], but it currently checks only the vendor/product pair.
This is weak for quirk table entries that also depend on additional
USB_DEVICE_ID match fields, such as device or interface class,
subclass, protocol, interface number, or bcdDevice range.
Keep the aliased vid:pid as the lookup key, then validate only the
remaining match criteria of each candidate entry against the real
device/interface descriptors by clearing USB_DEVICE_ID_MATCH_DEVICE
from a temporary copy and passing it to usb_match_one_id().
Suggested-by: Takashi Iwai <tiwai@suse.de>
Signed-off-by: Cássio Gabriel <cassiogabrielcontato@gmail.com>
---
Changes in v3:
- rework alias quirk matching as suggested by Takashi Iwai
- drop the explicit per-field helper
- keep the aliased vid:pid check first
- clear USB_DEVICE_ID_MATCH_DEVICE from a temporary id copy
- Link to v2: https://lore.kernel.org/r/20260317-alsa-usb-fix-quirk-alias-v2-1-6e531c67f0c8@gmail.com
Changes in v2:
- drop the temporary usb_device_id reconstruction approach
- validate only the remaining match_flags explicitly
- pass struct usb_interface * to get_alias_quirk()
- Link to v1: https://lore.kernel.org/r/20260314-alsa-usb-fix-quirk-alias-v1-1-3269998f7ada@gmail.com
---
sound/usb/card.c | 24 +++++++++++++++---------
1 file changed, 15 insertions(+), 9 deletions(-)
diff --git a/sound/usb/card.c b/sound/usb/card.c
index fd81f32a66fb..f42d72cd0378 100644
--- a/sound/usb/card.c
+++ b/sound/usb/card.c
@@ -866,19 +866,25 @@ static void find_last_interface(struct snd_usb_audio *chip)
/* look for the corresponding quirk */
static const struct snd_usb_audio_quirk *
-get_alias_quirk(struct usb_device *dev, unsigned int id)
+get_alias_quirk(struct usb_interface *intf, unsigned int id)
{
const struct usb_device_id *p;
+ struct usb_device_id match_id;
for (p = usb_audio_ids; p->match_flags; p++) {
- /* FIXME: this checks only vendor:product pair in the list */
- if ((p->match_flags & USB_DEVICE_ID_MATCH_DEVICE) ==
- USB_DEVICE_ID_MATCH_DEVICE &&
- p->idVendor == USB_ID_VENDOR(id) &&
- p->idProduct == USB_ID_PRODUCT(id))
- return (const struct snd_usb_audio_quirk *)p->driver_info;
- }
+ if ((p->match_flags & USB_DEVICE_ID_MATCH_DEVICE) !=
+ USB_DEVICE_ID_MATCH_DEVICE)
+ continue;
+ if (p->idVendor != USB_ID_VENDOR(id) ||
+ p->idProduct != USB_ID_PRODUCT(id))
+ continue;
+ match_id = *p;
+ match_id.match_flags &= ~USB_DEVICE_ID_MATCH_DEVICE;
+ if (!match_id.match_flags || usb_match_one_id(intf, &match_id))
+ return (const struct snd_usb_audio_quirk *)
+ p->driver_info;
+ }
return NULL;
}
@@ -927,7 +933,7 @@ static int usb_audio_probe(struct usb_interface *intf,
id = USB_ID(le16_to_cpu(dev->descriptor.idVendor),
le16_to_cpu(dev->descriptor.idProduct));
if (get_alias_id(dev, &id))
- quirk = get_alias_quirk(dev, id);
+ quirk = get_alias_quirk(intf, id);
if (quirk && quirk->ifnum >= 0 && ifnum != quirk->ifnum)
return -ENXIO;
if (quirk && quirk->ifnum == QUIRK_NODEV_INTERFACE)
---
base-commit: f803b7bb17dd19fbd84fe783683321f38834a1df
change-id: 20260313-alsa-usb-fix-quirk-alias-e9c8300ba836
Best regards,
--
Cássio Gabriel <cassiogabrielcontato@gmail.com>
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v3] ALSA: usb-audio: validate full match when resolving quirk aliases
2026-03-18 14:08 [PATCH v3] ALSA: usb-audio: validate full match when resolving quirk aliases Cássio Gabriel
@ 2026-03-18 16:03 ` Takashi Iwai
0 siblings, 0 replies; 2+ messages in thread
From: Takashi Iwai @ 2026-03-18 16:03 UTC (permalink / raw)
To: Cássio Gabriel
Cc: Takashi Iwai, Jaroslav Kysela, Greg Kroah-Hartman, linux-sound,
linux-usb, linux-kernel, Takashi Iwai
On Wed, 18 Mar 2026 15:08:46 +0100,
Cássio Gabriel wrote:
>
> get_alias_quirk() resolves a quirk for an aliased USB ID by scanning
> usb_audio_ids[], but it currently checks only the vendor/product pair.
>
> This is weak for quirk table entries that also depend on additional
> USB_DEVICE_ID match fields, such as device or interface class,
> subclass, protocol, interface number, or bcdDevice range.
>
> Keep the aliased vid:pid as the lookup key, then validate only the
> remaining match criteria of each candidate entry against the real
> device/interface descriptors by clearing USB_DEVICE_ID_MATCH_DEVICE
> from a temporary copy and passing it to usb_match_one_id().
>
> Suggested-by: Takashi Iwai <tiwai@suse.de>
> Signed-off-by: Cássio Gabriel <cassiogabrielcontato@gmail.com>
> ---
> Changes in v3:
> - rework alias quirk matching as suggested by Takashi Iwai
> - drop the explicit per-field helper
> - keep the aliased vid:pid check first
> - clear USB_DEVICE_ID_MATCH_DEVICE from a temporary id copy
> - Link to v2: https://lore.kernel.org/r/20260317-alsa-usb-fix-quirk-alias-v2-1-6e531c67f0c8@gmail.com
>
> Changes in v2:
> - drop the temporary usb_device_id reconstruction approach
> - validate only the remaining match_flags explicitly
> - pass struct usb_interface * to get_alias_quirk()
> - Link to v1: https://lore.kernel.org/r/20260314-alsa-usb-fix-quirk-alias-v1-1-3269998f7ada@gmail.com
Applied to for-next branch now. Thanks.
Takashi
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-03-18 16:03 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-18 14:08 [PATCH v3] ALSA: usb-audio: validate full match when resolving quirk aliases Cássio Gabriel
2026-03-18 16:03 ` Takashi Iwai
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox