Alsa-Devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 00/11] ALSA: Cleanup with snd_ctl_find_id_mixer()
@ 2023-07-20  8:20 Takashi Iwai
  2023-07-20  8:20 ` [PATCH 01/11] ALSA: control: Introduce snd_ctl_find_id_mixer() Takashi Iwai
                   ` (10 more replies)
  0 siblings, 11 replies; 13+ messages in thread
From: Takashi Iwai @ 2023-07-20  8:20 UTC (permalink / raw)
  To: alsa-devel; +Cc: Takashi Iwai

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(-)

-- 
2.35.3


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH 01/11] ALSA: control: Introduce snd_ctl_find_id_mixer()
  2023-07-20  8:20 [PATCH 00/11] ALSA: Cleanup with snd_ctl_find_id_mixer() Takashi Iwai
@ 2023-07-20  8:20 ` Takashi Iwai
  2023-07-20  8:20 ` [PATCH 02/11] ALSA: ca0106: Simplify with snd_ctl_find_id_mixer() Takashi Iwai
                   ` (9 subsequent siblings)
  10 siblings, 0 replies; 13+ messages in thread
From: Takashi Iwai @ 2023-07-20  8:20 UTC (permalink / raw)
  To: alsa-devel; +Cc: Takashi Iwai

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.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
 include/sound/control.h | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/include/sound/control.h b/include/sound/control.h
index 42e8dbb22d8e..69d950a34ca3 100644
--- a/include/sound/control.h
+++ b/include/sound/control.h
@@ -145,6 +145,28 @@ struct snd_kcontrol *snd_ctl_find_numid(struct snd_card *card, unsigned int numi
 struct 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);
-- 
2.35.3


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 02/11] ALSA: ca0106: Simplify with snd_ctl_find_id_mixer()
  2023-07-20  8:20 [PATCH 00/11] ALSA: Cleanup with snd_ctl_find_id_mixer() Takashi Iwai
  2023-07-20  8:20 ` [PATCH 01/11] ALSA: control: Introduce snd_ctl_find_id_mixer() Takashi Iwai
@ 2023-07-20  8:20 ` Takashi Iwai
  2023-07-20  8:21 ` [PATCH 03/11] ALSA: cs46xx: " Takashi Iwai
                   ` (8 subsequent siblings)
  10 siblings, 0 replies; 13+ messages in thread
From: Takashi Iwai @ 2023-07-20  8:20 UTC (permalink / raw)
  To: alsa-devel; +Cc: Takashi Iwai

Replace an open code with the new snd_ctl_find_id_mixer().
There is no functional change.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
 sound/pci/ca0106/ca0106_mixer.c | 15 +++------------
 1 file changed, 3 insertions(+), 12 deletions(-)

diff --git a/sound/pci/ca0106/ca0106_mixer.c b/sound/pci/ca0106/ca0106_mixer.c
index f6381c098d4f..2f37d2c3dd38 100644
--- a/sound/pci/ca0106/ca0106_mixer.c
+++ b/sound/pci/ca0106/ca0106_mixer.c
@@ -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);
 	}
-- 
2.35.3


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 03/11] ALSA: cs46xx: Simplify with snd_ctl_find_id_mixer()
  2023-07-20  8:20 [PATCH 00/11] ALSA: Cleanup with snd_ctl_find_id_mixer() Takashi Iwai
  2023-07-20  8:20 ` [PATCH 01/11] ALSA: control: Introduce snd_ctl_find_id_mixer() Takashi Iwai
  2023-07-20  8:20 ` [PATCH 02/11] ALSA: ca0106: Simplify with snd_ctl_find_id_mixer() Takashi Iwai
@ 2023-07-20  8:21 ` Takashi Iwai
  2023-07-20  8:21 ` [PATCH 04/11] ALSA: emu10k1: " Takashi Iwai
                   ` (7 subsequent siblings)
  10 siblings, 0 replies; 13+ messages in thread
From: Takashi Iwai @ 2023-07-20  8:21 UTC (permalink / raw)
  To: alsa-devel; +Cc: Takashi Iwai

Replace an open code with the new snd_ctl_find_id_mixer().
There is no functional change.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
 sound/pci/cs46xx/cs46xx_lib.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/sound/pci/cs46xx/cs46xx_lib.c b/sound/pci/cs46xx/cs46xx_lib.c
index 7d882b33d45e..f3a94bb537bd 100644
--- a/sound/pci/cs46xx/cs46xx_lib.c
+++ b/sound/pci/cs46xx/cs46xx_lib.c
@@ -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) {
-- 
2.35.3


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 04/11] ALSA: emu10k1: Simplify with snd_ctl_find_id_mixer()
  2023-07-20  8:20 [PATCH 00/11] ALSA: Cleanup with snd_ctl_find_id_mixer() Takashi Iwai
                   ` (2 preceding siblings ...)
  2023-07-20  8:21 ` [PATCH 03/11] ALSA: cs46xx: " Takashi Iwai
@ 2023-07-20  8:21 ` Takashi Iwai
  2023-07-20  8:21 ` [PATCH 05/11] ALSA: es1968: " Takashi Iwai
                   ` (6 subsequent siblings)
  10 siblings, 0 replies; 13+ messages in thread
From: Takashi Iwai @ 2023-07-20  8:21 UTC (permalink / raw)
  To: alsa-devel; +Cc: Takashi Iwai

Replace an open code with the new snd_ctl_find_id_mixer().
There is no functional change.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
 sound/pci/emu10k1/emumixer.c | 11 +----------
 1 file changed, 1 insertion(+), 10 deletions(-)

diff --git a/sound/pci/emu10k1/emumixer.c b/sound/pci/emu10k1/emumixer.c
index f72a01f8f8f2..0a32ea53d8c6 100644
--- a/sound/pci/emu10k1/emumixer.c
+++ b/sound/pci/emu10k1/emumixer.c
@@ -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;
-- 
2.35.3


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 05/11] ALSA: es1968: Simplify with snd_ctl_find_id_mixer()
  2023-07-20  8:20 [PATCH 00/11] ALSA: Cleanup with snd_ctl_find_id_mixer() Takashi Iwai
                   ` (3 preceding siblings ...)
  2023-07-20  8:21 ` [PATCH 04/11] ALSA: emu10k1: " Takashi Iwai
@ 2023-07-20  8:21 ` Takashi Iwai
  2023-07-20  8:21 ` [PATCH 06/11] ALSA: ice1712: " Takashi Iwai
                   ` (5 subsequent siblings)
  10 siblings, 0 replies; 13+ messages in thread
From: Takashi Iwai @ 2023-07-20  8:21 UTC (permalink / raw)
  To: alsa-devel; +Cc: Takashi Iwai

Replace an open code with the new snd_ctl_find_id_mixer().
There is no functional change.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
 sound/pci/es1968.c | 15 ++++-----------
 1 file changed, 4 insertions(+), 11 deletions(-)

diff --git a/sound/pci/es1968.c b/sound/pci/es1968.c
index 4a7e20bb11bc..4bc0f53c223b 100644
--- a/sound/pci/es1968.c
+++ b/sound/pci/es1968.c
@@ -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;
-- 
2.35.3


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 06/11] ALSA: ice1712: Simplify with snd_ctl_find_id_mixer()
  2023-07-20  8:20 [PATCH 00/11] ALSA: Cleanup with snd_ctl_find_id_mixer() Takashi Iwai
                   ` (4 preceding siblings ...)
  2023-07-20  8:21 ` [PATCH 05/11] ALSA: es1968: " Takashi Iwai
@ 2023-07-20  8:21 ` Takashi Iwai
  2023-07-20  8:21 ` [PATCH 07/11] ALSA: maestro3: " Takashi Iwai
                   ` (4 subsequent siblings)
  10 siblings, 0 replies; 13+ messages in thread
From: Takashi Iwai @ 2023-07-20  8:21 UTC (permalink / raw)
  To: alsa-devel; +Cc: Takashi Iwai

Replace 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.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
 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(-)

diff --git a/sound/pci/ice1712/juli.c b/sound/pci/ice1712/juli.c
index f0f8324b08b6..d80ecf1edc16 100644
--- a/sound/pci/ice1712/juli.c
+++ b/sound/pci/ice1712/juli.c
@@ -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); */
diff --git a/sound/pci/ice1712/psc724.c b/sound/pci/ice1712/psc724.c
index 82cf365cda10..0818e42c94ca 100644
--- a/sound/pci/ice1712/psc724.c
+++ b/sound/pci/ice1712/psc724.c
@@ -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)
diff --git a/sound/pci/ice1712/quartet.c b/sound/pci/ice1712/quartet.c
index 20b3e8f94719..9450c4b104f7 100644
--- a/sound/pci/ice1712/quartet.c
+++ b/sound/pci/ice1712/quartet.c
@@ -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);
 	}
diff --git a/sound/pci/ice1712/wm8776.c b/sound/pci/ice1712/wm8776.c
index 6eda86119dff..493425697bb4 100644
--- a/sound/pci/ice1712/wm8776.c
+++ b/sound/pci/ice1712/wm8776.c
@@ -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);
-- 
2.35.3


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 07/11] ALSA: maestro3: Simplify with snd_ctl_find_id_mixer()
  2023-07-20  8:20 [PATCH 00/11] ALSA: Cleanup with snd_ctl_find_id_mixer() Takashi Iwai
                   ` (5 preceding siblings ...)
  2023-07-20  8:21 ` [PATCH 06/11] ALSA: ice1712: " Takashi Iwai
@ 2023-07-20  8:21 ` Takashi Iwai
  2023-07-20  8:21 ` [PATCH 08/11] ALSA: via82xx: " Takashi Iwai
                   ` (3 subsequent siblings)
  10 siblings, 0 replies; 13+ messages in thread
From: Takashi Iwai @ 2023-07-20  8:21 UTC (permalink / raw)
  To: alsa-devel; +Cc: Takashi Iwai

Replace an open code with the new snd_ctl_find_id_mixer().
There is no functional change.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
 sound/pci/maestro3.c | 15 ++++-----------
 1 file changed, 4 insertions(+), 11 deletions(-)

diff --git a/sound/pci/maestro3.c b/sound/pci/maestro3.c
index 261850775c80..305cbd24a391 100644
--- a/sound/pci/maestro3.c
+++ b/sound/pci/maestro3.c
@@ -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;
-- 
2.35.3


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 08/11] ALSA: via82xx: Simplify with snd_ctl_find_id_mixer()
  2023-07-20  8:20 [PATCH 00/11] ALSA: Cleanup with snd_ctl_find_id_mixer() Takashi Iwai
                   ` (6 preceding siblings ...)
  2023-07-20  8:21 ` [PATCH 07/11] ALSA: maestro3: " Takashi Iwai
@ 2023-07-20  8:21 ` Takashi Iwai
  2023-07-20  8:21 ` [PATCH 09/11] ALSA: cmipci: " Takashi Iwai
                   ` (2 subsequent siblings)
  10 siblings, 0 replies; 13+ messages in thread
From: Takashi Iwai @ 2023-07-20  8:21 UTC (permalink / raw)
  To: alsa-devel; +Cc: Takashi Iwai

Replace an open code with the new snd_ctl_find_id_mixer().
There is no functional change.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
 sound/pci/via82xx.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/sound/pci/via82xx.c b/sound/pci/via82xx.c
index 361b83fd721e..d8666ff7bdfa 100644
--- a/sound/pci/via82xx.c
+++ b/sound/pci/via82xx.c
@@ -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));
-- 
2.35.3


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 09/11] ALSA: cmipci: Simplify with snd_ctl_find_id_mixer()
  2023-07-20  8:20 [PATCH 00/11] ALSA: Cleanup with snd_ctl_find_id_mixer() Takashi Iwai
                   ` (7 preceding siblings ...)
  2023-07-20  8:21 ` [PATCH 08/11] ALSA: via82xx: " Takashi Iwai
@ 2023-07-20  8:21 ` Takashi Iwai
  2023-07-20  8:21 ` [PATCH 10/11] ASoC: mediatek: mt8188: " Takashi Iwai
  2023-07-20  8:21 ` [PATCH 11/11] ALSA: ac97: " Takashi Iwai
  10 siblings, 0 replies; 13+ messages in thread
From: Takashi Iwai @ 2023-07-20  8:21 UTC (permalink / raw)
  To: alsa-devel; +Cc: Takashi Iwai

Replace an open code with the new snd_ctl_find_id_mixer().
There is no functional change.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
 sound/pci/cmipci.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/sound/pci/cmipci.c b/sound/pci/cmipci.c
index 6d25c12d9ef0..1415baac9c36 100644
--- a/sound/pci/cmipci.c
+++ b/sound/pci/cmipci.c
@@ -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;
 	}
-- 
2.35.3


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 10/11] ASoC: mediatek: mt8188: Simplify with snd_ctl_find_id_mixer()
  2023-07-20  8:20 [PATCH 00/11] ALSA: Cleanup with snd_ctl_find_id_mixer() Takashi Iwai
                   ` (8 preceding siblings ...)
  2023-07-20  8:21 ` [PATCH 09/11] ALSA: cmipci: " Takashi Iwai
