[PATCH 4/5] block: blk-sysfs: reject invalid rq_affinity values

From: shao.mingyin

Date: Thu Dec 03 2026 - 09:17:33 EST


From: Shao Mingyin <shao.mingyin@xxxxxxxxxx>

On SMP, queue_rq_affinity_store() accepts any value: 0, 1 and 2 update
QUEUE_FLAG_SAME_COMP and QUEUE_FLAG_SAME_FORCE, and every other value
is silently ignored while the write reports success. The attribute
documents only 0, 1 and 2.

Return -EINVAL for other values so that a wrong setting is not silently
dropped.

Fixes: e8037d498354 ("block: Fix queue_flag update when rq_affinity goes from 2 to 1")
Signed-off-by: Shao Mingyin <shao.mingyin@xxxxxxxxxx>
---
Tested on 7.4.0-rc5-next-20261130 (QEMU/TCG guest) with a null_blk
device created through configfs.

Writing 3 was accepted without changing the flags:

unpatched patched
write of 3 accepted, reads back 1 write of 3 rejected (-EINVAL)

block/blk-sysfs.c | 2 ++
1 file changed, 2 insertions(+)

diff --git a/block/blk-sysfs.c b/block/blk-sysfs.c
index a66e572a489b..22a536c9c77e 100644
--- a/block/blk-sysfs.c
+++ b/block/blk-sysfs.c
@@ -507,6 +507,8 @@ queue_rq_affinity_store(struct gendisk *disk, const char *page, size_t count)
} else if (val == 0) {
blk_queue_flag_clear(QUEUE_FLAG_SAME_COMP, q);
blk_queue_flag_clear(QUEUE_FLAG_SAME_FORCE, q);
+ } else {
+ return -EINVAL;
}
#endif
return ret;
--
2.34.1