diff mbox series

[4/6] null_blk: check for valid block size value

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

Commit Message

Chaitanya Kulkarni Oct. 7, 2022, 6:30 a.m. UTC
Right now we don't check for valid module parameter value for
block size, that allows user to set negative values.

Add a callback to error out when block size value is set < 1 before
module is loaded.

Signed-off-by: Chaitanya Kulkarni <kch@nvidia.com>
---
 drivers/block/null_blk/main.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/drivers/block/null_blk/main.c b/drivers/block/null_blk/main.c
index 83bf9065831a..7cfc1eaa5e3c 100644
--- a/drivers/block/null_blk/main.c
+++ b/drivers/block/null_blk/main.c
@@ -180,7 +180,18 @@  device_param_cb(gb, &null_gb_param_ops, &g_gb, 0444);
 MODULE_PARM_DESC(gb, "Size in GB");
 
 static int g_bs = 512;
-module_param_named(bs, g_bs, int, 0444);
+
+static int null_set_bs(const char *s, const struct kernel_param *p)
+{
+	return null_param_store_val(s, &g_bs, 512, INT_MAX);
+}
+
+static const struct kernel_param_ops null_bs_param_ops = {
+	.set	= null_set_bs,
+	.get	= param_get_int,
+};
+
+device_param_cb(bs, &null_bs_param_ops, &g_bs, 0444);
 MODULE_PARM_DESC(bs, "Block size (in bytes)");
 
 static int g_max_sectors;