blk-mq: check invalid nr_requests in queue_requests_store()
authorYu Kuai <yukuai3@huawei.com>
Wed, 10 Sep 2025 08:04:38 +0000 (16:04 +0800)
committerJens Axboe <axboe@kernel.dk>
Wed, 10 Sep 2025 11:25:56 +0000 (05:25 -0600)
commitb46d4c447db76e36906ed59ebb9b3ef8f3383322
treec8afeeba4bbed2ccb7b12025575b89d109ae4bd0
parent8bd7195fea6d9662aa3b32498a3828bfd9b63185
blk-mq: check invalid nr_requests in queue_requests_store()

queue_requests_store() is the only caller of
blk_mq_update_nr_requests(), and blk_mq_update_nr_requests() is the
only caller of blk_mq_tag_update_depth(), however, they all have
checkings for nr_requests input by user.

Make code cleaner by moving all the checkings to the top function:

1) nr_requests > reserved tags;
2) if there is elevator, 4 <= nr_requests <= 2048;
3) if elevator is none, 4 <= nr_requests <= tag_set->queue_depth;

Meanwhile, case 2 is the only case tags can grow and -ENOMEM might be
returned.

Signed-off-by: Yu Kuai <yukuai3@huawei.com>
Reviewed-by: Nilay Shroff <nilay@linux.ibm.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
block/blk-mq-tag.c
block/blk-mq.c
block/blk-mq.h
block/blk-sysfs.c