Skip to contentSkip to conversation

ALSA: Fix kctl->id initialization

PATCH In review Takashi Iwai 2 participants 6 messages Jun 6, 2023 Sound

lore
Share & tools
lore
#0 lore raw

cover ALSA: Fix kctl->id initialization

Inspired by the recent Jaroslav's fix patch, I skimmed over the tree and found that there are a few other similar bugs. Here is a patch set to address them. Most of them are just shuffling the call order, while the one in HD-audio is changed to use snd_ctl_replace_id() helper.

Takashi

===

Takashi Iwai (4):
ALSA: ymfpci: Fix kctl->id initialization
ALSA: cmipci: Fix kctl->id initialization
ALSA: gus: Fix kctl->id initialization
ALSA: hda: Fix kctl->id initialization

 sound/isa/gus/gus_pcm.c        | 2 +-
 sound/pci/cmipci.c             | 6 +++---
 sound/pci/hda/hda_codec.c      | 6 +++++-
 sound/pci/ymfpci/ymfpci_main.c | 6 +++---
 4 files changed, 12 insertions(+), 8 deletions(-)
Signature · 1 line
2.35.3
#1 lore raw

PATCH 1/4 ALSA: ymfpci: Fix kctl->id initialization

ymfpci driver replaces the kctl->id.device after assigning the kctl via snd_ctl_add(). This doesn't work any longer with the new Xarray lookup change. It has to be set before snd_ctl_add() call instead.

Fixes c27e1efb61c5 ("ALSA: control: Use xarray for faster lookups")
---
 sound/pci/ymfpci/ymfpci_main.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
sound/pci/ymfpci/ymfpci_main.c +3 -3
index 6971eec45a4d..6b8d8690b6b2 100644
@@ -1822,20 +1822,20 @@ int snd_ymfpci_mixer(struct snd_ymfpci *chip, int rear_switch)
 	if (snd_BUG_ON(!chip->pcm_spdif))
 		return -ENXIO;
 	kctl = snd_ctl_new1(&snd_ymfpci_spdif_default, chip);
+	kctl->id.device = chip->pcm_spdif->device;
 	err = snd_ctl_add(chip->card, kctl);
 	if (err < 0)
 		return err;
-	kctl->id.device = chip->pcm_spdif->device;
 	kctl = snd_ctl_new1(&snd_ymfpci_spdif_mask, chip);
+	kctl->id.device = chip->pcm_spdif->device;
 	err = snd_ctl_add(chip->card, kctl);
 	if (err < 0)
 		return err;
-	kctl->id.device = chip->pcm_spdif->device;
 	kctl = snd_ctl_new1(&snd_ymfpci_spdif_stream, chip);
+	kctl->id.device = chip->pcm_spdif->device;
 	err = snd_ctl_add(chip->card, kctl);
 	if (err < 0)
 		return err;
-	kctl->id.device = chip->pcm_spdif->device;
 	chip->spdif_pcm_ctl = kctl;
 
 	/* direct recording source */
Signature · 1 line
2.35.3
#2 lore raw

PATCH 2/4 ALSA: cmipci: Fix kctl->id initialization

In reply to Takashi Iwai

cmipci driver replaces the kctl->id.device after assigning the kctl via snd_ctl_add(). This doesn't work any longer with the new Xarray lookup change. It has to be set before snd_ctl_add() call instead.

Fixes c27e1efb61c5 ("ALSA: control: Use xarray for faster lookups")
---
 sound/pci/cmipci.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
sound/pci/cmipci.c +3 -3
index 727db6d43391..6d25c12d9ef0 100644
@@ -2688,20 +2688,20 @@ static int snd_cmipci_mixer_new(struct cmipci *cm, int pcm_spdif_device)
 		}
 		if (cm->can_ac3_hw) {
 			kctl = snd_ctl_new1(&snd_cmipci_spdif_default, cm);
+			kctl->id.device = pcm_spdif_device;
 			err = snd_ctl_add(card, kctl);
 			if (err < 0)
 				return err;
-			kctl->id.device = pcm_spdif_device;
 			kctl = snd_ctl_new1(&snd_cmipci_spdif_mask, cm);
+			kctl->id.device = pcm_spdif_device;
 			err = snd_ctl_add(card, kctl);
 			if (err < 0)
 				return err;
-			kctl->id.device = pcm_spdif_device;
 			kctl = snd_ctl_new1(&snd_cmipci_spdif_stream, cm);
+			kctl->id.device = pcm_spdif_device;
 			err = snd_ctl_add(card, kctl);
 			if (err < 0)
 				return err;
-			kctl->id.device = pcm_spdif_device;
 		}
 		if (cm->chip_version <= 37) {
 			sw = snd_cmipci_old_mixer_switches;
Signature · 1 line
2.35.3
#3 lore raw

PATCH 3/4 ALSA: gus: Fix kctl->id initialization

In reply to Takashi Iwai

GUS driver replaces the kctl->id.index after assigning the kctl via snd_ctl_add(). This doesn't work any longer with the new Xarray lookup change. It has to be set before snd_ctl_add() call instead.

Fixes c27e1efb61c5 ("ALSA: control: Use xarray for faster lookups")
---
 sound/isa/gus/gus_pcm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
sound/isa/gus/gus_pcm.c +1 -1
index 230f65a0e4b0..388db5fb65bd 100644
@@ -892,10 +892,10 @@ int snd_gf1_pcm_new(struct snd_gus_card *gus, int pcm_dev, int control_index)
 		kctl = snd_ctl_new1(&snd_gf1_pcm_volume_control1, gus);
 	else
 		kctl = snd_ctl_new1(&snd_gf1_pcm_volume_control, gus);
+	kctl->id.index = control_index;
 	err = snd_ctl_add(card, kctl);
 	if (err < 0)
 		return err;
-	kctl->id.index = control_index;
 
 	return 0;
 }
Signature · 1 line
2.35.3
#4 lore raw

PATCH 4/4 ALSA: hda: Fix kctl->id initialization

In reply to Takashi Iwai

HD-audio core code replaces the kctl->id.index of SPDIF-related controls after assigning via snd_ctl_add(). This doesn't work any longer with the new Xarray lookup change. The change of the kctl->id content has to be done via snd_ctl_rename_id() helper, instead.

Fixes c27e1efb61c5 ("ALSA: control: Use xarray for faster lookups")
---
 sound/pci/hda/hda_codec.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
sound/pci/hda/hda_codec.c +5 -1
index 9f79c0ac2bda..bd19f92aeeec 100644
@@ -2458,10 +2458,14 @@ int snd_hda_create_dig_out_ctls(struct hda_codec *codec,
 		   type == HDA_PCM_TYPE_HDMI) {
 		/* suppose a single SPDIF device */
 		for (dig_mix = dig_mixes; dig_mix->name; dig_mix++) {
+			struct snd_ctl_elem_id id;
+
 			kctl = find_mixer_ctl(codec, dig_mix->name, 0, 0);
 			if (!kctl)
 				break;
-			kctl->id.index = spdif_index;
+			id = kctl->id;
+			id.index = spdif_index;
+			snd_ctl_rename_id(codec->card, &kctl->id, &id);
 		}
 		bus->primary_dig_out_type = HDA_PCM_TYPE_HDMI;
 	}
Signature · 1 line
2.35.3
maintainer Reviewed-by on the v1 series
#5 lore raw
In reply to Takashi Iwai
Quoted 5 lines · Takashi Iwai

Inspired by the recent Jaroslav's fix patch, I skimmed over the tree and found that there are a few other similar bugs. Here is a patch set to address them. Most of them are just shuffling the call order, while the one in HD-audio is changed to use snd_ctl_replace_id() helper.

For all patches in the set:

Thanks. I planned to check the other code today later, but you're really fast.

Signature · 2 lines
Jaroslav Kysela <[email protected]>
Linux Sound Maintainer; ALSA Project; Red Hat, Inc.