diff mbox series

[V2,6/9] null_blk: check for valid max_sectors value

Message ID 20230330213134.131298-7-kch@nvidia.com (mailing list archive)
State New, archived
Headers show
Series null_blk: add modparam checks | expand

Commit Message

Chaitanya Kulkarni March 30, 2023, 9:31 p.m. UTC
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@nvidia.com>
---
 drivers/block/null_blk/main.c | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/drivers/block/null_blk/main.c b/drivers/block/null_blk/main.c
index d8d79c66a7aa..c13f0f2b8d86 100644
--- a/drivers/block/null_blk/main.c
+++ b/drivers/block/null_blk/main.c
@@ -209,8 +209,23 @@  static int g_bs = 512;
 device_param_cb(bs, &null_bs_param_ops, &g_bs, 0444);
 MODULE_PARM_DESC(bs, "Block size (in bytes)");
 
+static int null_set_max_sects(const char *s, const struct kernel_param *kp)
+{
+	int ret;
+
+	ret = null_param_store_int(s, kp->arg, 1, INT_MAX);
+	if (ret)
+		pr_err("only positive values are allowed for max_sectors\n");
+	return ret;
+}
+
+static const struct kernel_param_ops null_max_sects_param_ops = {
+	.set	= null_set_max_sects,
+	.get	= param_get_int,
+};
+
 static int g_max_sectors;
-module_param_named(max_sectors, g_max_sectors, int, 0444);
+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;