]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
ALSA: hda: Add input value sanity checks to HDMI channel map controls
authorTakashi Iwai <tiwai@suse.de>
Sun, 16 Jun 2024 07:34:47 +0000 (09:34 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 12 Sep 2024 09:06:45 +0000 (11:06 +0200)
[ Upstream commit 6278056e42d953e207e2afd416be39d09ed2d496 ]

Add a simple sanity check to HD-audio HDMI Channel Map controls.
Although the value might not be accepted for the actual connection, we
can filter out some bogus values beforehand, and that should be enough
for making kselftest happier.

Reviewed-by: Jaroslav Kysela <perex@perex.cz>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Link: https://lore.kernel.org/20240616073454.16512-7-tiwai@suse.de
Signed-off-by: Sasha Levin <sashal@kernel.org>
sound/hda/hdmi_chmap.c

index aad5c4bf4d3441754b0ec1d5d046b438b1ee6c5e..0ebf4d90785222b75ba4088556abfd01d6fa66a3 100644 (file)
@@ -753,6 +753,20 @@ static int hdmi_chmap_ctl_get(struct snd_kcontrol *kcontrol,
        return 0;
 }
 
+/* a simple sanity check for input values to chmap kcontrol */
+static int chmap_value_check(struct hdac_chmap *hchmap,
+                            const struct snd_ctl_elem_value *ucontrol)
+{
+       int i;
+
+       for (i = 0; i < hchmap->channels_max; i++) {
+               if (ucontrol->value.integer.value[i] < 0 ||
+                   ucontrol->value.integer.value[i] > SNDRV_CHMAP_LAST)
+                       return -EINVAL;
+       }
+       return 0;
+}
+
 static int hdmi_chmap_ctl_put(struct snd_kcontrol *kcontrol,
                              struct snd_ctl_elem_value *ucontrol)
 {
@@ -764,6 +778,10 @@ static int hdmi_chmap_ctl_put(struct snd_kcontrol *kcontrol,
        unsigned char chmap[8], per_pin_chmap[8];
        int i, err, ca, prepared = 0;
 
+       err = chmap_value_check(hchmap, ucontrol);
+       if (err < 0)
+               return err;
+
        /* No monitor is connected in dyn_pcm_assign.
         * It's invalid to setup the chmap
         */