aboutsummaryrefslogtreecommitdiffstats
path: root/sound/pci/hda/hda_codec.c
diff options
context:
space:
mode:
authorTakashi Iwai <tiwai@suse.de>2008-07-30 09:01:45 -0400
committerTakashi Iwai <tiwai@suse.de>2008-10-12 20:43:00 -0400
commitf44ac8378d3d84b912b34f08afaff64182ee1b41 (patch)
treeeb89207bbb0697655d6b18480d106106c2357295 /sound/pci/hda/hda_codec.c
parent603c40199252f0c3b91fca02fd3283c4f8e55179 (diff)
ALSA: hda - Allocate name string of each codec
Allocate dynamically the name string of each codec instead of pointing to a static string. Signed-off-by: Takashi Iwai <tiwai@suse.de>
Diffstat (limited to 'sound/pci/hda/hda_codec.c')
-rw-r--r--sound/pci/hda/hda_codec.c37
1 files changed, 25 insertions, 12 deletions
diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c
index 39a49d4a864a..53e36495fae5 100644
--- a/sound/pci/hda/hda_codec.c
+++ b/sound/pci/hda/hda_codec.c
@@ -446,7 +446,7 @@ int __devinit snd_hda_bus_new(struct snd_card *card,
446 446
447#ifdef CONFIG_SND_HDA_GENERIC 447#ifdef CONFIG_SND_HDA_GENERIC
448#define is_generic_config(codec) \ 448#define is_generic_config(codec) \
449 (codec->bus->modelname && !strcmp(codec->bus->modelname, "generic")) 449 (codec->modelname && !strcmp(codec->modelname, "generic"))
450#else 450#else
451#define is_generic_config(codec) 0 451#define is_generic_config(codec) 0
452#endif 452#endif
@@ -481,15 +481,14 @@ find_codec_preset(struct hda_codec *codec)
481} 481}
482 482
483/* 483/*
484 * snd_hda_get_codec_name - store the codec name 484 * get_codec_name - store the codec name
485 */ 485 */
486void snd_hda_get_codec_name(struct hda_codec *codec, 486static int get_codec_name(struct hda_codec *codec)
487 char *name, int namelen)
488{ 487{
489 const struct hda_vendor_id *c; 488 const struct hda_vendor_id *c;
490 const char *vendor = NULL; 489 const char *vendor = NULL;
491 u16 vendor_id = codec->vendor_id >> 16; 490 u16 vendor_id = codec->vendor_id >> 16;
492 char tmp[16]; 491 char tmp[16], name[32];
493 492
494 for (c = hda_vendor_ids; c->id; c++) { 493 for (c = hda_vendor_ids; c->id; c++) {
495 if (c->id == vendor_id) { 494 if (c->id == vendor_id) {
@@ -502,10 +501,15 @@ void snd_hda_get_codec_name(struct hda_codec *codec,
502 vendor = tmp; 501 vendor = tmp;
503 } 502 }
504 if (codec->preset && codec->preset->name) 503 if (codec->preset && codec->preset->name)
505 snprintf(name, namelen, "%s %s", vendor, codec->preset->name); 504 snprintf(name, sizeof(name), "%s %s", vendor,
505 codec->preset->name);
506 else 506 else
507 snprintf(name, namelen, "%s ID %x", vendor, 507 snprintf(name, sizeof(name), "%s ID %x", vendor,
508 codec->vendor_id & 0xffff); 508 codec->vendor_id & 0xffff);
509 codec->name = kstrdup(name, GFP_KERNEL);
510 if (!codec->name)
511 return -ENOMEM;
512 return 0;
509} 513}
510 514
511/* 515/*
@@ -575,6 +579,8 @@ static void snd_hda_codec_free(struct hda_codec *codec)
575 codec->patch_ops.free(codec); 579 codec->patch_ops.free(codec);
576 free_hda_cache(&codec->amp_cache); 580 free_hda_cache(&codec->amp_cache);
577 free_hda_cache(&codec->cmd_cache); 581 free_hda_cache(&codec->cmd_cache);
582 kfree(codec->name);
583 kfree(codec->modelname);
578 kfree(codec->wcaps); 584 kfree(codec->wcaps);
579 kfree(codec); 585 kfree(codec);
580} 586}
@@ -661,12 +667,19 @@ int __devinit snd_hda_codec_new(struct hda_bus *bus, unsigned int codec_addr,
661 snd_hda_codec_read(codec, nid, 0, 667 snd_hda_codec_read(codec, nid, 0,
662 AC_VERB_GET_SUBSYSTEM_ID, 0); 668 AC_VERB_GET_SUBSYSTEM_ID, 0);
663 } 669 }
670 if (bus->modelname)
671 codec->modelname = kstrdup(bus->modelname, GFP_KERNEL);
664 672
665 codec->preset = find_codec_preset(codec); 673 codec->preset = find_codec_preset(codec);
674 if (!codec->name) {
675 err = get_codec_name(codec);
676 if (err < 0)
677 return err;
678 }
666 /* audio codec should override the mixer name */ 679 /* audio codec should override the mixer name */
667 if (codec->afg || !*bus->card->mixername) 680 if (codec->afg || !*codec->bus->card->mixername)
668 snd_hda_get_codec_name(codec, bus->card->mixername, 681 strlcpy(codec->bus->card->mixername, codec->name,
669 sizeof(bus->card->mixername)); 682 sizeof(codec->bus->card->mixername));
670 683
671 if (is_generic_config(codec)) { 684 if (is_generic_config(codec)) {
672 err = snd_hda_parse_generic_codec(codec); 685 err = snd_hda_parse_generic_codec(codec);
@@ -2370,11 +2383,11 @@ int snd_hda_check_board_config(struct hda_codec *codec,
2370 int num_configs, const char **models, 2383 int num_configs, const char **models,
2371 const struct snd_pci_quirk *tbl) 2384 const struct snd_pci_quirk *tbl)
2372{ 2385{
2373 if (codec->bus->modelname && models) { 2386 if (codec->modelname && models) {
2374 int i; 2387 int i;
2375 for (i = 0; i < num_configs; i++) { 2388 for (i = 0; i < num_configs; i++) {
2376 if (models[i] && 2389 if (models[i] &&
2377 !strcmp(codec->bus->modelname, models[i])) { 2390 !strcmp(codec->modelname, models[i])) {
2378 snd_printd(KERN_INFO "hda_codec: model '%s' is " 2391 snd_printd(KERN_INFO "hda_codec: model '%s' is "
2379 "selected\n", models[i]); 2392 "selected\n", models[i]);
2380 return i; 2393 return i;