ALSA: hda - consolidate chip rename functions

A few multiple codec drivers do renaming the chip_name string but all
these are open-coded and some of them have even no error check.  Let's
make common helpers to do it properly.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
This commit is contained in:
Takashi Iwai 2015-10-01 17:59:43 +02:00
parent 3e19fec33a
commit ded255be22
7 changed files with 54 additions and 39 deletions

View File

@ -117,6 +117,7 @@ int snd_hdac_device_init(struct hdac_device *dev, struct hdac_bus *bus,
void snd_hdac_device_exit(struct hdac_device *dev); void snd_hdac_device_exit(struct hdac_device *dev);
int snd_hdac_device_register(struct hdac_device *codec); int snd_hdac_device_register(struct hdac_device *codec);
void snd_hdac_device_unregister(struct hdac_device *codec); void snd_hdac_device_unregister(struct hdac_device *codec);
int snd_hdac_device_set_chip_name(struct hdac_device *codec, const char *name);
int snd_hdac_refresh_widgets(struct hdac_device *codec); int snd_hdac_refresh_widgets(struct hdac_device *codec);
int snd_hdac_refresh_widget_sysfs(struct hdac_device *codec); int snd_hdac_refresh_widget_sysfs(struct hdac_device *codec);

View File

@ -163,6 +163,28 @@ void snd_hdac_device_unregister(struct hdac_device *codec)
} }
EXPORT_SYMBOL_GPL(snd_hdac_device_unregister); EXPORT_SYMBOL_GPL(snd_hdac_device_unregister);
/**
* snd_hdac_device_set_chip_name - set/update the codec name
* @codec: the HDAC device
* @name: name string to set
*
* Returns 0 if the name is set or updated, or a negative error code.
*/
int snd_hdac_device_set_chip_name(struct hdac_device *codec, const char *name)
{
char *newname;
if (!name)
return 0;
newname = kstrdup(name, GFP_KERNEL);
if (!newname)
return -ENOMEM;
kfree(codec->chip_name);
codec->chip_name = newname;
return 0;
}
EXPORT_SYMBOL_GPL(snd_hdac_device_set_chip_name);
/** /**
* snd_hdac_make_cmd - compose a 32bit command word to be sent to the * snd_hdac_make_cmd - compose a 32bit command word to be sent to the
* HD-audio controller * HD-audio controller

View File

@ -45,15 +45,31 @@ static void hda_codec_unsol_event(struct hdac_device *dev, unsigned int ev)
codec->patch_ops.unsol_event(codec, ev); codec->patch_ops.unsol_event(codec, ev);
} }
/* reset the codec name from the preset */ /**
static int codec_refresh_name(struct hda_codec *codec, const char *name) * snd_hda_codec_set_name - set the codec name
* @codec: the HDA codec
* @name: name string to set
*/
int snd_hda_codec_set_name(struct hda_codec *codec, const char *name)
{ {
if (name) { int err;
kfree(codec->core.chip_name);
codec->core.chip_name = kstrdup(name, GFP_KERNEL); if (!name)
return 0;
err = snd_hdac_device_set_chip_name(&codec->core, name);
if (err < 0)
return err;
/* update the mixer name */
if (!*codec->card->mixername) {
snprintf(codec->card->mixername,
sizeof(codec->card->mixername), "%s %s",
codec->core.vendor_name, codec->core.chip_name);
} }
return codec->core.chip_name ? 0 : -ENOMEM;
return 0;
} }
EXPORT_SYMBOL_GPL(snd_hda_codec_set_name);
static int hda_codec_driver_probe(struct device *dev) static int hda_codec_driver_probe(struct device *dev)
{ {
@ -64,7 +80,7 @@ static int hda_codec_driver_probe(struct device *dev)
if (WARN_ON(!codec->preset)) if (WARN_ON(!codec->preset))
return -EINVAL; return -EINVAL;
err = codec_refresh_name(codec, codec->preset->name); err = snd_hda_codec_set_name(codec, codec->preset->name);
if (err < 0) if (err < 0)
goto error; goto error;
err = snd_hdac_regmap_init(&codec->core); err = snd_hdac_regmap_init(&codec->core);
@ -251,11 +267,6 @@ int snd_hda_codec_configure(struct hda_codec *codec)
} }
} }
/* audio codec should override the mixer name */
if (codec->core.afg || !*codec->card->mixername)
snprintf(codec->card->mixername,
sizeof(codec->card->mixername), "%s %s",
codec->core.vendor_name, codec->core.chip_name);
return 0; return 0;
error: error:

