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>
This commit is contained in:
Takashi Iwai 2008-07-30 15:01:45 +02:00
parent 603c401992
commit f44ac8378d
3 changed files with 29 additions and 15 deletions

View File

@ -446,7 +446,7 @@ int __devinit snd_hda_bus_new(struct snd_card *card,
#ifdef CONFIG_SND_HDA_GENERIC
#define is_generic_config(codec) \
(codec->bus->modelname && !strcmp(codec->bus->modelname, "generic"))
(codec->modelname && !strcmp(codec->modelname, "generic"))
#else
#define is_generic_config(codec) 0
#endif
@ -481,15 +481,14 @@ find_codec_preset(struct hda_codec *codec)
}
/*
* snd_hda_get_codec_name - store the codec name
* get_codec_name - store the codec name
*/
void snd_hda_get_codec_name(struct hda_codec *codec,
char *name, int namelen)
static int get_codec_name(struct hda_codec *codec)
{
const struct hda_vendor_id *c;
const char *vendor = NULL;
u16 vendor_id = codec->vendor_id >> 16;
char tmp[16];
char tmp[16], name[32];
for (c = hda_vendor_ids; c->id; c++) {
if (c->id == vendor_id) {
@ -502,10 +501,15 @@ void snd_hda_get_codec_name(struct hda_codec *codec,
vendor = tmp;
}
if (codec->preset && codec->preset->name)
snprintf(name, namelen, "%s %s", vendor, codec->preset->name);
snprintf(name, sizeof(name), "%s %s", vendor,
codec->preset->name);
else
snprintf(name, namelen, "%s ID %x", vendor,
snprintf(name, sizeof(name), "%s ID %x", vendor,
codec->vendor_id & 0xffff);
codec->name = kstrdup(name, GFP_KERNEL);
if (!codec->name)
return -ENOMEM;
return 0;
}
/*
@ -575,6 +579,8 @@ static void snd_hda_codec_free(struct hda_codec *codec)
codec->patch_ops.free(codec);
free_hda_cache(&codec->amp_cache);
free_hda_cache(&codec->cmd_cache);
kfree(codec->name);
kfree(codec->modelname);
kfree(codec->wcaps);
kfree(codec);
}
@ -661,12 +667,19 @@ int __devinit snd_hda_codec_new(struct hda_bus *bus, unsigned int codec_addr,
snd_hda_codec_read(codec, nid, 0,
AC_VERB_GET_SUBSYSTEM_ID, 0);
}
if (bus->modelname)
codec->modelname = kstrdup(bus->modelname, GFP_KERNEL);
codec->preset = find_codec_preset(codec);
if (!codec->name) {
err = get_codec_name(codec);
if (err < 0)
return err;
}
/* audio codec should override the mixer name */
if (codec->afg || !*bus->card->mixername)
snd_hda_get_codec_name(codec, bus->card->mixername,
sizeof(bus->card->mixername));
if (codec->afg || !*codec->bus->card->mixername)
strlcpy(codec->bus->card->mixername, codec->name,
sizeof(codec->bus->card->mixername));
if (is_generic_config(codec)) {
err = snd_hda_parse_generic_codec(codec);
@ -2370,11 +2383,11 @@ int snd_hda_check_board_config(struct hda_codec *codec,
int num_configs, const char **models,
const struct snd_pci_quirk *tbl)
{
if (codec->bus->modelname && models) {
if (codec->modelname && models) {
int i;
for (i = 0; i < num_configs; i++) {
if (models[i] &&
!strcmp(codec->bus->modelname, models[i])) {
!strcmp(codec->modelname, models[i])) {
snd_printd(KERN_INFO "hda_codec: model '%s' is "
"selected\n", models[i]);
return i;

View File

@ -719,6 +719,8 @@ struct hda_codec {
/* detected preset */
const struct hda_codec_preset *preset;
const char *name; /* codec name */
const char *modelname; /* model name for preset */
/* set by patch */
struct hda_codec_ops patch_ops;

View File

@ -511,12 +511,11 @@ static void print_codec_info(struct snd_info_entry *entry,
struct snd_info_buffer *buffer)
{
struct hda_codec *codec = entry->private_data;
char buf[32];
hda_nid_t nid;
int i, nodes;
snd_hda_get_codec_name(codec, buf, sizeof(buf));
snd_iprintf(buffer, "Codec: %s\n", buf);
snd_iprintf(buffer, "Codec: %s\n",
codec->name ? codec->name : "Not Set");
snd_iprintf(buffer, "Address: %d\n", codec->addr);
snd_iprintf(buffer, "Vendor Id: 0x%x\n", codec->vendor_id);
snd_iprintf(buffer, "Subsystem Id: 0x%x\n", codec->subsystem_id);