Skip to contentSkip to conversation

ALSA: usb-audio: Reduce device table

PATCH In review Takashi Iwai 2 participants 8 messages Aug 17, 2020 – Aug 23, 2020 Sound

lore
Share & tools
lore
#0 lore raw

cover ALSA: usb-audio: Reduce device table

Hi,

this is a patch set for USB-audio driver to reduce the unnecessary entries from the exported device table. Also it contains the corrections of the device matching for a few entries to be more strict.

Takashi

===

Takashi Iwai (3):
ALSA: usb-audio: Move device rename and profile quirks to an internal
table
ALSA: usb-audio: Simplify quirk entries with a macro
ALSA: usb-audio: Properly match with audio interface class

 sound/usb/card.c         | 133 +++++++++++++++++++++--
 sound/usb/quirks-table.h | 276 +++++++----------------------------------------
 sound/usb/usbaudio.h     |   1 -
 3 files changed, 162 insertions(+), 248 deletions(-)
Signature · 1 line
2.16.4
#1 lore raw

PATCH 1/3 ALSA: usb-audio: Move device rename and profile quirks to an internal table

So far we've added the devices that need vendor/product string renames or the profile setup into the standard quirk table in quirks-table.h. This table is imported into the primary USB audio device entry, hence it's all exported for the probing so that udev and co can take a look at it. OTOH, for renaming or profile setup, we don't need to expose those explicit entries because the probe itself follows the standard way. That said, we're exposing unnecessarily too many entries.

This patch moves such internal quirk entries into the own table, and reduces the exported device table size. Along with the moving items, re-arrange the entries in the proper order.

---
 sound/usb/card.c         | 133 +++++++++++++++++++++++++++++++++++++++++++----
 sound/usb/quirks-table.h | 120 ------------------------------------------
 sound/usb/usbaudio.h     |   1 -
 3 files changed, 124 insertions(+), 130 deletions(-)
sound/usb/card.c +124 -9
index 696e788c5d31..fa764b61fe9c 100644
@@ -332,6 +332,106 @@ static int snd_usb_create_streams(struct snd_usb_audio *chip, int ctrlif)
 	return 0;
 }
 
+/*
+ * Profile name preset table
+ */
+struct usb_audio_device_name {
+	u32 id;
+	const char *vendor_name;
+	const char *product_name;
+	const char *profile_name;	/* override card->longname */
+};
+
+#define PROFILE_NAME(vid, pid, vendor, product, profile)	 \
+	{ .id = USB_ID(vid, pid), .vendor_name = (vendor),	 \
+	  .product_name = (product), .profile_name = (profile) }
+#define DEVICE_NAME(vid, pid, vendor, product) \
+	PROFILE_NAME(vid, pid, vendor, product, NULL)
+
+/* vendor/product and profile name presets, sorted in device id order */
+static const struct usb_audio_device_name usb_audio_names[] = {
+	/* HP Thunderbolt Dock Audio Headset */
+	PROFILE_NAME(0x03f0, 0x0269, "HP", "Thunderbolt Dock Audio Headset",
+		     "HP-Thunderbolt-Dock-Audio-Headset"),
+	/* HP Thunderbolt Dock Audio Module */
+	PROFILE_NAME(0x03f0, 0x0567, "HP", "Thunderbolt Dock Audio Module",
+		     "HP-Thunderbolt-Dock-Audio-Module"),
+
+	/* Two entries for Gigabyte TRX40 Aorus Master:
+	 * TRX40 Aorus Master has two USB-audio devices, one for the front
+	 * headphone with ESS SABRE9218 DAC chip, while another for the rest
+	 * I/O (the rear panel and the front mic) with Realtek ALC1220-VB.
+	 * Here we provide two distinct names for making UCM profiles easier.
+	 */
+	PROFILE_NAME(0x0414, 0xa000, "Gigabyte", "Aorus Master Front Headphone",
+		     "Gigabyte-Aorus-Master-Front-Headphone"),
+	PROFILE_NAME(0x0414, 0xa001, "Gigabyte", "Aorus Master Main Audio",
+		     "Gigabyte-Aorus-Master-Main-Audio"),
+
+	/* Gigabyte TRX40 Aorus Pro WiFi */
+	PROFILE_NAME(0x0414, 0xa002,
+		     "Realtek", "ALC1220-VB-DT", "Realtek-ALC1220-VB-Desktop"),
+
+	/* Creative/E-Mu devices */
+	DEVICE_NAME(0x041e, 0x3010, "Creative Labs", "Sound Blaster MP3+"),
+	/* Creative/Toshiba Multimedia Center SB-0500 */
+	DEVICE_NAME(0x041e, 0x3048, "Toshiba", "SB-0500"),
+
+	DEVICE_NAME(0x046d, 0x0990, "Logitech, Inc.", "QuickCam Pro 9000"),
+
+	/* Dell WD15 Dock */
+	PROFILE_NAME(0x0bda, 0x4014, "Dell", "WD15 Dock", "Dell-WD15-Dock"),
+	/* Dell WD19 Dock */
+	PROFILE_NAME(0x0bda, 0x402e, "Dell", "WD19 Dock", "Dell-WD15-Dock"),
+
+	DEVICE_NAME(0x0ccd, 0x0028, "TerraTec", "Aureon5.1MkII"),
+
+	/*
+	 * The original product_name is "USB Sound Device", however this name
+	 * is also used by the CM106 based cards, so make it unique.
+	 */
+	DEVICE_NAME(0x0d8c, 0x0102, NULL, "ICUSBAUDIO7D"),
+	DEVICE_NAME(0x0d8c, 0x0103, NULL, "Audio Advantage MicroII"),
+
+	/* MSI TRX40 Creator */
+	PROFILE_NAME(0x0db0, 0x0d64,
+		     "Realtek", "ALC1220-VB-DT", "Realtek-ALC1220-VB-Desktop"),
+	/* MSI TRX40 */
+	PROFILE_NAME(0x0db0, 0x543d,
+		     "Realtek", "ALC1220-VB-DT", "Realtek-ALC1220-VB-Desktop"),
+
+	/* Stanton/N2IT Final Scratch v1 device ('Scratchamp') */
+	DEVICE_NAME(0x103d, 0x0100, "Stanton", "ScratchAmp"),
+	DEVICE_NAME(0x103d, 0x0101, "Stanton", "ScratchAmp"),
+
+	/* aka. Serato Scratch Live DJ Box */
+	DEVICE_NAME(0x13e5, 0x0001, "Rane", "SL-1"),
+
+	/* Lenovo ThinkStation P620 Rear Line-in, Line-out and Microphone */
+	PROFILE_NAME(0x17aa, 0x1046, "Lenovo", "ThinkStation P620 Rear",
+		     "Lenovo-ThinkStation-P620-Rear"),
+	/* Lenovo ThinkStation P620 Internal Speaker + Front Headset */
+	PROFILE_NAME(0x17aa, 0x104d, "Lenovo", "ThinkStation P620 Main",
+		     "Lenovo-ThinkStation-P620-Main"),
+
+	/* Asrock TRX40 Creator */
+	PROFILE_NAME(0x26ce, 0x0a01,
+		     "Realtek", "ALC1220-VB-DT", "Realtek-ALC1220-VB-Desktop"),
+
+	{ } /* terminator */
+};
+
+static const struct usb_audio_device_name *
+lookup_device_name(u32 id)
+{
+	static const struct usb_audio_device_name *p;
+
+	for (p = usb_audio_names; p->id; p++)
+		if (p->id == id)
+			return p;
+	return NULL;
+}
+
 /*
  * free the chip instance
  *
@@ -357,10 +457,16 @@ static void usb_audio_make_shortname(struct usb_device *dev,
 				     const struct snd_usb_audio_quirk *quirk)
 {
 	struct snd_card *card = chip->card;
-
-	if (quirk && quirk->product_name && *quirk->product_name) {
-		strlcpy(card->shortname, quirk->product_name,
-			sizeof(card->shortname));
+	const struct usb_audio_device_name *preset;
+	const char *s = NULL;
+
+	preset = lookup_device_name(chip->usb_id);
+	if (preset && preset->product_name)
+		s = preset->product_name;
+	else if (quirk && quirk->product_name)
+		s = quirk->product_name;
+	if (s && *s) {
+		strlcpy(card->shortname, s, sizeof(card->shortname));
 		return;
 	}
 
@@ -382,17 +488,26 @@ static void usb_audio_make_longname(struct usb_device *dev,
 				    const struct snd_usb_audio_quirk *quirk)
 {
 	struct snd_card *card = chip->card;
+	const struct usb_audio_device_name *preset;
+	const char *s = NULL;
 	int len;
 
+	preset = lookup_device_name(chip->usb_id);
+
 	/* shortcut - if any pre-defined string is given, use it */
