Right now we don't check for valid module parameter value for max_sectors, that allows user to set negative values. Add a callback to error out when max_sectors value is set < 1 before module is loaded. Signed-off-by: Chaitanya Kulkarni <kch@xxxxxxxxxx> --- drivers/block/null_blk/main.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/drivers/block/null_blk/main.c b/drivers/block/null_blk/main.c index 7cfc1eaa5e3c..1b9fa5af02d5 100644 --- a/drivers/block/null_blk/main.c +++ b/drivers/block/null_blk/main.c @@ -195,7 +195,18 @@ device_param_cb(bs, &null_bs_param_ops, &g_bs, 0444); MODULE_PARM_DESC(bs, "Block size (in bytes)"); static int g_max_sectors; -module_param_named(max_sectors, g_max_sectors, int, 0444); + +static int null_set_max_sects(const char *s, const struct kernel_param *p) +{ + return null_param_store_val(s, &g_max_sectors, 1, INT_MAX); +} + +static const struct kernel_param_ops null_max_sects_param_ops = { + .set = null_set_max_sects, + .get = param_get_int, +}; + +device_param_cb(max_sectors, &null_max_sects_param_ops, &g_max_sectors, 0444); MODULE_PARM_DESC(max_sectors, "Maximum size of a command (in 512B sectors)"); static unsigned int nr_devices = 1; -- 2.29.0