@ 2023-07-20  8:21 ` Takashi Iwai
  2023-07-20 13:02   ` Mark Brown
  2023-07-20  8:21 ` [PATCH 11/11] ALSA: ac97: " Takashi Iwai
  10 siblings, 1 reply; 13+ messages in thread
From: Takashi Iwai @ 2023-07-20  8:21 UTC (permalink / raw)
  To: alsa-devel; +Cc: Takashi Iwai, Trevor Wu, Mark Brown

Replace an open code with the new snd_ctl_find_id_mixer().
There is no functional change.

Cc: Trevor Wu <trevor.wu@mediatek.com>
Cc: Mark Brown <broonie@kernel.org>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
 sound/soc/mediatek/mt8188/mt8188-mt6359.c | 12 +-----------
 1 file changed, 1 insertion(+), 11 deletions(-)

diff --git a/sound/soc/mediatek/mt8188/mt8188-mt6359.c b/sound/soc/mediatek/mt8188/mt8188-mt6359.c
index ac69c23e0da1..6ebcc9497ea0 100644
--- a/sound/soc/mediatek/mt8188/mt8188-mt6359.c
+++ b/sound/soc/mediatek/mt8188/mt8188-mt6359.c
@@ -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
-- 
2.35.3


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 11/11] ALSA: ac97: Simplify with snd_ctl_find_id_mixer()
  2023-07-20  8:20 [PATCH 00/11] ALSA: Cleanup with snd_ctl_find_id_mixer() Takashi Iwai
                   ` (9 preceding siblings ...)
  2023-07-20  8:21 ` [PATCH 10/11] ASoC: mediatek: mt8188: " Takashi Iwai
@ 2023-07-20  8:21 ` Takashi Iwai
  10 siblings, 0 replies; 13+ messages in thread
From: Takashi Iwai @ 2023-07-20  8:21 UTC (permalink / raw)
  To: alsa-devel; +Cc: Takashi Iwai

Replace an open code with the new snd_ctl_find_id_mixer().
There is no functional change.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
 sound/pci/ac97/ac97_patch.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/sound/pci/ac97/ac97_patch.c b/sound/pci/ac97/ac97_patch.c
index 4b5f33de70d5..ccfd9c7bf900 100644
--- a/sound/pci/ac97/ac97_patch.c
+++ b/sound/pci/ac97/ac97_patch.c
@@ -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 */
-- 
2.35.3


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: [PATCH 10/11] ASoC: mediatek: mt8188: Simplify with snd_ctl_find_id_mixer()
  2023-07-20  8:21 ` [PATCH 10/11] ASoC: mediatek: mt8188: " Takashi Iwai
@ 2023-07-20 13:02   ` Mark Brown
  0 siblings, 0 replies; 13+ messages in thread
From: Mark Brown @ 2023-07-20 13:02 UTC (permalink / raw)
  To: Takashi Iwai; +Cc: alsa-devel, Trevor Wu

[-- Attachment #1: Type: text/plain, Size: 199 bytes --]

On Thu, Jul 20, 2023 at 10:21:07AM +0200, Takashi Iwai wrote:
> Replace an open code with the new snd_ctl_find_id_mixer().
> There is no functional change.

Acked-by: Mark Brown <broonie@kernel.org>

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2023-07-20 13:03 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-07-20  8:20 [PATCH 00/11] ALSA: Cleanup with snd_ctl_find_id_mixer() Takashi Iwai
2023-07-20  8:20 ` [PATCH 01/11] ALSA: control: Introduce snd_ctl_find_id_mixer() Takashi Iwai
2023-07-20  8:20 ` [PATCH 02/11] ALSA: ca0106: Simplify with snd_ctl_find_id_mixer() Takashi Iwai
2023-07-20  8:21 ` [PATCH 03/11] ALSA: cs46xx: " Takashi Iwai
2023-07-20  8:21 ` [PATCH 04/11] ALSA: emu10k1: " Takashi Iwai
2023-07-20  8:21 ` [PATCH 05/11] ALSA: es1968: " Takashi Iwai
2023-07-20  8:21 ` [PATCH 06/11] ALSA: ice1712: " Takashi Iwai
2023-07-20  8:21 ` [PATCH 07/11] ALSA: maestro3: " Takashi Iwai
2023-07-20  8:21 ` [PATCH 08/11] ALSA: via82xx: " Takashi Iwai
2023-07-20  8:21 ` [PATCH 09/11] ALSA: cmipci: " Takashi Iwai
2023-07-20  8:21 ` [PATCH 10/11] ASoC: mediatek: mt8188: " Takashi Iwai
2023-07-20 13:02   ` Mark Brown
2023-07-20  8:21 ` [PATCH 11/11] ALSA: ac97: " Takashi Iwai

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox