ALSA: Cleanup with snd_ctl_find_id_mixer()
Subsystems (3)
cover ALSA: Cleanup with snd_ctl_find_id_mixer()
Quite a few drivers have the very same open code to find a control element from the given name string. Provide a standard helper and replace with it for cleanup.
Takashi
===
Takashi Iwai (11):
ALSA: control: Introduce snd_ctl_find_id_mixer()
ALSA: ca0106: Simplify with snd_ctl_find_id_mixer()
ALSA: cs46xx: Simplify with snd_ctl_find_id_mixer()
ALSA: emu10k1: Simplify with snd_ctl_find_id_mixer()
ALSA: es1968: Simplify with snd_ctl_find_id_mixer()
ALSA: ice1712: Simplify with snd_ctl_find_id_mixer()
ALSA: maestro3: Simplify with snd_ctl_find_id_mixer()
ALSA: via82xx: Simplify with snd_ctl_find_id_mixer()
ALSA: cmipci: Simplify with snd_ctl_find_id_mixer()
ASoC: mediatek: mt8188: Simplify with snd_ctl_find_id_mixer()
ALSA: ac97: Simplify with snd_ctl_find_id_mixer()
include/sound/control.h | 22 ++++++++++++++++++++++ sound/pci/ac97/ac97_patch.c | 6 +----- sound/pci/ca0106/ca0106_mixer.c | 15 +++------------ sound/pci/cmipci.c | 6 +----- sound/pci/cs46xx/cs46xx_lib.c | 7 ++----- sound/pci/emu10k1/emumixer.c | 11 +---------- sound/pci/es1968.c | 15 ++++----------- sound/pci/ice1712/juli.c | 13 ++----------- sound/pci/ice1712/psc724.c | 19 ++++++++----------- sound/pci/ice1712/quartet.c | 13 ++----------- sound/pci/ice1712/wm8776.c | 6 +----- sound/pci/maestro3.c | 15 ++++----------- sound/pci/via82xx.c | 6 +----- sound/soc/mediatek/mt8188/mt8188-mt6359.c | 12 +----------- 14 files changed, 53 insertions(+), 113 deletions(-)
Signature · 1 line
2.35.3
PATCH 1/11 ALSA: control: Introduce snd_ctl_find_id_mixer()
A commonly seen pattern is to run snd_ctl_find_id() for a mixer control element with a given string. Let's provide a standard helper for achieving that for simplifying the code.
--- include/sound/control.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+)
include/sound/control.h +22 -0
@@ -145,6 +145,28 @@ struct snd_kcontrol *snd_ctl_find_numid(struct snd_card *card, unsigned int numistruct snd_kcontrol *snd_ctl_find_id_locked (struct snd_card *card,const struct snd_ctl_elem_id *id);struct snd_kcontrol *snd_ctl_find_id (struct snd_card *card,const struct snd_ctl_elem_id *id); +/** +* snd_ctl_find_id_mixer - find the control instance with the given name string +* @card: the card instance +* @name: the name string +* +* Finds the control instance with the given name and +* @SNDRV_CTL_ELEM_IFACE_MIXER. Other fields are set to zero. +* +* This is merely a wrapper to snd_ctl_find_id(). +* +* Return: The pointer of the instance if found, or %NULL if not. +*/ +static inline struct snd_kcontrol * +snd_ctl_find_id_mixer (struct snd_card *card,const char *name) +{ +struct snd_ctl_elem_id id = {}; + + id.iface =SNDRV_CTL_ELEM_IFACE_MIXER ; +strscpy (id.name, name,sizeof (id.name)); +return snd_ctl_find_id (card, &id); +} +int snd_ctl_create (struct snd_card *card);int snd_ctl_register_ioctl (snd_kctl_ioctl_func_t fcn);
Signature · 1 line
2.35.3
PATCH 2/11 ALSA: ca0106: Simplify with snd_ctl_find_id_mixer()
In reply to Takashi IwaiReplace an open code with the new snd_ctl_find_id_mixer(). There is no functional change.
--- sound/pci/ca0106/ca0106_mixer.c | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-)
sound/pci/ca0106/ca0106_mixer.c +3 -12
@@ -706,19 +706,9 @@ static int remove_ctl(struct snd_card *card, const char *name)return snd_ctl_remove_id (card, &id); } -static struct snd_kcontrol *ctl_find (struct snd_card *card,const char *name) -{ -struct snd_ctl_elem_id sid; -memset (&sid,0 ,sizeof (sid)); -/* FIXME: strcpy is bad. */ -strcpy (sid.name, name); - sid.iface =SNDRV_CTL_ELEM_IFACE_MIXER ; -return snd_ctl_find_id (card, &sid); -} -static int rename_ctl (struct snd_card *card,const char *src,const char *dst) { -struct snd_kcontrol *kctl =ctl_find (card, src); +struct snd_kcontrol *kctl =snd_ctl_find_id_mixer (card, src);if (kctl) {snd_ctl_rename (card, kctl, dst);return 0 ;
@@ -765,7 +755,8 @@ static void add_followers(struct snd_card *card, struct snd_kcontrol *master, const char * const *list) {for (; *list; list++) { -struct snd_kcontrol *follower =ctl_find (card, *list); +struct snd_kcontrol *follower = +snd_ctl_find_id_mixer (card, *list);if (follower)snd_ctl_add_follower (master, follower); }
Signature · 1 line
2.35.3
PATCH 3/11 ALSA: cs46xx: Simplify with snd_ctl_find_id_mixer()
In reply to Takashi IwaiReplace an open code with the new snd_ctl_find_id_mixer(). There is no functional change.
--- sound/pci/cs46xx/cs46xx_lib.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
sound/pci/cs46xx/cs46xx_lib.c +2 -5
@@ -2449,7 +2449,6 @@ static int cs46xx_detect_codec(struct snd_cs46xx *chip, int codec)int snd_cs46xx_mixer (struct snd_cs46xx *chip,int spdif_device) {struct snd_card *card = chip->card; -struct snd_ctl_elem_id id;int err;unsigned int idx;static const struct snd_ac97_bus_ops ops = {
@@ -2490,10 +2489,8 @@ int snd_cs46xx_mixer(struct snd_cs46xx *chip, int spdif_device) }/* get EAPD mixer switch (for voyetra hack) */ -memset (&id,0 ,sizeof (id)); - id.iface =SNDRV_CTL_ELEM_IFACE_MIXER ; -strcpy (id.name,"External Amplifier" ); - chip->eapd_switch =snd_ctl_find_id (chip->card, &id); + chip->eapd_switch =snd_ctl_find_id_mixer (chip->card, +"External Amplifier" );#ifdef CONFIG_SND_CS46XX_NEW_DSP if (chip->nr_ac97_codecs ==1 ) {
Signature · 1 line
2.35.3
PATCH 4/11 ALSA: emu10k1: Simplify with snd_ctl_find_id_mixer()
In reply to Takashi IwaiReplace an open code with the new snd_ctl_find_id_mixer(). There is no functional change.
--- sound/pci/emu10k1/emumixer.c | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-)
sound/pci/emu10k1/emumixer.c +1 -10
@@ -1982,18 +1982,9 @@ static int remove_ctl(struct snd_card *card, const char *name)return snd_ctl_remove_id (card, &id); } -static struct snd_kcontrol *ctl_find (struct snd_card *card,const char *name) -{ -struct snd_ctl_elem_id sid; -memset (&sid,0 ,sizeof (sid)); -strcpy (sid.name, name); - sid.iface =SNDRV_CTL_ELEM_IFACE_MIXER ; -return snd_ctl_find_id (card, &sid); -} -static int rename_ctl (struct snd_card *card,const char *src,const char *dst) { -struct snd_kcontrol *kctl =ctl_find (card, src); +struct snd_kcontrol *kctl =snd_ctl_find_id_mixer (card, src);if (kctl) {snd_ctl_rename (card, kctl, dst);return 0 ;
Signature · 1 line
2.35.3
PATCH 5/11 ALSA: es1968: Simplify with snd_ctl_find_id_mixer()
In reply to Takashi IwaiReplace an open code with the new snd_ctl_find_id_mixer(). There is no functional change.
--- sound/pci/es1968.c | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-)
sound/pci/es1968.c +4 -11
@@ -2005,9 +2005,6 @@ snd_es1968_mixer(struct es1968 *chip) {struct snd_ac97_bus *pbus;struct snd_ac97_template ac97; -#ifndef CONFIG_SND_ES1968_INPUT -struct snd_ctl_elem_id elem_id; -#endif int err;static const struct snd_ac97_bus_ops ops = { .write = snd_es1968_ac97_write,
@@ -2027,14 +2024,10 @@ snd_es1968_mixer(struct es1968 *chip)#ifndef CONFIG_SND_ES1968_INPUT /* attach master switch / volumes for h/w volume control */ -memset (&elem_id,0 ,sizeof (elem_id)); - elem_id.iface =SNDRV_CTL_ELEM_IFACE_MIXER ; -strcpy (elem_id.name,"Master Playback Switch" ); - chip->master_switch =snd_ctl_find_id (chip->card, &elem_id); -memset (&elem_id,0 ,sizeof (elem_id)); - elem_id.iface =SNDRV_CTL_ELEM_IFACE_MIXER ; -strcpy (elem_id.name,"Master Playback Volume" ); - chip->master_volume =snd_ctl_find_id (chip->card, &elem_id); + chip->master_switch =snd_ctl_find_id_mixer (chip->card, +"Master Playback Switch" ); + chip->master_volume =snd_ctl_find_id_mixer (chip->card, +"Master Playback Volume" );#endif return 0 ;
Signature · 1 line
2.35.3
PATCH 6/11 ALSA: ice1712: Simplify with snd_ctl_find_id_mixer()
In reply to Takashi IwaiReplace an open code with the new snd_ctl_find_id_mixer(). There is no functional change.
Also, add the missing NULL checks in psc724_set_jack_state() to deal with error cases.
--- sound/pci/ice1712/juli.c | 13 ++----------- sound/pci/ice1712/psc724.c | 19 ++++++++----------- sound/pci/ice1712/quartet.c | 13 ++----------- sound/pci/ice1712/wm8776.c | 6 +----- 4 files changed, 13 insertions(+), 38 deletions(-)
sound/pci/ice1712/juli.c +2 -11
@@ -408,22 +408,13 @@ static const char * const follower_vols[] = {static DECLARE_TLV_DB_SCALE(juli_master_db_scale, -6350, 50, 1); -static struct snd_kcontrol *ctl_find (struct snd_card *card, -const char *name) -{ -struct snd_ctl_elem_id sid = {0 }; - -strscpy (sid.name, name,sizeof (sid.name)); - sid.iface =SNDRV_CTL_ELEM_IFACE_MIXER ; -return snd_ctl_find_id (card, &sid); -} -static void add_followers (struct snd_card *card,struct snd_kcontrol *master,const char *const *list) {for (; *list; list++) { -struct snd_kcontrol *follower =ctl_find (card, *list); +struct snd_kcontrol *follower = +snd_ctl_find_id_mixer (card, *list);/* dev_dbg(card->dev, "add_followers - %s\n", *list); */ if (follower) {/* dev_dbg(card->dev, "follower %s found\n", *list); */
sound/pci/ice1712/psc724.c +8 -11
@@ -177,7 +177,6 @@ static bool psc724_get_master_switch(struct snd_ice1712 *ice)static void psc724_set_jack_state (struct snd_ice1712 *ice,bool hp_connected) {struct psc724_spec *spec = ice->spec; -struct snd_ctl_elem_id elem_id;struct snd_kcontrol *kctl;u16 power = spec->wm8776.regs[WM8776_REG_PWRDOWN ] & ~WM8776_PWR_HPPD ;
@@ -187,17 +186,15 @@ static void psc724_set_jack_state(struct snd_ice1712 *ice, bool hp_connected)snd_wm8776_set_power (&spec->wm8776, power); spec->hp_connected = hp_connected;/* notify about master speaker mute change */ -memset (&elem_id,0 ,sizeof (elem_id)); - elem_id.iface =SNDRV_CTL_ELEM_IFACE_MIXER ; -strscpy (elem_id.name,"Master Speakers Playback Switch" , -sizeof (elem_id.name)); - kctl =snd_ctl_find_id (ice->card, &elem_id); -snd_ctl_notify (ice->card,SNDRV_CTL_EVENT_MASK_VALUE , &kctl->id); + kctl =snd_ctl_find_id_mixer (ice->card, +"Master Speakers Playback Switch" ); +if (kctl) +snd_ctl_notify (ice->card,SNDRV_CTL_EVENT_MASK_VALUE , &kctl->id);/* and headphone mute change */ -strscpy (elem_id.name, spec->wm8776.ctl[WM8776_CTL_HP_SW ].name, -sizeof (elem_id.name)); - kctl =snd_ctl_find_id (ice->card, &elem_id); -snd_ctl_notify (ice->card,SNDRV_CTL_EVENT_MASK_VALUE , &kctl->id); + kctl =snd_ctl_find_id_mixer (ice->card, + spec->wm8776.ctl[WM8776_CTL_HP_SW ].name); +if (kctl) +snd_ctl_notify (ice->card,SNDRV_CTL_EVENT_MASK_VALUE , &kctl->id); }static void psc724_update_hp_jack_state (struct work_struct *work)
sound/pci/ice1712/quartet.c +2 -11
@@ -766,21 +766,12 @@ static const char * const follower_vols[] = {static DECLARE_TLV_DB_SCALE(qtet_master_db_scale, -6350, 50, 1); -static struct snd_kcontrol *ctl_find (struct snd_card *card, -const char *name) -{ -struct snd_ctl_elem_id sid = {0 }; - -strscpy (sid.name, name,sizeof (sid.name)); - sid.iface =SNDRV_CTL_ELEM_IFACE_MIXER ; -return snd_ctl_find_id (card, &sid); -} -static void add_followers (struct snd_card *card,struct snd_kcontrol *master,const char *const *list) {for (; *list; list++) { -struct snd_kcontrol *follower =ctl_find (card, *list); +struct snd_kcontrol *follower = +snd_ctl_find_id_mixer (card, *list);if (follower)snd_ctl_add_follower (master, follower); }
sound/pci/ice1712/wm8776.c +1 -5
@@ -34,13 +34,9 @@ static void snd_wm8776_activate_ctl(struct snd_wm8776 *wm,struct snd_card *card = wm->card;struct snd_kcontrol *kctl;struct snd_kcontrol_volatile *vd; -struct snd_ctl_elem_id elem_id;unsigned int index_offset; -memset (&elem_id,0 ,sizeof (elem_id)); -strscpy (elem_id.name, ctl_name,sizeof (elem_id.name)); - elem_id.iface =SNDRV_CTL_ELEM_IFACE_MIXER ; - kctl =snd_ctl_find_id (card, &elem_id); + kctl =snd_ctl_find_id_mixer (card, ctl_name);if (!kctl)return ; index_offset =snd_ctl_get_ioff (kctl, &kctl->id);
Signature · 1 line
2.35.3
PATCH 7/11 ALSA: maestro3: Simplify with snd_ctl_find_id_mixer()
In reply to Takashi IwaiReplace an open code with the new snd_ctl_find_id_mixer(). There is no functional change.
--- sound/pci/maestro3.c | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-)
sound/pci/maestro3.c +4 -11
@@ -2029,9 +2029,6 @@ static int snd_m3_mixer(struct snd_m3 *chip) {struct snd_ac97_bus *pbus;struct snd_ac97_template ac97; -#ifndef CONFIG_SND_MAESTRO3_INPUT -struct snd_ctl_elem_id elem_id; -#endif int err;static const struct snd_ac97_bus_ops ops = { .write = snd_m3_ac97_write,
@@ -2054,14 +2051,10 @@ static int snd_m3_mixer(struct snd_m3 *chip)snd_ac97_write (chip->ac97,AC97_PCM ,0 );#ifndef CONFIG_SND_MAESTRO3_INPUT -memset (&elem_id,0 ,sizeof (elem_id)); - elem_id.iface =SNDRV_CTL_ELEM_IFACE_MIXER ; -strcpy (elem_id.name,"Master Playback Switch" ); - chip->master_switch =snd_ctl_find_id (chip->card, &elem_id); -memset (&elem_id,0 ,sizeof (elem_id)); - elem_id.iface =SNDRV_CTL_ELEM_IFACE_MIXER ; -strcpy (elem_id.name,"Master Playback Volume" ); - chip->master_volume =snd_ctl_find_id (chip->card, &elem_id); + chip->master_switch =snd_ctl_find_id_mixer (chip->card, +"Master Playback Switch" ); + chip->master_volume =snd_ctl_find_id_mixer (chip->card, +"Master Playback Volume" );#endif return 0 ;
Signature · 1 line
2.35.3
PATCH 8/11 ALSA: via82xx: Simplify with snd_ctl_find_id_mixer()
In reply to Takashi IwaiReplace an open code with the new snd_ctl_find_id_mixer(). There is no functional change.
--- sound/pci/via82xx.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)
sound/pci/via82xx.c +1 -5
@@ -1984,11 +1984,7 @@ static int snd_via8233_init_misc(struct via82xx *chip)/* when no h/w PCM volume control is found, use DXS volume control * as the PCM vol control */ -struct snd_ctl_elem_id sid; -memset (&sid,0 ,sizeof (sid)); -strcpy (sid.name,"PCM Playback Volume" ); - sid.iface =SNDRV_CTL_ELEM_IFACE_MIXER ; -if (!snd_ctl_find_id (chip->card, &sid)) { +if (!snd_ctl_find_id_mixer (chip->card,"PCM Playback Volume" )) {dev_info (chip->card->dev,"Using DXS as PCM Playback\n" ); err =snd_ctl_add (chip->card,snd_ctl_new1 (&snd_via8233_pcmdxs_volume_control, chip));
Signature · 1 line
2.35.3
PATCH 9/11 ALSA: cmipci: Simplify with snd_ctl_find_id_mixer()
In reply to Takashi IwaiReplace an open code with the new snd_ctl_find_id_mixer(). There is no functional change.
--- sound/pci/cmipci.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)
sound/pci/cmipci.c +1 -5
@@ -2734,12 +2734,8 @@ static int snd_cmipci_mixer_new(struct cmipci *cm, int pcm_spdif_device) }for (idx =0 ; idx <CM_SAVED_MIXERS ; idx++) { -struct snd_ctl_elem_id elem_id;struct snd_kcontrol *ctl; -memset (&elem_id,0 ,sizeof (elem_id)); - elem_id.iface =SNDRV_CTL_ELEM_IFACE_MIXER ; -strcpy (elem_id.name, cm_saved_mixer[idx].name); - ctl =snd_ctl_find_id (cm->card, &elem_id); + ctl =snd_ctl_find_id_mixer (cm->card, cm_saved_mixer[idx].name);if (ctl) cm->mixer_res_ctl[idx] = ctl; }
Signature · 1 line
2.35.3
PATCH 10/11 ASoC: mediatek: mt8188: Simplify with snd_ctl_find_id_mixer()
In reply to Takashi IwaiReplace an open code with the new snd_ctl_find_id_mixer(). There is no functional change.
--- sound/soc/mediatek/mt8188/mt8188-mt6359.c | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-)
sound/soc/mediatek/mt8188/mt8188-mt6359.c +1 -11
@@ -969,16 +969,6 @@ static struct snd_soc_dai_link mt8188_mt6359_dai_links[] = { }, }; -static struct snd_kcontrol *ctl_find (struct snd_card *card,const char *name) -{ -struct snd_ctl_elem_id sid; - -memset (&sid,0 ,sizeof (sid)); -strcpy (sid.name, name); - sid.iface =SNDRV_CTL_ELEM_IFACE_MIXER ; -return snd_ctl_find_id (card, &sid); -} -static void mt8188_fixup_controls (struct snd_soc_card *card) {struct mt8188_mt6359_priv *priv =snd_soc_card_get_drvdata (card);
@@ -995,7 +985,7 @@ static void mt8188_fixup_controls(struct snd_soc_card *card)snd_soc_dapm_free_widget (w); } - kctl =ctl_find (card->snd_card,"Headphone Switch" ); + kctl =snd_ctl_find_id_mixer (card->snd_card,"Headphone Switch" );if (kctl)snd_ctl_remove (card->snd_card, kctl);else
Signature · 1 line
2.35.3
Re: [PATCH 10/11] ASoC: mediatek: mt8188: Simplify with snd_ctl_find_id_mixer()
Quoted 2 lines · Takashi Iwai
Replace an open code with the new
snd_ctl_find_id_mixer(). There is no functional change.
PATCH 11/11 ALSA: ac97: Simplify with snd_ctl_find_id_mixer()
In reply to Takashi IwaiReplace an open code with the new snd_ctl_find_id_mixer(). There is no functional change.
--- sound/pci/ac97/ac97_patch.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)
sound/pci/ac97/ac97_patch.c +1 -5
@@ -3431,11 +3431,7 @@ static const char * const follower_sws_vt1616[] = {static struct snd_kcontrol *snd_ac97_find_mixer_ctl (struct snd_ac97 *ac97,const char *name) { -struct snd_ctl_elem_id id; -memset (&id,0 ,sizeof (id)); - id.iface =SNDRV_CTL_ELEM_IFACE_MIXER ; -strcpy (id.name, name); -return snd_ctl_find_id (ac97->bus->card, &id); +return snd_ctl_find_id_mixer (ac97->bus->card, name); }/* create a virtual master control and add followers */
Signature · 1 line
2.35.3