Skip to content

Commit

Permalink
ALSA: usb - Remove trailing spaces from USB card name strings
Browse files Browse the repository at this point in the history
Some USB devices give trailing spaces in strings returned from
usb_string().  This confuses the automatic card-id creation, resulting
always in "default".
This patch fixes the behavior by removing trailing spaces.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
  • Loading branch information
Takashi Iwai committed Mar 21, 2011
1 parent 977a6ef commit 3ffc122
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions sound/usb/card.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include <linux/list.h>
#include <linux/slab.h>
#include <linux/string.h>
#include <linux/ctype.h>
#include <linux/usb.h>
#include <linux/moduleparam.h>
#include <linux/mutex.h>
Expand Down Expand Up @@ -283,6 +284,15 @@ static int snd_usb_audio_dev_free(struct snd_device *device)
return snd_usb_audio_free(chip);
}

static void remove_trailing_spaces(char *str)
{
char *p;

if (!*str)
return;
for (p = str + strlen(str) - 1; p >= str && isspace(*p); p--)
*p = 0;
}

/*
* create a chip instance and set its names.
Expand Down Expand Up @@ -351,7 +361,7 @@ static int snd_usb_audio_create(struct usb_device *dev, int idx,
snd_component_add(card, component);

/* retrieve the device string as shortname */
if (quirk && quirk->product_name) {
if (quirk && quirk->product_name && *quirk->product_name) {
strlcpy(card->shortname, quirk->product_name, sizeof(card->shortname));
} else {
if (!dev->descriptor.iProduct ||
Expand All @@ -363,9 +373,10 @@ static int snd_usb_audio_create(struct usb_device *dev, int idx,
USB_ID_PRODUCT(chip->usb_id));
}
}
remove_trailing_spaces(card->shortname);

/* retrieve the vendor and device strings as longname */
if (quirk && quirk->vendor_name) {
if (quirk && quirk->vendor_name && *quirk->vendor_name) {
len = strlcpy(card->longname, quirk->vendor_name, sizeof(card->longname));
} else {
if (dev->descriptor.iManufacturer)
Expand All @@ -375,8 +386,11 @@ static int snd_usb_audio_create(struct usb_device *dev, int idx,
len = 0;
/* we don't really care if there isn't any vendor string */
}
if (len > 0)
strlcat(card->longname, " ", sizeof(card->longname));
if (len > 0) {
remove_trailing_spaces(card->longname);
if (*card->longname)
strlcat(card->longname, " ", sizeof(card->longname));
}

strlcat(card->longname, card->shortname, sizeof(card->longname));

Expand Down

0 comments on commit 3ffc122

Please sign in to comment.