[PATCH 3/5] block: blk-sysfs: reject out-of-range nomerges values

From: shao.mingyin

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


From: Shao Mingyin <shao.mingyin@xxxxxxxxxx>

queue_nomerges_store() accepts any value: 0 and 1 clear or set
QUEUE_FLAG_NOXMERGES, 2 sets QUEUE_FLAG_NOMERGES, and every other value
is treated like 1. The attribute documents only 0, 1 and 2, so a typo
such as 3 silently changes the merge policy and reads back as 1.

Reject values above 2.

Fixes: 488991e28e55 ("block: Added in stricter no merge semantics for block I/O")
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 and enabled the "no merges except ..." mode:

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

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

diff --git a/block/blk-sysfs.c b/block/blk-sysfs.c
index 520972676ab4..a66e572a489b 100644
--- a/block/blk-sysfs.c
+++ b/block/blk-sysfs.c
@@ -459,6 +459,9 @@ static ssize_t queue_nomerges_store(struct gendisk *disk, const char *page,
if (ret < 0)
return ret;

+ if (nm > 2)
+ return -EINVAL;
+
blk_queue_flag_clear(QUEUE_FLAG_NOMERGES, q);
blk_queue_flag_clear(QUEUE_FLAG_NOXMERGES, q);
if (nm == 2)
--
2.34.1