ALSA: Cleanup with snd_ctl_add_followers()
v2 cover ALSA: Cleanup with snd_ctl_add_followers()
This is another set of cleanup patches: introduce a new standard helper for adding vmaster control elements, and replace the open code in a few drivers with it.
Takashi
===
v1->v2: Cleanup of ac97 patch to drop unnecessary check of the error
condition
===
Takashi Iwai (4):
ALSA: vmaster: Add snd_ctl_add_followers() helper
ALSA: ac97: Use the standard snd_ctl_add_followers() helper
ALSA: ca0106: Use the standard snd_ctl_add_followers() helper
ALSA: ice1712: Use the standard snd_ctl_add_followers() helper
include/sound/control.h | 3 +++ sound/core/vmaster.c | 28 ++++++++++++++++++++++++++++ sound/pci/ac97/ac97_patch.c | 16 +--------------- sound/pci/ca0106/ca0106_mixer.c | 19 ++++++------------- sound/pci/ice1712/juli.c | 19 +++---------------- sound/pci/ice1712/quartet.c | 15 +++------------ 6 files changed, 44 insertions(+), 56 deletions(-)
Signature · 1 line
2.35.3
PATCH v2 1/4 ALSA: vmaster: Add snd_ctl_add_followers() helper
Add a new helper to add multiple vmaster followers in a shot. The same function was open-coded in various places, and this helper replaces them.
--- include/sound/control.h | 3 +++ sound/core/vmaster.c | 28 ++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+)
include/sound/control.h +3 -0
@@ -262,6 +262,9 @@ snd_ctl_add_follower(struct snd_kcontrol *master, struct snd_kcontrol *follower)return _snd_ctl_add_follower (master, follower,0 ); } +int snd_ctl_add_followers (struct snd_card *card,struct snd_kcontrol *master, +const char *const *list); +/** * snd_ctl_add_follower_uncached - Add a virtual follower control * @master: vmaster element
sound/core/vmaster.c +28 -0
@@ -280,6 +280,34 @@ int _snd_ctl_add_follower(struct snd_kcontrol *master, }EXPORT_SYMBOL (_snd_ctl_add_follower); +/** +* snd_ctl_add_followers - add multiple followers to vmaster +* @card: card instance +* @master: the target vmaster kcontrol object +* @list: NULL-terminated list of name strings of followers to be added +* +* Adds the multiple follower kcontrols with the given names. +* Returns 0 for success or a negative error code. +*/ +int snd_ctl_add_followers (struct snd_card *card,struct snd_kcontrol *master, +const char *const *list) +{ +struct snd_kcontrol *follower; +int err; + +for (; *list; list++) { + follower =snd_ctl_find_id_mixer (card, *list); +if (follower) { + err =snd_ctl_add_follower (master, follower); +if (err <0 ) +return err; + } + } + +return 0 ; +} +EXPORT_SYMBOL_GPL (snd_ctl_add_followers); +/* * ctl callbacks for master controls */
Signature · 1 line
2.35.3
PATCH v2 2/4 ALSA: ac97: Use the standard snd_ctl_add_followers() helper
In reply to Takashi IwaiInstead of open-code, use the new standard helper to manage vmaster stuff for code simplification.
Except for a debug print, there should be no functional change.
---v1->v2: drop unnecessary check of the error condition
sound/pci/ac97/ac97_patch.c | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-)
sound/pci/ac97/ac97_patch.c +1 -15
@@ -3440,7 +3440,6 @@ static int snd_ac97_add_vmaster(struct snd_ac97 *ac97, char *name, const char * const *followers) {struct snd_kcontrol *kctl; -const char *const *s;int err; kctl =snd_ctl_make_virtual_master (name, tlv);
@@ -3450,20 +3449,7 @@ static int snd_ac97_add_vmaster(struct snd_ac97 *ac97, char *name,if (err <0 )return err; -for (s = followers; *s; s++) { -struct snd_kcontrol *sctl; - - sctl =snd_ac97_find_mixer_ctl (ac97, *s); -if (!sctl) { -dev_dbg (ac97->bus->card->dev, -"Cannot find follower %s, skipped\n" , *s); -continue ; - } - err =snd_ctl_add_follower (kctl, sctl); -if (err <0 ) -return err; - } -return 0 ; +return snd_ctl_add_followers (ac97->bus->card, kctl, followers); }static int patch_vt1616_specific (struct snd_ac97 * ac97)
Signature · 1 line
2.35.3
PATCH v2 3/4 ALSA: ca0106: Use the standard snd_ctl_add_followers() helper
In reply to Takashi IwaiInstead of open-code, use the new standard helper to manage vmaster stuff for code simplification.
Also, handle the errors from the helper more properly instead of silently ignoring.
--- sound/pci/ca0106/ca0106_mixer.c | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-)
sound/pci/ca0106/ca0106_mixer.c +6 -13
@@ -751,17 +751,6 @@ static const char * const follower_sws[] = { NULL }; -static void add_followers (struct snd_card *card, -struct snd_kcontrol *master,const char *const *list) -{ -for (; *list; list++) { -struct snd_kcontrol *follower = -snd_ctl_find_id_mixer (card, *list); -if (follower) -snd_ctl_add_follower (master, follower); - } -} -int snd_ca0106_mixer (struct snd_ca0106 *emu) {int err;
@@ -843,7 +832,9 @@ int snd_ca0106_mixer(struct snd_ca0106 *emu) err =snd_ctl_add (card, vmaster);if (err <0 )return err; -add_followers (card, vmaster, follower_vols); + err =snd_ctl_add_followers (card, vmaster, follower_vols); +if (err <0 ) +return err;if (emu->details->spi_dac) { vmaster = snd_ctl_make_virtual_master("Master Playback Switch",
@@ -853,7 +844,9 @@ int snd_ca0106_mixer(struct snd_ca0106 *emu) err =snd_ctl_add (card, vmaster);if (err <0 )return err; -add_followers (card, vmaster, follower_sws); + err =snd_ctl_add_followers (card, vmaster, follower_sws); +if (err <0 ) +return err; }strcpy (card->mixername,"CA0106" );
Signature · 1 line
2.35.3
PATCH v2 4/4 ALSA: ice1712: Use the standard snd_ctl_add_followers() helper
In reply to Takashi IwaiInstead of open-code, use the new standard helper to manage vmaster stuff for code simplification.
Also, handle the errors from the helper more properly instead of silently ignoring.
The code changes the call order of snd_ctl_add() of the vmaster object and its followers for avoiding the possible memory leaks at error path. But there should be no difference in the functionality.
--- sound/pci/ice1712/juli.c | 19 +++---------------- sound/pci/ice1712/quartet.c | 15 +++------------ 2 files changed, 6 insertions(+), 28 deletions(-)
sound/pci/ice1712/juli.c +3 -16
@@ -408,21 +408,6 @@ static const char * const follower_vols[] = {static DECLARE_TLV_DB_SCALE(juli_master_db_scale, -6350, 50, 1); -static void add_followers (struct snd_card *card, -struct snd_kcontrol *master, -const char *const *list) -{ -for (; *list; 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); */ -snd_ctl_add_follower (master, follower); - } - } -} -static int juli_add_controls (struct snd_ice1712 *ice) {struct juli_spec *spec = ice->spec;
@@ -445,8 +430,10 @@ static int juli_add_controls(struct snd_ice1712 *ice) juli_master_db_scale);if (!vmaster)return -ENOMEM ; -add_followers (ice->card, vmaster, follower_vols); err =snd_ctl_add (ice->card, vmaster); +if (err <0 ) +return err; + err =snd_ctl_add_followers (ice->card, vmaster, follower_vols);if (err <0 )return err;
sound/pci/ice1712/quartet.c +3 -12
@@ -766,17 +766,6 @@ static const char * const follower_vols[] = {static DECLARE_TLV_DB_SCALE(qtet_master_db_scale, -6350, 50, 1); -static void add_followers (struct snd_card *card, -struct snd_kcontrol *master,const char *const *list) -{ -for (; *list; list++) { -struct snd_kcontrol *follower = -snd_ctl_find_id_mixer (card, *list); -if (follower) -snd_ctl_add_follower (master, follower); - } -} -static int qtet_add_controls (struct snd_ice1712 *ice) {struct qtet_spec *spec = ice->spec;
@@ -797,8 +786,10 @@ static int qtet_add_controls(struct snd_ice1712 *ice) qtet_master_db_scale);if (!vmaster)return -ENOMEM ; -add_followers (ice->card, vmaster, follower_vols); err =snd_ctl_add (ice->card, vmaster); +if (err <0 ) +return err; + err =snd_ctl_add_followers (ice->card, vmaster, follower_vols);if (err <0 )return err;/* only capture SPDIF over AK4113 */
Signature · 1 line
2.35.3