-	if (quirk && quirk->profile_name && *quirk->profile_name) {
-		strlcpy(card->longname, quirk->profile_name,
-			sizeof(card->longname));
+	if (preset && preset->profile_name)
+		s = preset->profile_name;
+	if (s && *s) {
+		strlcpy(card->longname, s, sizeof(card->longname));
 		return;
 	}
 
-	if (quirk && quirk->vendor_name && *quirk->vendor_name) {
-		len = strlcpy(card->longname, quirk->vendor_name, sizeof(card->longname));
+	if (preset && preset->vendor_name)
+		s = preset->vendor_name;
+	else if (quirk && quirk->vendor_name)
+		s = quirk->vendor_name;
+	if (s && *s) {
+		len = strlcpy(card->longname, s, sizeof(card->longname));
 	} else {
 		/* retrieve the vendor and device strings as longname */
 		if (dev->descriptor.iManufacturer)
sound/usb/quirks-table.h +0 -120

178 lines not on this page · raw message

sound/usb/usbaudio.h +0 -1
index b91c4c0807ec..2275295fe71f 100644
@@ -109,7 +109,6 @@ enum quirk_type {
 struct snd_usb_audio_quirk {
 	const char *vendor_name;
 	const char *product_name;
-	const char *profile_name;	/* override the card->longname */
 	int16_t ifnum;
 	uint16_t type;
 	bool shares_media_device;
Signature · 1 line
2.16.4
#2 lore raw

PATCH 2/3 ALSA: usb-audio: Simplify quirk entries with a macro

In reply to Takashi Iwai

Introduce a new macro USB_AUDIO_DEVICE() for the entries matching with the pid/vid pair and the class/subclass, and remove the open-code.

---
 sound/usb/quirks-table.h | 105 ++++++++++-------------------------------------
 1 file changed, 21 insertions(+), 84 deletions(-)
sound/usb/quirks-table.h +21 -84
index 978f7113bd81..988bb9d00192 100644
@@ -25,6 +25,16 @@
 	.idProduct = prod, \
 	.bInterfaceClass = USB_CLASS_VENDOR_SPEC
 
+/* A standard entry matching with vid/pid and the audio class/subclass */
+#define USB_AUDIO_DEVICE(vend, prod) \
+	.match_flags = USB_DEVICE_ID_MATCH_DEVICE | \
+		       USB_DEVICE_ID_MATCH_INT_CLASS | \
+		       USB_DEVICE_ID_MATCH_INT_SUBCLASS, \
+	.idVendor = vend, \
+	.idProduct = prod, \
+	.bInterfaceClass = USB_CLASS_AUDIO, \
+	.bInterfaceSubClass = USB_SUBCLASS_AUDIOCONTROL
+
 /* FTDI devices */
 {
 	USB_DEVICE(0x0403, 0xb8d8),
@@ -127,69 +137,13 @@
  * Logitech QuickCam: bDeviceClass is vendor-specific, so generic interface
  * class matches do not take effect without an explicit ID match.
  */
-{
-	.match_flags = USB_DEVICE_ID_MATCH_DEVICE |
-		       USB_DEVICE_ID_MATCH_INT_CLASS |
-		       USB_DEVICE_ID_MATCH_INT_SUBCLASS,
-	.idVendor = 0x046d,
-	.idProduct = 0x0850,
-	.bInterfaceClass = USB_CLASS_AUDIO,
-	.bInterfaceSubClass = USB_SUBCLASS_AUDIOCONTROL
-},
-{
-	.match_flags = USB_DEVICE_ID_MATCH_DEVICE |
-		       USB_DEVICE_ID_MATCH_INT_CLASS |
-		       USB_DEVICE_ID_MATCH_INT_SUBCLASS,
-	.idVendor = 0x046d,
-	.idProduct = 0x08ae,
-	.bInterfaceClass = USB_CLASS_AUDIO,
-	.bInterfaceSubClass = USB_SUBCLASS_AUDIOCONTROL
-},
-{
-	.match_flags = USB_DEVICE_ID_MATCH_DEVICE |
-		       USB_DEVICE_ID_MATCH_INT_CLASS |
-		       USB_DEVICE_ID_MATCH_INT_SUBCLASS,
-	.idVendor = 0x046d,
-	.idProduct = 0x08c6,
-	.bInterfaceClass = USB_CLASS_AUDIO,
-	.bInterfaceSubClass = USB_SUBCLASS_AUDIOCONTROL
-},
-{
-	.match_flags = USB_DEVICE_ID_MATCH_DEVICE |
-		       USB_DEVICE_ID_MATCH_INT_CLASS |
-		       USB_DEVICE_ID_MATCH_INT_SUBCLASS,
-	.idVendor = 0x046d,
-	.idProduct = 0x08f0,
-	.bInterfaceClass = USB_CLASS_AUDIO,
-	.bInterfaceSubClass = USB_SUBCLASS_AUDIOCONTROL
-},
-{
-	.match_flags = USB_DEVICE_ID_MATCH_DEVICE |
-		       USB_DEVICE_ID_MATCH_INT_CLASS |
-		       USB_DEVICE_ID_MATCH_INT_SUBCLASS,
-	.idVendor = 0x046d,
-	.idProduct = 0x08f5,
-	.bInterfaceClass = USB_CLASS_AUDIO,
-	.bInterfaceSubClass = USB_SUBCLASS_AUDIOCONTROL
-},
-{
-	.match_flags = USB_DEVICE_ID_MATCH_DEVICE |
-		       USB_DEVICE_ID_MATCH_INT_CLASS |
-		       USB_DEVICE_ID_MATCH_INT_SUBCLASS,
-	.idVendor = 0x046d,
-	.idProduct = 0x08f6,
-	.bInterfaceClass = USB_CLASS_AUDIO,
-	.bInterfaceSubClass = USB_SUBCLASS_AUDIOCONTROL
-},
-{
-	.match_flags = USB_DEVICE_ID_MATCH_DEVICE |
-		       USB_DEVICE_ID_MATCH_INT_CLASS |
-		       USB_DEVICE_ID_MATCH_INT_SUBCLASS,
-	.idVendor = 0x046d,
-	.idProduct = 0x0990,
-	.bInterfaceClass = USB_CLASS_AUDIO,
-	.bInterfaceSubClass = USB_SUBCLASS_AUDIOCONTROL,
-},
+{ USB_AUDIO_DEVICE(0x046d, 0x0850) },
+{ USB_AUDIO_DEVICE(0x046d, 0x08ae) },
+{ USB_AUDIO_DEVICE(0x046d, 0x08c6) },
+{ USB_AUDIO_DEVICE(0x046d, 0x08f0) },
+{ USB_AUDIO_DEVICE(0x046d, 0x08f5) },
+{ USB_AUDIO_DEVICE(0x046d, 0x08f6) },
+{ USB_AUDIO_DEVICE(0x046d, 0x0990) },
 
 /*
  * Yamaha devices
@@ -2831,13 +2785,7 @@ YAMAHA_DEVICE(0x7010, "UB99"),
  */
 
 #define AU0828_DEVICE(vid, pid, vname, pname) { \
-	.idVendor = vid, \
-	.idProduct = pid, \
-	.match_flags = USB_DEVICE_ID_MATCH_DEVICE | \
-		       USB_DEVICE_ID_MATCH_INT_CLASS | \
-		       USB_DEVICE_ID_MATCH_INT_SUBCLASS, \
-	.bInterfaceClass = USB_CLASS_AUDIO, \
-	.bInterfaceSubClass = USB_SUBCLASS_AUDIOCONTROL, \
+	USB_AUDIO_DEVICE(vid, pid), \
 	.driver_info = (unsigned long) &(const struct snd_usb_audio_quirk) { \
 		.vendor_name = vname, \
 		.product_name = pname, \
@@ -2867,13 +2815,7 @@ AU0828_DEVICE(0x2040, 0x7270, "Hauppauge", "HVR-950Q"),
 
 /* Syntek STK1160 */
 {
-	.match_flags = USB_DEVICE_ID_MATCH_DEVICE |
-		       USB_DEVICE_ID_MATCH_INT_CLASS |
-		       USB_DEVICE_ID_MATCH_INT_SUBCLASS,
-	.idVendor = 0x05e1,
-	.idProduct = 0x0408,
-	.bInterfaceClass = USB_CLASS_AUDIO,
-	.bInterfaceSubClass = USB_SUBCLASS_AUDIOCONTROL,
+	USB_AUDIO_DEVICE(0x05e1, 0x0408),
 	.driver_info = (unsigned long) &(const struct snd_usb_audio_quirk) {
 		.vendor_name = "Syntek",
 		.product_name = "STK1160",
@@ -3628,13 +3570,7 @@ AU0828_DEVICE(0x2040, 0x7270, "Hauppauge", "HVR-950Q"),
  * channels to be swapped and out of phase, which is dealt with in quirks.c.
  */
 {
-	.match_flags = USB_DEVICE_ID_MATCH_DEVICE |
-		       USB_DEVICE_ID_MATCH_INT_CLASS |
-		       USB_DEVICE_ID_MATCH_INT_SUBCLASS,
-	.idVendor = 0x534d,
-	.idProduct = 0x2109,
-	.bInterfaceClass = USB_CLASS_AUDIO,
-	.bInterfaceSubClass = USB_SUBCLASS_AUDIOCONTROL,
+	USB_AUDIO_DEVICE(0x534d, 0x2109),
 	.driver_info = (unsigned long) &(const struct snd_usb_audio_quirk) {
 		.vendor_name = "MacroSilicon",
 		.product_name = "MS2109",
@@ -3675,3 +3611,4 @@ AU0828_DEVICE(0x2040, 0x7270, "Hauppauge", "HVR-950Q"),
 },
 
 #undef USB_DEVICE_VENDOR_SPEC
+#undef USB_AUDIO_DEVICE
Signature · 1 line
2.16.4
#3 lore raw

PATCH 3/3 ALSA: usb-audio: Properly match with audio interface class

In reply to Takashi Iwai

There are a few entries in the quirk table that set the device ID with USB_DEVICE() macro while having an extra bInterfaceClass field. But bInterfaceClass field is never checked unless the proper match_flags is set, so those may match incorrectly with all interfaces.

Introduce another macro to match with the vid/pid pair and the audio class interface, and apply it to such entries, so that they can match properly.

---
 sound/usb/quirks-table.h | 55 +++++++++++++++++-------------------------------
 1 file changed, 19 insertions(+), 36 deletions(-)
sound/usb/quirks-table.h +19 -36
index 988bb9d00192..7a80ef31bbe4 100644
@@ -35,6 +35,14 @@
 	.bInterfaceClass = USB_CLASS_AUDIO, \
 	.bInterfaceSubClass = USB_SUBCLASS_AUDIOCONTROL
 
+/* Another standard entry matching with vid/pid and the audio class */
+#define USB_AUDIO_CLASS(vend, prod) \
+	.match_flags = USB_DEVICE_ID_MATCH_DEVICE | \
+		       USB_DEVICE_ID_MATCH_INT_CLASS, \
+	.idVendor = vend, \
+	.idProduct = prod, \
+	.bInterfaceClass = USB_CLASS_AUDIO
+
 /* FTDI devices */
 {
 	USB_DEVICE(0x0403, 0xb8d8),
@@ -68,34 +76,14 @@
 	}
 },
 
-{
-	/* E-Mu 0202 USB */
-	.match_flags = USB_DEVICE_ID_MATCH_DEVICE,
-	.idVendor = 0x041e,
-	.idProduct = 0x3f02,
-	.bInterfaceClass = USB_CLASS_AUDIO,
-},
-{
-	/* E-Mu 0404 USB */
-	.match_flags = USB_DEVICE_ID_MATCH_DEVICE,
-	.idVendor = 0x041e,
-	.idProduct = 0x3f04,
-	.bInterfaceClass = USB_CLASS_AUDIO,
-},
-{
-	/* E-Mu Tracker Pre */
-	.match_flags = USB_DEVICE_ID_MATCH_DEVICE,
-	.idVendor = 0x041e,
-	.idProduct = 0x3f0a,
-	.bInterfaceClass = USB_CLASS_AUDIO,
-},
-{
-	/* E-Mu 0204 USB */
-	.match_flags = USB_DEVICE_ID_MATCH_DEVICE,
-	.idVendor = 0x041e,
-	.idProduct = 0x3f19,
-	.bInterfaceClass = USB_CLASS_AUDIO,
-},
+/* E-Mu 0202 USB */
+{ USB_AUDIO_CLASS(0x041e, 0x3f02) },
+/* E-Mu 0404 USB */
+{ USB_AUDIO_CLASS(0x041e, 0x3f04) },
+/* E-Mu Tracker Pre */
+{ USB_AUDIO_CLASS(0x041e, 0x3f0a) },
+/* E-Mu 0204 USB */
+{ USB_AUDIO_CLASS(0x041e, 0x3f19) },
 
 /*
  * HP Wireless Audio
@@ -2751,10 +2739,7 @@ YAMAHA_DEVICE(0x7010, "UB99"),
 },
 
 /* KeithMcMillen Stringport */
-{
-	USB_DEVICE(0x1f38, 0x0001),
-	.bInterfaceClass = USB_CLASS_AUDIO,
-},
+{ USB_AUDIO_CLASS(0x1f38, 0x0001) },
 
 /* Miditech devices */
 {
@@ -2977,10 +2962,7 @@ AU0828_DEVICE(0x2040, 0x7270, "Hauppauge", "HVR-950Q"),
 },
 {
 	/* Tascam US122 MKII - playback-only support */
-	.match_flags = USB_DEVICE_ID_MATCH_DEVICE,
-	.idVendor = 0x0644,
-	.idProduct = 0x8021,
-	.bInterfaceClass = USB_CLASS_AUDIO,
+	USB_AUDIO_CLASS(0x0644, 0x8021),
 	.driver_info = (unsigned long) &(const struct snd_usb_audio_quirk) {
 		.vendor_name = "TASCAM",
 		.product_name = "US122 MKII",
@@ -3612,3 +3594,4 @@ AU0828_DEVICE(0x2040, 0x7270, "Hauppauge", "HVR-950Q"),
 
 #undef USB_DEVICE_VENDOR_SPEC
 #undef USB_AUDIO_DEVICE
+#undef USB_AUDIO_CLASS
Signature · 1 line
2.16.4
#4 lore raw

Re: [PATCH 3/3] ALSA: usb-audio: Properly match with audio interface class

В Пн, 17/08/2020 в 10:21 +0200, Takashi Iwai пишет:

Quoted 106 lines

There are a few entries in the quirk table that set the device ID with
USB_DEVICE() macro while having an extra bInterfaceClass field. But bInterfaceClass field is never checked unless the proper match_flags is set, so those may match incorrectly with all interfaces.

Introduce another macro to match with the vid/pid pair and the audio class interface, and apply it to such entries, so that they can match properly.

---
 sound/usb/quirks-table.h | 55 +++++++++++++++++---------------------
----------
 1 file changed, 19 insertions(+), 36 deletions(-)
sound/usb/quirks-table.h +8 -0
index 988bb9d00192..7a80ef31bbe4 100644
@@ -35,6 +35,14 @@
 	.bInterfaceClass = USB_CLASS_AUDIO, \
 	.bInterfaceSubClass = USB_SUBCLASS_AUDIOCONTROL
 
+/* Another standard entry matching with vid/pid and the audio class
 */
+#define USB_AUDIO_CLASS(vend, prod) \
+	.match_flags = USB_DEVICE_ID_MATCH_DEVICE | \
+		       USB_DEVICE_ID_MATCH_INT_CLASS, \
+	.idVendor = vend, \
+	.idProduct = prod, \
+	.bInterfaceClass = USB_CLASS_AUDIO
+
 /* FTDI devices */
 {
sound/usb/quirks-table.h +10 -36
 	USB_DEVICE(0x0403, 0xb8d8),
@@ -68,34 +76,14 @@
 	}
 },
 
-{
-	/* E-Mu 0202 USB */
-	.match_flags = USB_DEVICE_ID_MATCH_DEVICE,
-	.idVendor = 0x041e,
-	.idProduct = 0x3f02,
-	.bInterfaceClass = USB_CLASS_AUDIO,
-},
-{
-	/* E-Mu 0404 USB */
-	.match_flags = USB_DEVICE_ID_MATCH_DEVICE,
-	.idVendor = 0x041e,
-	.idProduct = 0x3f04,
-	.bInterfaceClass = USB_CLASS_AUDIO,
-},
-{
-	/* E-Mu Tracker Pre */
-	.match_flags = USB_DEVICE_ID_MATCH_DEVICE,
-	.idVendor = 0x041e,
-	.idProduct = 0x3f0a,
-	.bInterfaceClass = USB_CLASS_AUDIO,
-},
-{
-	/* E-Mu 0204 USB */
-	.match_flags = USB_DEVICE_ID_MATCH_DEVICE,
-	.idVendor = 0x041e,
-	.idProduct = 0x3f19,
-	.bInterfaceClass = USB_CLASS_AUDIO,
-},
+/* E-Mu 0202 USB */
+{ USB_AUDIO_CLASS(0x041e, 0x3f02) },
+/* E-Mu 0404 USB */
+{ USB_AUDIO_CLASS(0x041e, 0x3f04) },
+/* E-Mu Tracker Pre */
+{ USB_AUDIO_CLASS(0x041e, 0x3f0a) },
+/* E-Mu 0204 USB */
+{ USB_AUDIO_CLASS(0x041e, 0x3f19) },
 
 /*
  * HP Wireless Audio
@@ -2751,10 +2739,7 @@ YAMAHA_DEVICE(0x7010, "UB99"),
 },
 
 /* KeithMcMillen Stringport */
-{
-	USB_DEVICE(0x1f38, 0x0001),
-	.bInterfaceClass = USB_CLASS_AUDIO,
-},
+{ USB_AUDIO_CLASS(0x1f38, 0x0001) },
 
 /* Miditech devices */
 {
@@ -2977,10 +2962,7 @@ AU0828_DEVICE(0x2040, 0x7270, "Hauppauge",
 "HVR-950Q"),
 },
 {
 	/* Tascam US122 MKII - playback-only support */
-	.match_flags = USB_DEVICE_ID_MATCH_DEVICE,
-	.idVendor = 0x0644,
-	.idProduct = 0x8021,
-	.bInterfaceClass = USB_CLASS_AUDIO,
+	USB_AUDIO_CLASS(0x0644, 0x8021),
 	.driver_info = (unsigned long) &(const struct
 snd_usb_audio_quirk) {
sound/usb/quirks-table.h +0 -0
 		.vendor_name = "TASCAM",
 		.product_name = "US122 MKII",

sound/usb/quirks-table.h AU0828_DEVICE(0x2040, 0x7270, "Hauppauge", · line 3597

Quoted 5 lines
sound/usb/quirks-table.h +1 -0
@@ -3612,3 +3594,4 @@ AU0828_DEVICE(0x2040, 0x7270, "Hauppauge",
 "HVR-950Q"),
 
 #undef USB_DEVICE_VENDOR_SPEC
 #undef USB_AUDIO_DEVICE
+#undef USB_AUDIO_CLASS

I don't know anything about KeithMcMillen Stringport, but all other devices (US122 MKII and E-mu) seems to have Vendor-specific Class. And since the driver should already match all compliant devices, the only potentional use for USB_AUDIO_CLASS macro is for devices with bInterfaceClass = USB_CLASS_AUDIO and with some invalid bInterfaceSubClass.

#5 lore raw

Re: [PATCH 3/3] ALSA: usb-audio: Properly match with audio interface class

Quoted 110 lines · Alexander Tsoy

В Пн, 17/08/2020 в 10:21 +0200, Takashi Iwai пишет:

Quoted 108 lines

There are a few entries in the quirk table that set the device ID with
USB_DEVICE() macro while having an extra bInterfaceClass field. But bInterfaceClass field is never checked unless the proper match_flags is set, so those may match incorrectly with all interfaces.

Introduce another macro to match with the vid/pid pair and the audio class interface, and apply it to such entries, so that they can match properly.

---
 sound/usb/quirks-table.h | 55 +++++++++++++++++---------------------
----------
 1 file changed, 19 insertions(+), 36 deletions(-)
sound/usb/quirks-table.h +8 -0
index 988bb9d00192..7a80ef31bbe4 100644
@@ -35,6 +35,14 @@
 	.bInterfaceClass = USB_CLASS_AUDIO, \
 	.bInterfaceSubClass = USB_SUBCLASS_AUDIOCONTROL
 
+/* Another standard entry matching with vid/pid and the audio class
 */
+#define USB_AUDIO_CLASS(vend, prod) \
+	.match_flags = USB_DEVICE_ID_MATCH_DEVICE | \
+		       USB_DEVICE_ID_MATCH_INT_CLASS, \
+	.idVendor = vend, \
+	.idProduct = prod, \
+	.bInterfaceClass = USB_CLASS_AUDIO
+
 /* FTDI devices */
 {
sound/usb/quirks-table.h +10 -36
 	USB_DEVICE(0x0403, 0xb8d8),
@@ -68,34 +76,14 @@
 	}
 },
 
-{
-	/* E-Mu 0202 USB */
-	.match_flags = USB_DEVICE_ID_MATCH_DEVICE,
-	.idVendor = 0x041e,
-	.idProduct = 0x3f02,
-	.bInterfaceClass = USB_CLASS_AUDIO,
-},
-{
-	/* E-Mu 0404 USB */
-	.match_flags = USB_DEVICE_ID_MATCH_DEVICE,
-	.idVendor = 0x041e,
-	.idProduct = 0x3f04,
-	.bInterfaceClass = USB_CLASS_AUDIO,
-},
-{
-	/* E-Mu Tracker Pre */
-	.match_flags = USB_DEVICE_ID_MATCH_DEVICE,
-	.idVendor = 0x041e,
-	.idProduct = 0x3f0a,
-	.bInterfaceClass = USB_CLASS_AUDIO,
-},
-{
-	/* E-Mu 0204 USB */
-	.match_flags = USB_DEVICE_ID_MATCH_DEVICE,
-	.idVendor = 0x041e,
-	.idProduct = 0x3f19,
-	.bInterfaceClass = USB_CLASS_AUDIO,
-},
+/* E-Mu 0202 USB */
+{ USB_AUDIO_CLASS(0x041e, 0x3f02) },
+/* E-Mu 0404 USB */
+{ USB_AUDIO_CLASS(0x041e, 0x3f04) },
+/* E-Mu Tracker Pre */
+{ USB_AUDIO_CLASS(0x041e, 0x3f0a) },
+/* E-Mu 0204 USB */
+{ USB_AUDIO_CLASS(0x041e, 0x3f19) },
 
 /*
  * HP Wireless Audio
@@ -2751,10 +2739,7 @@ YAMAHA_DEVICE(0x7010, "UB99"),
 },
 
 /* KeithMcMillen Stringport */
-{
-	USB_DEVICE(0x1f38, 0x0001),
-	.bInterfaceClass = USB_CLASS_AUDIO,
-},
+{ USB_AUDIO_CLASS(0x1f38, 0x0001) },
 
 /* Miditech devices */
 {
@@ -2977,10 +2962,7 @@ AU0828_DEVICE(0x2040, 0x7270, "Hauppauge",
 "HVR-950Q"),
 },
 {
 	/* Tascam US122 MKII - playback-only support */
-	.match_flags = USB_DEVICE_ID_MATCH_DEVICE,
-	.idVendor = 0x0644,
-	.idProduct = 0x8021,
-	.bInterfaceClass = USB_CLASS_AUDIO,
+	USB_AUDIO_CLASS(0x0644, 0x8021),
 	.driver_info = (unsigned long) &(const struct
 snd_usb_audio_quirk) {
sound/usb/quirks-table.h +0 -0
 		.vendor_name = "TASCAM",
 		.product_name = "US122 MKII",
@@ -3612,3 +3594,4 @@ AU0828_DEVICE(0x2040, 0x7270, "Hauppauge",
 "HVR-950Q"),
 
Quoted 6 lines

sound/usb/quirks-table.h AU0828_DEVICE(0x2040, 0x7270, "Hauppauge", "HVR-950Q"), · line 3597

Quoted 3 lines
sound/usb/quirks-table.h +1 -0
 #undef USB_DEVICE_VENDOR_SPEC
 #undef USB_AUDIO_DEVICE
+#undef USB_AUDIO_CLASS

I don't know anything about KeithMcMillen Stringport, but all other devices (US122 MKII and E-mu) seems to have Vendor-specific Class.

OK, then it must be with USB_DEVICE_VENDOR_SPEC macro instead although they had .bInterfaceClass = USB_CLASS_AUDIO line wrongly. Could you submit the correction patch, or shall I fix in my side?

Quoted 5 lines

And
since the driver should already match all compliant devices, the only potentional use for USB_AUDIO_CLASS macro is for devices with bInterfaceClass = USB_CLASS_AUDIO and with some invalid bInterfaceSubClass.

The problem is that without the class match in addition to the device id match, it would match too eagerly, e.g. if a USB device defines multiple different classes with the same device id like HID and video. So we should restrict the matching as much as possible.

thanks,

Takashi

#6 lore raw

Re: [PATCH 3/3] ALSA: usb-audio: Properly match with audio interface class

Quoted 120 lines · Takashi Iwai
Quoted 110 lines · Alexander Tsoy

В Пн, 17/08/2020 в 10:21 +0200, Takashi Iwai пишет:

Quoted 108 lines

There are a few entries in the quirk table that set the device ID with
USB_DEVICE() macro while having an extra bInterfaceClass field. But bInterfaceClass field is never checked unless the proper match_flags is set, so those may match incorrectly with all interfaces.

Introduce another macro to match with the vid/pid pair and the audio class interface, and apply it to such entries, so that they can match properly.

---
 sound/usb/quirks-table.h | 55 +++++++++++++++++---------------------
----------
 1 file changed, 19 insertions(+), 36 deletions(-)
sound/usb/quirks-table.h +8 -0
index 988bb9d00192..7a80ef31bbe4 100644
@@ -35,6 +35,14 @@
 	.bInterfaceClass = USB_CLASS_AUDIO, \
 	.bInterfaceSubClass = USB_SUBCLASS_AUDIOCONTROL
 
+/* Another standard entry matching with vid/pid and the audio class
 */
+#define USB_AUDIO_CLASS(vend, prod) \
+	.match_flags = USB_DEVICE_ID_MATCH_DEVICE | \
+		       USB_DEVICE_ID_MATCH_INT_CLASS, \
+	.idVendor = vend, \
+	.idProduct = prod, \
+	.bInterfaceClass = USB_CLASS_AUDIO
+
 /* FTDI devices */
 {
sound/usb/quirks-table.h +10 -36
 	USB_DEVICE(0x0403, 0xb8d8),
@@ -68,34 +76,14 @@
 	}
 },
 
-{
-	/* E-Mu 0202 USB */
-	.match_flags = USB_DEVICE_ID_MATCH_DEVICE,
-	.idVendor = 0x041e,
-	.idProduct = 0x3f02,
-	.bInterfaceClass = USB_CLASS_AUDIO,
-},
-{
-	/* E-Mu 0404 USB */
-	.match_flags = USB_DEVICE_ID_MATCH_DEVICE,
-	.idVendor = 0x041e,
-	.idProduct = 0x3f04,
-	.bInterfaceClass = USB_CLASS_AUDIO,
-},
-{
-	/* E-Mu Tracker Pre */
-	.match_flags = USB_DEVICE_ID_MATCH_DEVICE,
-	.idVendor = 0x041e,
-	.idProduct = 0x3f0a,
-	.bInterfaceClass = USB_CLASS_AUDIO,
-},
-{
-	/* E-Mu 0204 USB */
-	.match_flags = USB_DEVICE_ID_MATCH_DEVICE,
-	.idVendor = 0x041e,
-	.idProduct = 0x3f19,
-	.bInterfaceClass = USB_CLASS_AUDIO,
-},
+/* E-Mu 0202 USB */
+{ USB_AUDIO_CLASS(0x041e, 0x3f02) },
+/* E-Mu 0404 USB */
+{ USB_AUDIO_CLASS(0x041e, 0x3f04) },
+/* E-Mu Tracker Pre */
+{ USB_AUDIO_CLASS(0x041e, 0x3f0a) },
+/* E-Mu 0204 USB */
+{ USB_AUDIO_CLASS(0x041e, 0x3f19) },
 
 /*
  * HP Wireless Audio
@@ -2751,10 +2739,7 @@ YAMAHA_DEVICE(0x7010, "UB99"),
 },
 
 /* KeithMcMillen Stringport */
-{
-	USB_DEVICE(0x1f38, 0x0001),
-	.bInterfaceClass = USB_CLASS_AUDIO,
-},
+{ USB_AUDIO_CLASS(0x1f38, 0x0001) },
 
 /* Miditech devices */
 {
@@ -2977,10 +2962,7 @@ AU0828_DEVICE(0x2040, 0x7270, "Hauppauge",
 "HVR-950Q"),
 },
 {
 	/* Tascam US122 MKII - playback-only support */
-	.match_flags = USB_DEVICE_ID_MATCH_DEVICE,
-	.idVendor = 0x0644,
-	.idProduct = 0x8021,
-	.bInterfaceClass = USB_CLASS_AUDIO,
+	USB_AUDIO_CLASS(0x0644, 0x8021),
 	.driver_info = (unsigned long) &(const struct
 snd_usb_audio_quirk) {
sound/usb/quirks-table.h +0 -0
 		.vendor_name = "TASCAM",
 		.product_name = "US122 MKII",
@@ -3612,3 +3594,4 @@ AU0828_DEVICE(0x2040, 0x7270, "Hauppauge",
 "HVR-950Q"),
 
Quoted 6 lines

sound/usb/quirks-table.h AU0828_DEVICE(0x2040, 0x7270, "Hauppauge", "HVR-950Q"), · line 3597

Quoted 3 lines
sound/usb/quirks-table.h +1 -0
 #undef USB_DEVICE_VENDOR_SPEC
 #undef USB_AUDIO_DEVICE
+#undef USB_AUDIO_CLASS

I don't know anything about KeithMcMillen Stringport, but all other devices (US122 MKII and E-mu) seems to have Vendor-specific Class.

Quoted 3 lines

OK, then it must be with USB_DEVICE_VENDOR_SPEC macro instead although they had .bInterfaceClass = USB_CLASS_AUDIO line wrongly. Could you submit the correction patch, or shall I fix in my side?

Never mind, I prepared a patch by myself. Will submit now.

Takashi

#7 lore raw

Re: [PATCH 3/3] ALSA: usb-audio: Properly match with audio interface class

В Вс, 23/08/2020 в 13:28 +0200, Takashi Iwai пишет:

Quoted 132 lines
Quoted 130 lines · Takashi Iwai
Quoted 127 lines · Alexander Tsoy

В Пн, 17/08/2020 в 10:21 +0200, Takashi Iwai пишет:

Quoted 115 lines

There are a few entries in the quirk table that set the device ID
with
USB_DEVICE() macro while having an extra bInterfaceClass field. But
bInterfaceClass field is never checked unless the proper match_flags
is set, so those may match incorrectly with all interfaces.

Introduce another macro to match with the vid/pid pair and the audio
class interface, and apply it to such entries, so that they can match
properly.

---
 sound/usb/quirks-table.h | 55 +++++++++++++++++---------------
------
----------
 1 file changed, 19 insertions(+), 36 deletions(-)
sound/usb/quirks- renamed from sound/usb/quirks-table.h +0 -0

table.h
index 988bb9d00192..7a80ef31bbe4 100644

sound/usb/quirks-table.h +1 -0
@@ -35,6 +35,14 @@
 	.bInterfaceClass = USB_CLASS_AUDIO, \
 	.bInterfaceSubClass = USB_SUBCLASS_AUDIOCONTROL
 
+/* Another standard entry matching with vid/pid and the audio

class
*/

sound/usb/quirks-table.h +17 -36
+#define USB_AUDIO_CLASS(vend, prod) \
+	.match_flags = USB_DEVICE_ID_MATCH_DEVICE | \
+		       USB_DEVICE_ID_MATCH_INT_CLASS, \
+	.idVendor = vend, \
+	.idProduct = prod, \
+	.bInterfaceClass = USB_CLASS_AUDIO
+
 /* FTDI devices */
 {
 	USB_DEVICE(0x0403, 0xb8d8),
@@ -68,34 +76,14 @@
 	}
 },
 
-{
-	/* E-Mu 0202 USB */
-	.match_flags = USB_DEVICE_ID_MATCH_DEVICE,
-	.idVendor = 0x041e,
-	.idProduct = 0x3f02,
-	.bInterfaceClass = USB_CLASS_AUDIO,
-},
-{
-	/* E-Mu 0404 USB */
-	.match_flags = USB_DEVICE_ID_MATCH_DEVICE,
-	.idVendor = 0x041e,
-	.idProduct = 0x3f04,
-	.bInterfaceClass = USB_CLASS_AUDIO,
-},
-{
-	/* E-Mu Tracker Pre */
-	.match_flags = USB_DEVICE_ID_MATCH_DEVICE,
-	.idVendor = 0x041e,
-	.idProduct = 0x3f0a,
-	.bInterfaceClass = USB_CLASS_AUDIO,
-},
-{
-	/* E-Mu 0204 USB */
-	.match_flags = USB_DEVICE_ID_MATCH_DEVICE,
-	.idVendor = 0x041e,
-	.idProduct = 0x3f19,
-	.bInterfaceClass = USB_CLASS_AUDIO,
-},
+/* E-Mu 0202 USB */
+{ USB_AUDIO_CLASS(0x041e, 0x3f02) },
+/* E-Mu 0404 USB */
+{ USB_AUDIO_CLASS(0x041e, 0x3f04) },
+/* E-Mu Tracker Pre */
+{ USB_AUDIO_CLASS(0x041e, 0x3f0a) },
+/* E-Mu 0204 USB */
+{ USB_AUDIO_CLASS(0x041e, 0x3f19) },
 
 /*
  * HP Wireless Audio
@@ -2751,10 +2739,7 @@ YAMAHA_DEVICE(0x7010, "UB99"),
 },
 
 /* KeithMcMillen Stringport */
-{
-	USB_DEVICE(0x1f38, 0x0001),
-	.bInterfaceClass = USB_CLASS_AUDIO,
-},
+{ USB_AUDIO_CLASS(0x1f38, 0x0001) },
 
 /* Miditech devices */
 {
@@ -2977,10 +2962,7 @@ AU0828_DEVICE(0x2040, 0x7270,
 "Hauppauge",
 "HVR-950Q"),
 },
 {
 	/* Tascam US122 MKII - playback-only support */
-	.match_flags = USB_DEVICE_ID_MATCH_DEVICE,
-	.idVendor = 0x0644,
-	.idProduct = 0x8021,
-	.bInterfaceClass = USB_CLASS_AUDIO,
+	USB_AUDIO_CLASS(0x0644, 0x8021),
 	.driver_info = (unsigned long) &(const struct

snd_usb_audio_quirk) {

sound/usb/quirks-table.h +0 -0
 		.vendor_name = "TASCAM",
 		.product_name = "US122 MKII",

sound/usb/quirks-table.h AU0828_DEVICE(0x2040, 0x7270, · line 3597

Quoted 6 lines
sound/usb/quirks-table.h +1 -0
@@ -3612,3 +3594,4 @@ AU0828_DEVICE(0x2040, 0x7270,
 "Hauppauge",
 "HVR-950Q"),
 
 #undef USB_DEVICE_VENDOR_SPEC
 #undef USB_AUDIO_DEVICE
+#undef USB_AUDIO_CLASS

I don't know anything about KeithMcMillen Stringport, but all other
devices (US122 MKII and E-mu) seems to have Vendor-specific Class.

Quoted 6 lines
Quoted 4 lines

OK, then it must be with USB_DEVICE_VENDOR_SPEC macro instead although
they had .bInterfaceClass = USB_CLASS_AUDIO line wrongly. Could you submit the correction patch, or shall I fix in my side?

Never mind, I prepared a patch by myself. Will submit now.

Thank you! Yes, I think entries in quirks-table were incorrect. Here are some proofs:

- E-Mu 0202 USB:
https://github.com/linuxhw/LsUSB/blob/master/Desktop/ASUSTek%20Computer/All/All%20Series/EB6955AE5064/ROSA-2016.1/4.9.20-NRJ-DESKTOP-1ROSA-X86_64/X86_64/7339AF533B#L1073
- E-Mu 0404 USB:
https://github.com/linuxhw/LsUSB/blob/master/Desktop/ASUSTek%20Computer/M5A97/M5A97%20R2.0/4BA2C16B387E/ROSA-2014.1/4.1.15-NRJ-DESKTOP-1ROSA-X86_64/X86_64/E08FEFA436#L997
- E-Mu 0204 USB:
https://github.com/linuxhw/LsUSB/blob/master/Desktop/ASUSTek%20Computer/P5/P5LD2-SE/D614D36EB275/ROSA-2014.1/4.1.15-NRJ-DESKTOP-1ROSA-X86_64/X86_64/09F4577139#L782
- E-MU Tracker Pre:
https://github.com/linuxhw/LsUSB/blob/master/Desktop/ASRock/H61/H61M-HVGS/AD71CCCE2E3F/ROSA-2014.1/3.14.44-NRJ-DESKTOP-2ROSA-X86_64/X86_64/6996B0918E#L2
- TASCAM US-122mkII
https://github.com/linuxhw/LsUSB/blob/master/Desktop/Intel/WX58BP/WX58BP%20AAE64643-203/2B1109DE1986/ROSA-2014.1/4.1.22-NRJ-DESKTOP-2ROSA-X86_64/X86_64/0E7E6022A3#L421