Alsa-Devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: "Geoffrey D. Bennett" <g@b4.vu>
To: Takashi Iwai <tiwai@suse.de>
Cc: Jaroslav Kysela <perex@perex.cz>, Takashi Iwai <tiwai@suse.com>,
	alsa-devel@alsa-project.org, linux-sound@vger.kernel.org
Subject: [PATCH 05/11] ALSA: scarlett2: Add clamp() in scarlett2_mixer_ctl_put()
Date: Wed, 20 Dec 2023 04:07:52 +1030	[thread overview]
Message-ID: <3b19fb3da641b587749b85fe1daa1b4e696c0c1b.1703001053.git.g@b4.vu> (raw)
In-Reply-To: <cover.1703001053.git.g@b4.vu>

Ensure the value passed to scarlett2_mixer_ctl_put() is between 0 and
SCARLETT2_MIXER_MAX_VALUE so we don't attempt to access outside
scarlett2_mixer_values[].

Signed-off-by: Geoffrey D. Bennett <g@b4.vu>
Fixes: 9e4d5c1be21f ("ALSA: usb-audio: Scarlett Gen 2 mixer interface")
---
 sound/usb/mixer_scarlett2.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/sound/usb/mixer_scarlett2.c b/sound/usb/mixer_scarlett2.c
index 373911937487..f1636a1614da 100644
--- a/sound/usb/mixer_scarlett2.c
+++ b/sound/usb/mixer_scarlett2.c
@@ -3663,7 +3663,8 @@ static int scarlett2_mixer_ctl_put(struct snd_kcontrol *kctl,
 	mutex_lock(&private->data_mutex);
 
 	oval = private->mix[index];
-	val = ucontrol->value.integer.value[0];
+	val = clamp(ucontrol->value.integer.value[0],
+		    0L, (long)SCARLETT2_MIXER_MAX_VALUE);
 	num_mixer_in = port_count[SCARLETT2_PORT_TYPE_MIX][SCARLETT2_PORT_OUT];
 	mix_num = index / num_mixer_in;
 
-- 
2.43.0


  parent reply	other threads:[~2023-12-19 17:39 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-19 17:36 [PATCH 00/11] ALSA: scarlett2: Firmware Upgrade and Error Handling Improvements Geoffrey D. Bennett
2023-12-19 17:36 ` [PATCH 01/11] ALSA: scarlett2: Update maintainer info Geoffrey D. Bennett
2023-12-19 17:37 ` [PATCH 02/11] ALSA: scarlett2: Add missing error check to scarlett2_config_save() Geoffrey D. Bennett
2023-12-19 17:37 ` [PATCH 03/11] ALSA: scarlett2: Add missing error check to scarlett2_usb_set_config() Geoffrey D. Bennett
2023-12-19 17:37 ` [PATCH 04/11] ALSA: scarlett2: Add missing error checks to *_ctl_get() Geoffrey D. Bennett
2023-12-19 17:37 ` Geoffrey D. Bennett [this message]
2023-12-19 17:38 ` [PATCH 06/11] ALSA: scarlett2: Add missing mutex lock around get meter levels Geoffrey D. Bennett
2023-12-19 17:38 ` [PATCH 07/11] ALSA: scarlett2: Add #defines for firmware upgrade Geoffrey D. Bennett
2023-12-19 17:38 ` [PATCH 08/11] ALSA: scarlett2: Retrieve useful flash segment numbers Geoffrey D. Bennett
2023-12-19 17:39 ` [PATCH 09/11] ALSA: scarlett2: Add skeleton hwdep/ioctl interface Geoffrey D. Bennett
2023-12-19 17:50 ` [PATCH 10/11] ALSA: scarlett2: Add ioctl commands to erase flash segments Geoffrey D. Bennett
2023-12-19 17:50 ` [PATCH 11/11] ALSA: scarlett2: Add support for uploading new firmware Geoffrey D. Bennett
2023-12-29 12:19   ` [PATCH v2 " Geoffrey D. Bennett
2023-12-29 15:08 ` [PATCH 00/11] ALSA: scarlett2: Firmware Upgrade and Error Handling Improvements Takashi Iwai

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=3b19fb3da641b587749b85fe1daa1b4e696c0c1b.1703001053.git.g@b4.vu \
    --to=g@b4.vu \
    --cc=alsa-devel@alsa-project.org \
    --cc=linux-sound@vger.kernel.org \
    --cc=perex@perex.cz \
    --cc=tiwai@suse.com \
    --cc=tiwai@suse.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