[RFC V2 PATCH 07/11] ALSA: mixer_audient: Add integer range checks

From: Christian Ruppert

Date: Sun Nov 01 2026 - 19:34:23 EST


Add range checks to integer parameters to improve error management:
- Reject out-of-range write attempts with -EINVAL
- Prune out-of-range values returned by the device to the range limits

Signed-off-by: Christian Ruppert <arc@xxxxxx>
---
sound/usb/mixer_audient.c | 17 +++++++++++++++--
1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/sound/usb/mixer_audient.c b/sound/usb/mixer_audient.c
index 4b20db9a82e2..433bb5479d8e 100644
--- a/sound/usb/mixer_audient.c
+++ b/sound/usb/mixer_audient.c
@@ -44,10 +44,10 @@ static const struct snd_audient_ctrl_type {
unsigned long flags;
size_t len; /* datatype size, can be 1, 2 or 4 bytes */
union {
- int integer;
+ long integer;
} min; /* for booleans holds physical int value for false */
union {
- int integer;
+ long integer;
} max; /* for booleans holds physical int value for true */
const unsigned int *tlv;
u8 unit;
@@ -425,6 +425,12 @@ static int snd_ctl_audient_integer_get(struct snd_kcontrol *kctl,
if (ret < 0)
return ret;

+ if (val < ctype->min.integer)
+ val = ctype->min.integer;
+
+ if (val > ctype->max.integer)
+ val = ctype->max.integer;
+
ctl_val->value.integer.value[i] = val;
}

@@ -448,6 +454,13 @@ static int snd_ctl_audient_integer_set(struct snd_kcontrol *kctl,
int changed = 0;
int i;

+ for (i = 0; i < hwchan; i++) {
+ long val = ctl_val->value.integer.value[i];
+
+ if ((val < ctype->min.integer) || (val > ctype->max.integer))
+ return -EINVAL;
+ }
+
CLASS(snd_usb_lock, pm)(mixer->chip);
if (pm.err < 0)
return pm.err;
--
2.56.0