Commit f7c4ce89 authored by André Almeida's avatar André Almeida Committed by Jens Axboe

null_blk: validate the number of devices

A negative number of devices is nonsensical, so change the type to
unsigned. If the number of devices is 0, it is impossible for userspace
to interact with the module, so refuse loading the driver for that case.
Signed-off-by: default avatarAndré Almeida <andrealmeid@collabora.com>
Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent 4e47ee8f
...@@ -141,7 +141,7 @@ static int g_bs = 512; ...@@ -141,7 +141,7 @@ static int g_bs = 512;
module_param_named(bs, g_bs, int, 0444); module_param_named(bs, g_bs, int, 0444);
MODULE_PARM_DESC(bs, "Block size (in bytes)"); MODULE_PARM_DESC(bs, "Block size (in bytes)");
static int nr_devices = 1; static unsigned int nr_devices = 1;
module_param(nr_devices, int, 0444); module_param(nr_devices, int, 0444);
MODULE_PARM_DESC(nr_devices, "Number of devices to register"); MODULE_PARM_DESC(nr_devices, "Number of devices to register");
...@@ -1767,6 +1767,10 @@ static int __init null_init(void) ...@@ -1767,6 +1767,10 @@ static int __init null_init(void)
pr_err("null_blk: legacy IO path no longer available\n"); pr_err("null_blk: legacy IO path no longer available\n");
return -EINVAL; return -EINVAL;
} }
if (!nr_devices) {
pr_err("null_blk: invalid number of devices\n");
return -EINVAL;
}
if (g_queue_mode == NULL_Q_MQ && g_use_per_node_hctx) { if (g_queue_mode == NULL_Q_MQ && g_use_per_node_hctx) {
if (g_submit_queues != nr_online_nodes) { if (g_submit_queues != nr_online_nodes) {
pr_warn("null_blk: submit_queues param is set to %u.\n", pr_warn("null_blk: submit_queues param is set to %u.\n",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment