Skip to contentSkip to conversation

ALSA: hda - Fix incorrect TLV callback check

PATCH In review Takashi Iwai 2 participants 4 messages Oct 17, 2017 – Oct 18, 2017 Sound

lore
Share & tools
lore
#0 lore raw

v2 cover ALSA: hda - Fix incorrect TLV callback check

Hi,

this is a revised patchset for addressing the incorrect TLV callback check introduced by a set_fs() removal commit. A fix for a superfluous '-' in the code is split as another fix so that it can be applied to older kernels without the rest. Other than that, only the changelog text updates since the older patch (that was embedded in the mail thread "4.13 regression: get_kctl_0dB_offset doesn't handle all possible callbacks").

thanks,

Takashi

===

Takashi Iwai (2):
ALSA: hda: Remove superfluous '-' added by printk conversion
ALSA: hda - Fix incorrect TLV callback check introduced during
set_fs() removal

 include/sound/control.h   |  3 ++
 sound/core/vmaster.c      | 31 +++++++++++++++
 sound/pci/hda/hda_codec.c | 97 +++++++++++++++++++++++++++--------------------
 3 files changed, 89 insertions(+), 42 deletions(-)
Signature · 1 line
2.14.2
#1 lore raw

PATCH v2 1/2 ALSA: hda: Remove superfluous '-' added by printk conversion

While converting the error messages to the standard macros in the commit 4e76a8833fac ("ALSA: hda - Replace with standard printk"), a superfluous '-' slipped in the code mistakenly. Its influence is almost negligible, merely shows a dB value as negative integer instead of positive integer (or vice versa) in the rare error message. So let's kill this embarrassing byte to show more correct value.

Fixes 4e76a8833fac ("ALSA: hda - Replace with standard printk")
---
 sound/pci/hda/hda_codec.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
sound/pci/hda/hda_codec.c +1 -1
index 3db26c451837..b6cf9684c2ec 100644
@@ -1824,7 +1824,7 @@ static int get_kctl_0dB_offset(struct hda_codec *codec,
 			return -1;
 		if (*step_to_check && *step_to_check != step) {
 			codec_err(codec, "Mismatching dB step for vmaster slave (%d!=%d)\n",
--				   *step_to_check, step);
+				   *step_to_check, step);
 			return -1;
 		}
 		*step_to_check = step;
Signature · 1 line
2.14.2
#2 lore raw

PATCH v2 2/2 ALSA: hda - Fix incorrect TLV callback check introduced during set_fs() removal

In reply to Takashi Iwai

The commit 99b5c5bb9a54 ("ALSA: hda - Remove the use of set_fs()") converted the get_kctl_0dB_offset() call for killing set_fs() usage in HD-audio codec code. The conversion assumed that the TLV callback used in HD-audio code is only snd_hda_mixer_amp() and applies the TLV calculation locally.

Although this assumption is correct, and all slave kctls are actually with that callback, the current code is still utterly buggy; it doesn't hit this condition and falls back to the next check. It's because the function gets called after adding slave kctls to vmaster. By assigning a slave kctl, the slave kctl object is faked inside vmaster code, and the whole kctl ops are overridden. Thus the callback op points to a different value from what we've assumed.

More badly, as reported by the KERNEXEC and UDEREF features of PaX, the code flow turns into the unexpected pitfall. The next fallback check is SNDRV_CTL_ELEM_ACCESS_TLV_READ access bit, and this always hits for each kctl with TLV. Then it evaluates the callback function pointer wrongly as if it were a TLV array. Although currently its side-effect is fairly limited, this incorrect reference may lead to an unpleasant result.

For addressing the regression, this patch introduces a new helper to vmaster code, snd_ctl_apply_vmaster_slaves(). This works similarly like the existing map_slaves() in hda_codec.c: it loops over the slave list of the given master, and applies the given function to each slave. Then the initializer function receives the right kctl object and we can compare the correct pointer instead of the faked one.

Also, for catching the similar breakage in future, give an error message when the unexpected TLV callback is found and bail out immediately.

Fixes 99b5c5bb9a54 ("ALSA: hda - Remove the use of set_fs()")
Cc <[email protected]> # v4.13
---
 include/sound/control.h   |  3 ++
 sound/core/vmaster.c      | 31 +++++++++++++++
 sound/pci/hda/hda_codec.c | 97 +++++++++++++++++++++++++++--------------------
 3 files changed, 89 insertions(+), 42 deletions(-)
include/sound/control.h +3 -0
index bd7246de58e7..a1f1152bc687 100644
@@ -248,6 +248,9 @@ int snd_ctl_add_vmaster_hook(struct snd_kcontrol *kctl,
 			     void *private_data);
 void snd_ctl_sync_vmaster(struct snd_kcontrol *kctl, bool hook_only);
 #define snd_ctl_sync_vmaster_hook(kctl)	snd_ctl_sync_vmaster(kctl, true)
+int snd_ctl_apply_vmaster_slaves(struct snd_kcontrol *kctl,
+				 int (*func)(struct snd_kcontrol *, void *),
+				 void *arg);
 
 /*
  * Helper functions for jack-detection controls
sound/core/vmaster.c +31 -0
index 6c58e6f73a01..e43af18d4383 100644
@@ -484,3 +484,34 @@ void snd_ctl_sync_vmaster(struct snd_kcontrol *kcontrol, bool hook_only)
 		master->hook(master->hook_private_data, master->val);
 }
 EXPORT_SYMBOL_GPL(snd_ctl_sync_vmaster);
+
+/**
+ * snd_ctl_apply_vmaster_slaves - Apply function to each vmaster slave
+ * @kctl: vmaster kctl element
+ * @func: function to apply
+ * @arg: optional function argument
+ *
+ * Apply the function @func to each slave kctl of the given vmaster kctl.
+ * Returns 0 if successful, or a negative error code.
+ */
+int snd_ctl_apply_vmaster_slaves(struct snd_kcontrol *kctl,
+				 int (*func)(struct snd_kcontrol *, void *),
+				 void *arg)
+{
+	struct link_master *master;
+	struct link_slave *slave;
+	int err;
+
+	master = snd_kcontrol_chip(kctl);
+	err = master_init(master);
+	if (err < 0)
+		return err;
+	list_for_each_entry(slave, &master->slaves, list) {
+		err = func(&slave->slave, arg);
+		if (err < 0)
+			return err;
+	}
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(snd_ctl_apply_vmaster_slaves);
sound/pci/hda/hda_codec.c +55 -42

119 lines not on this page · raw message

Signature · 1 line
2.14.2
#3 lore raw

Re: [PATCH v2 2/2] ALSA: hda - Fix incorrect TLV callback check introduced during set_fs() removal

Quoted 2 lines · Takashi Iwai
Fixes 99b5c5bb9a54 ("ALSA: hda - Remove the use of set_fs()")

thanks, you can also add Tested-by: PaX Team <[email protected]>.