Linux Sound subsystem development
 help / color / mirror / Atom feed
From: Takashi Iwai <tiwai@suse.de>
To: linux-sound@vger.kernel.org
Cc: Paul Menzel <pmenzel@molgen.mpg.de>,
	Mark Brown <broonie@kernel.org>, Jaroslav Kysela <perex@perex.cz>,
	linux-kselftest@vger.kernel.org
Subject: [PATCH v2 6/6] ALSA: hda: Add input value sanity checks to HDMI channel map controls
Date: Fri, 14 Jun 2024 17:37:15 +0200	[thread overview]
Message-ID: <20240614153717.30143-7-tiwai@suse.de> (raw)
In-Reply-To: <20240614153717.30143-1-tiwai@suse.de>

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.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
 sound/hda/hdmi_chmap.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/sound/hda/hdmi_chmap.c b/sound/hda/hdmi_chmap.c
index 5d8e1d944b0a..7b276047f85a 100644
--- a/sound/hda/hdmi_chmap.c
+++ b/sound/hda/hdmi_chmap.c
@@ -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
 	 */
-- 
2.43.0


  parent reply	other threads:[~2024-06-14 15:36 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-14 15:37 [PATCH v2 0/6] ALSA: some driver fixes for control input validations Takashi Iwai
2024-06-14 15:37 ` [PATCH v2 1/6] ALSA: vmaster: Return error for invalid input values Takashi Iwai
2024-06-14 15:37 ` [PATCH v2 2/6] ALSA: hda: Return -EINVAL for invalid volume/switch inputs Takashi Iwai
2024-06-14 15:37 ` [PATCH v2 3/6] ALSA: control: Apply sanity check of input values for user elements Takashi Iwai
2024-06-15  5:13   ` Takashi Sakamoto
2024-06-15  7:28     ` Takashi Iwai
2024-06-15  8:02       ` Takashi Sakamoto
2024-06-15  8:30         ` Takashi Iwai
2024-06-15 11:37           ` Takashi Iwai
2024-06-16  3:39             ` Takashi Sakamoto
2024-06-14 15:37 ` [PATCH v2 4/6] kselftest/alsa: mixer-test: Skip write verification for volatile controls Takashi Iwai
2024-06-14 15:43   ` Jaroslav Kysela
2024-06-14 15:57   ` Mark Brown
2024-06-14 16:08     ` Takashi Iwai
2024-06-14 16:28       ` Mark Brown
2024-06-14 15:37 ` [PATCH v2 5/6] ALSA: chmap: Mark Channel Map controls as volatile Takashi Iwai
2024-06-14 15:37 ` Takashi Iwai [this message]
2024-06-14 15:44   ` [PATCH v2 6/6] ALSA: hda: Add input value sanity checks to HDMI channel map controls Jaroslav Kysela

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240614153717.30143-7-tiwai@suse.de \
    --to=tiwai@suse.de \
    --cc=broonie@kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux-sound@vger.kernel.org \
    --cc=perex@perex.cz \
    --cc=pmenzel@molgen.mpg.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox