aboutsummaryrefslogtreecommitdiffstats
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
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>
-rw-r--r--sound/pci/hda/hda_codec.c37
-rw-r--r--sound/pci/hda/hda_codec.h2
-rw-r--r--sound/pci/hda/hda_proc.c5
3 files changed, 29 insertions, 15 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;
diff --git a/sound/pci/hda/hda_codec.h b/sound/pci/hda/hda_codec.h
index 77064b0cb821..53f3b08b24cd 100644
--- a/sound/pci/hda/hda_codec.h
+++ b/sound/pci/hda/hda_codec.h
@@ -719,6 +719,8 @@ struct hda_codec {
719 719
720 /* detected preset */ 720 /* detected preset */
721 const struct hda_codec_preset *preset; 721 const struct hda_codec_preset *preset;
722 const char *name; /* codec name */
723 const char *modelname; /* model name for preset */
722 724
723 /* set by patch */ 725 /* set by patch */
724 struct hda_codec_ops patch_ops; 726 struct hda_codec_ops patch_ops;
diff --git a/sound/pci/hda/hda_proc.c b/sound/pci/hda/hda_proc.c
index 743d77922bce..64ab19f14f79 100644
--- a/sound/pci/hda/hda_proc.c
+++ b/sound/pci/hda/hda_proc.c
@@ -511,12 +511,11 @@ static void print_codec_info(struct snd_info_entry *entry,
511 struct snd_info_buffer *buffer) 511 struct snd_info_buffer *buffer)
512{ 512{
513 struct hda_codec *codec = entry->private_data; 513 struct hda_codec *codec = entry->private_data;
514 char buf[32];
515 hda_nid_t nid; 514 hda_nid_t nid;
516 int i, nodes; 515 int i, nodes;
517 516
518 snd_hda_get_codec_name(codec, buf, sizeof(buf)); 517 snd_iprintf(buffer, "Codec: %s\n",
519 snd_iprintf(buffer, "Codec: %s\n", buf); 518 codec->name ? codec->name : "Not Set");
520 snd_iprintf(buffer, "Address: %d\n", codec->addr); 519 snd_iprintf(buffer, "Address: %d\n", codec->addr);
521 snd_iprintf(buffer, "Vendor Id: 0x%x\n", codec->vendor_id); 520 snd_iprintf(buffer, "Vendor Id: 0x%x\n", codec->vendor_id);
522 snd_iprintf(buffer, "Subsystem Id: 0x%x\n", codec->subsystem_id); 521 snd_iprintf(buffer, "Subsystem Id: 0x%x\n", codec->subsystem_id);