Skip to content

Commit 42ef170

Browse files
committed
ALSA: usb-audio: Convert the last strlcpy() usage
The last remaining usage of strlcpy() in USB-audio driver is the setup of the card longname string. Basically we need to know whether any non-empty string is set or not, and no real length is needed. Refactor the code and use strscpy() instead. After this change, strlcpy() is gone from all sound/* code. Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Takashi Iwai <[email protected]>
1 parent e8afdfd commit 42ef170

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

sound/usb/card.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -514,18 +514,17 @@ static void usb_audio_make_longname(struct usb_device *dev,
514514
s = preset->vendor_name;
515515
else if (quirk && quirk->vendor_name)
516516
s = quirk->vendor_name;
517+
*card->longname = 0;
517518
if (s && *s) {
518-
len = strlcpy(card->longname, s, sizeof(card->longname));
519+
strscpy(card->longname, s, sizeof(card->longname));
519520
} else {
520521
/* retrieve the vendor and device strings as longname */
521522
if (dev->descriptor.iManufacturer)
522-
len = usb_string(dev, dev->descriptor.iManufacturer,
523-
card->longname, sizeof(card->longname));
524-
else
525-
len = 0;
523+
usb_string(dev, dev->descriptor.iManufacturer,
524+
card->longname, sizeof(card->longname));
526525
/* we don't really care if there isn't any vendor string */
527526
}
528-
if (len > 0) {
527+
if (*card->longname) {
529528
strim(card->longname);
530529
if (*card->longname)
531530
strlcat(card->longname, " ", sizeof(card->longname));

0 commit comments

Comments
 (0)