Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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.

Link: https://lore.kernel.org/r/20230721071643.3631-2-tiwai@suse.de
Signed-off-by: Takashi Iwai <tiwai@suse.de>

+31
+3
include/sound/control.h
··· 262 262 return _snd_ctl_add_follower(master, follower, 0); 263 263 } 264 264 265 + int snd_ctl_add_followers(struct snd_card *card, struct snd_kcontrol *master, 266 + const char * const *list); 267 + 265 268 /** 266 269 * snd_ctl_add_follower_uncached - Add a virtual follower control 267 270 * @master: vmaster element
+28
sound/core/vmaster.c
··· 280 280 } 281 281 EXPORT_SYMBOL(_snd_ctl_add_follower); 282 282 283 + /** 284 + * snd_ctl_add_followers - add multiple followers to vmaster 285 + * @card: card instance 286 + * @master: the target vmaster kcontrol object 287 + * @list: NULL-terminated list of name strings of followers to be added 288 + * 289 + * Adds the multiple follower kcontrols with the given names. 290 + * Returns 0 for success or a negative error code. 291 + */ 292 + int snd_ctl_add_followers(struct snd_card *card, struct snd_kcontrol *master, 293 + const char * const *list) 294 + { 295 + struct snd_kcontrol *follower; 296 + int err; 297 + 298 + for (; *list; list++) { 299 + follower = snd_ctl_find_id_mixer(card, *list); 300 + if (follower) { 301 + err = snd_ctl_add_follower(master, follower); 302 + if (err < 0) 303 + return err; 304 + } 305 + } 306 + 307 + return 0; 308 + } 309 + EXPORT_SYMBOL_GPL(snd_ctl_add_followers); 310 + 283 311 /* 284 312 * ctl callbacks for master controls 285 313 */