View File

@ -463,6 +463,8 @@ void snd_hda_unlock_devices(struct hda_bus *bus);
void snd_hda_bus_reset(struct hda_bus *bus); void snd_hda_bus_reset(struct hda_bus *bus);
void snd_hda_bus_reset_codecs(struct hda_bus *bus); void snd_hda_bus_reset_codecs(struct hda_bus *bus);
int snd_hda_codec_set_name(struct hda_codec *codec, const char *name);
/* /*
* power management * power management
*/ */

View File

@ -595,8 +595,7 @@ static void parse_model_mode(char *buf, struct hda_bus *bus,
static void parse_chip_name_mode(char *buf, struct hda_bus *bus, static void parse_chip_name_mode(char *buf, struct hda_bus *bus,
struct hda_codec **codecp) struct hda_codec **codecp)
{ {
kfree((*codecp)->core.chip_name); snd_hda_codec_set_name(*codecp, buf);
(*codecp)->core.chip_name = kstrdup(buf, GFP_KERNEL);
} }
#define DEFINE_PARSE_ID_MODE(name) \ #define DEFINE_PARSE_ID_MODE(name) \

View File

@ -822,17 +822,7 @@ static const struct hda_codec_ops alc_patch_ops = {
}; };
/* replace the codec chip_name with the given string */ #define alc_codec_rename(codec, name) snd_hda_codec_set_name(codec, name)
static int alc_codec_rename(struct hda_codec *codec, const char *name)
{
kfree(codec->core.chip_name);
codec->core.chip_name = kstrdup(name, GFP_KERNEL);
if (!codec->core.chip_name) {
alc_free(codec);
return -ENOMEM;
}
return 0;
}
/* /*
* Rename codecs appropriately from COEF value or subvendor id * Rename codecs appropriately from COEF value or subvendor id

View File

@ -785,21 +785,11 @@ static int patch_vt1708S(struct hda_codec *codec)
override_mic_boost(codec, 0x1e, 0, 3, 40); override_mic_boost(codec, 0x1e, 0, 3, 40);
/* correct names for VT1708BCE */ /* correct names for VT1708BCE */
if (get_codec_type(codec) == VT1708BCE) { if (get_codec_type(codec) == VT1708BCE)
kfree(codec->core.chip_name); snd_hda_codec_set_name(codec, "VT1708BCE");
codec->core.chip_name = kstrdup("VT1708BCE", GFP_KERNEL);
snprintf(codec->card->mixername,
sizeof(codec->card->mixername),
"%s %s", codec->core.vendor_name, codec->core.chip_name);
}
/* correct names for VT1705 */ /* correct names for VT1705 */
if (codec->core.vendor_id == 0x11064397) { if (codec->core.vendor_id == 0x11064397)
kfree(codec->core.chip_name); snd_hda_codec_set_name(codec, "VT1705");
codec->core.chip_name = kstrdup("VT1705", GFP_KERNEL);
snprintf(codec->card->mixername,
sizeof(codec->card->mixername),
"%s %s", codec->core.vendor_name, codec->core.chip_name);
}
/* automatic parse from the BIOS config */ /* automatic parse from the BIOS config */
err = via_parse_auto_config(codec); err = via_parse_auto_config(codec);