diff mbox series

[V2,4/9] null_blk: check for valid gb value

Message ID 20230330213134.131298-5-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 gb, that
allows user to set negative values.

Add a callback to error out when gb 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 29bc4b5720c1..f55d88ebd7e6 100644
--- a/drivers/block/null_blk/main.c
+++ b/drivers/block/null_blk/main.c
@@ -171,8 +171,23 @@  static const struct kernel_param_ops null_queue_mode_param_ops = {
 device_param_cb(queue_mode, &null_queue_mode_param_ops, &g_queue_mode, 0444);
 MODULE_PARM_DESC(queue_mode, "Block interface to use (0=bio,1=rq,2=multiqueue)");
 
+static int null_set_gb(const char *s, const struct kernel_param *kp)
+{
+	int ret;
+
+	ret = null_param_store_int(s, kp->arg, NULL_Q_BIO, NULL_Q_MQ);
+	if (ret)
+		pr_err("only positive values are allowed for gb\n");
+	return ret;
+}
+
+static const struct kernel_param_ops null_gb_param_ops = {
+	.set	= null_set_gb,
+	.get	= param_get_int,
+};
+
 static int g_gb = 250;
-module_param_named(gb, g_gb, int, 0444);
+device_param_cb(gb, &null_gb_param_ops, &g_gb, 0444);
 MODULE_PARM_DESC(gb, "Size in GB");
 
 static int g_bs = 512;