aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTakashi Iwai <tiwai@suse.de>2011-03-21 07:00:00 -0400
committerTakashi Iwai <tiwai@suse.de>2011-03-21 07:32:44 -0400
commit3ffc1222bd2c30b0ef2d3a797b0e0070c7c61a98 (patch)
tree0e14e12239866c3269665febb2e46ce928c0cd95
parent977a6ef3c0cb622b572fb8e2e5088dbe09521375 (diff)
ALSA: usb - Remove trailing spaces from USB card name strings
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>
-rw-r--r--sound/usb/card.c22
1 files changed, 18 insertions, 4 deletions
diff --git a/sound/usb/card.c b/sound/usb/card.c
index 40722f8711ad..a90662af2d6b 100644
--- a/sound/usb/card.c
+++ b/sound/usb/card.c
@@ -41,6 +41,7 @@
41#include <linux/list.h> 41#include <linux/list.h>
42#include <linux/slab.h> 42#include <linux/slab.h>
43#include <linux/string.h> 43#include <linux/string.h>
44#include <linux/ctype.h>
44#include <linux/usb.h> 45#include <linux/usb.h>
45#include <linux/moduleparam.h> 46#include <linux/moduleparam.h>
46#include <linux/mutex.h> 47#include <linux/mutex.h>
@@ -283,6 +284,15 @@ static int snd_usb_audio_dev_free(struct snd_device *device)
283 return snd_usb_audio_free(chip); 284 return snd_usb_audio_free(chip);
284} 285}
285 286
287static void remove_trailing_spaces(char *str)
288{
289 char *p;
290
291 if (!*str)
292 return;
293 for (p = str + strlen(str) - 1; p >= str && isspace(*p); p--)
294 *p = 0;
295}
286 296
287/* 297/*
288 * create a chip instance and set its names. 298 * create a chip instance and set its names.
@@ -351,7 +361,7 @@ static int snd_usb_audio_create(struct usb_device *dev, int idx,
351 snd_component_add(card, component); 361 snd_component_add(card, component);
352 362
353 /* retrieve the device string as shortname */ 363 /* retrieve the device string as shortname */
354 if (quirk && quirk->product_name) { 364 if (quirk && quirk->product_name && *quirk->product_name) {
355 strlcpy(card->shortname, quirk->product_name, sizeof(card->shortname)); 365 strlcpy(card->shortname, quirk->product_name, sizeof(card->shortname));
356 } else { 366 } else {
357 if (!dev->descriptor.iProduct || 367 if (!dev->descriptor.iProduct ||
@@ -363,9 +373,10 @@ static int snd_usb_audio_create(struct usb_device *dev, int idx,
363 USB_ID_PRODUCT(chip->usb_id)); 373 USB_ID_PRODUCT(chip->usb_id));
364 } 374 }
365 } 375 }
376 remove_trailing_spaces(card->shortname);
366 377
367 /* retrieve the vendor and device strings as longname */ 378 /* retrieve the vendor and device strings as longname */
368 if (quirk && quirk->vendor_name) { 379 if (quirk && quirk->vendor_name && *quirk->vendor_name) {
369 len = strlcpy(card->longname, quirk->vendor_name, sizeof(card->longname)); 380 len = strlcpy(card->longname, quirk->vendor_name, sizeof(card->longname));
370 } else { 381 } else {
371 if (dev->descriptor.iManufacturer) 382 if (dev->descriptor.iManufacturer)
@@ -375,8 +386,11 @@ static int snd_usb_audio_create(struct usb_device *dev, int idx,
375 len = 0; 386 len = 0;
376 /* we don't really care if there isn't any vendor string */ 387 /* we don't really care if there isn't any vendor string */
377 } 388 }
378 if (len > 0) 389 if (len > 0) {
379 strlcat(card->longname, " ", sizeof(card->longname)); 390 remove_trailing_spaces(card->longname);
391 if (*card->longname)
392 strlcat(card->longname, " ", sizeof(card->longname));
393 }
380 394
381 strlcat(card->longname, card->shortname, sizeof(card->longname)); 395 strlcat(card->longname, card->shortname, sizeof(card->longname));
382 396