[PATCH] ALSA: pcmtest: Reject invalid fill_mode values

From: HyeongJun An

Date: Sun Oct 25 2026 - 23:17:14 EST


The fill_block() function handles only fill_mode 0 (random) and 1
(pattern). With any other value it writes nothing and does not move the
buffer position. A capture stream then gets no data, and a read fails
with -EIO after the timeout. Nothing in the kernel log says why.

Check the value in a set callback, so a bad value is rejected both when
the module is loaded and when the parameter is written.

Fixes: 315a3d57c64c ("ALSA: Implement the new Virtual PCM Test Driver")
Assisted-by: Claude:claude-opus-5-5
Signed-off-by: HyeongJun An <sammiee5311@xxxxxxxxx>
---
sound/drivers/pcmtest.c | 21 ++++++++++++++++++++-
1 file changed, 20 insertions(+), 1 deletion(-)

diff --git a/sound/drivers/pcmtest.c b/sound/drivers/pcmtest.c
index d1b0dff56cd9..422fdb10f237 100644
--- a/sound/drivers/pcmtest.c
+++ b/sound/drivers/pcmtest.c
@@ -72,13 +72,32 @@ static u8 playback_capture_test;
static u8 ioctl_reset_test;
static struct dentry *driver_debug_dir;

+static int fill_mode_set(const char *val, const struct kernel_param *kp)
+{
+ short mode;
+ int err;
+
+ err = kstrtos16(val, 0, &mode);
+ if (err)
+ return err;
+ if (mode != FILL_MODE_RAND && mode != FILL_MODE_PAT)
+ return -EINVAL;
+ fill_mode = mode;
+ return 0;
+}
+
+static const struct kernel_param_ops fill_mode_ops = {
+ .set = fill_mode_set,
+ .get = param_get_short,
+};
+
module_param(index, int, 0444);
MODULE_PARM_DESC(index, "Index value for pcmtest soundcard");
module_param(id, charp, 0444);
MODULE_PARM_DESC(id, "ID string for pcmtest soundcard");
module_param(enable, bool, 0444);
MODULE_PARM_DESC(enable, "Enable pcmtest soundcard.");
-module_param(fill_mode, short, 0600);
+module_param_cb(fill_mode, &fill_mode_ops, &fill_mode, 0600);
MODULE_PARM_DESC(fill_mode, "Buffer fill mode: rand(0) or pattern(1)");
module_param(inject_delay, int, 0600);
MODULE_PARM_DESC(inject_delay, "Inject delays during playback/capture (in jiffies)");
--
2.43.0