Skip to content

Commit b364a0d

Browse files
committed
ALSA: usb-audio: Use strings in struct usb_dev for manufacturer & co
The USB core already prepares the strings for manufacturer, product and serial number, and we don't have to extract the string at each time. Replace the manual usb_string() calls with the corresponding pointers in struct usb_dev as a code cleanup. Link: https://patch.msgid.link/20260305130426.975604-1-tiwai@suse.de Signed-off-by: Takashi Iwai <tiwai@suse.de>
1 parent 27b9bca commit b364a0d

2 files changed

Lines changed: 10 additions & 16 deletions

File tree

sound/usb/card.c

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -631,9 +631,9 @@ static void usb_audio_make_shortname(struct usb_device *dev,
631631
}
632632

633633
/* retrieve the device string as shortname */
634-
if (!dev->descriptor.iProduct ||
635-
usb_string(dev, dev->descriptor.iProduct,
636-
card->shortname, sizeof(card->shortname)) <= 0) {
634+
if (dev->product && *dev->product) {
635+
strscpy(card->shortname, dev->product);
636+
} else {
637637
/* no name available from anywhere, so use ID */
638638
scnprintf(card->shortname, sizeof(card->shortname),
639639
"USB Device %#04x:%#04x",
@@ -668,15 +668,11 @@ static void usb_audio_make_longname(struct usb_device *dev,
668668
else if (quirk && quirk->vendor_name)
669669
s = quirk->vendor_name;
670670
*card->longname = 0;
671-
if (s && *s) {
672-
strscpy(card->longname, s, sizeof(card->longname));
673-
} else {
674-
/* retrieve the vendor and device strings as longname */
675-
if (dev->descriptor.iManufacturer)
676-
usb_string(dev, dev->descriptor.iManufacturer,
677-
card->longname, sizeof(card->longname));
678-
/* we don't really care if there isn't any vendor string */
679-
}
671+
if (s && *s)
672+
strscpy(card->longname, s);
673+
else if (dev->manufacturer && *dev->manufacturer)
674+
strscpy(card->longname, dev->manufacturer);
675+
680676
if (*card->longname) {
681677
strim(card->longname);
682678
if (*card->longname)

sound/usb/midi2.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1057,10 +1057,8 @@ static void set_fallback_rawmidi_names(struct snd_usb_midi2_interface *umidi)
10571057
strscpy(ump->core.name, ump->info.name,
10581058
sizeof(ump->core.name));
10591059
/* use serial number string as unique UMP product id */
1060-
if (!*ump->info.product_id && dev->descriptor.iSerialNumber)
1061-
usb_string(dev, dev->descriptor.iSerialNumber,
1062-
ump->info.product_id,
1063-
sizeof(ump->info.product_id));
1060+
if (!*ump->info.product_id && dev->serial && *dev->serial)
1061+
strscpy(ump->info.product_id, dev->serial);
10641062
}
10651063
}
10661064

0 commit comments

Comments
 (0)