diff mbox series

[V2,8/9] null_blk: avoid use global modparam g_queue_mode

Message ID 20230330213134.131298-9-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
The reference to module parameter is already present in the
struct kernel_param dp->arg include/linux/moduleparam.h :-

device_param_cb(name, ops, arg, perm)
 level_param_cb(name, ops, arg, perm, level)
   __module_param_call(prefix, name, ops, arg, perm, level, flags)
288         /* Default value instead of permissions? */                     \
289         static const char __param_str_##name[] = prefix #name;          \
290         static struct kernel_param __moduleparam_const __param_##name   \
291         __used __section("__param")                                     \
292         __aligned(__alignof__(struct kernel_param))                     \
293         = { __param_str_##name, THIS_MODULE, ops,                       \
294             VERIFY_OCTAL_PERMISSIONS(perm), level, flags, { arg } }

Replace global reference to the g_queue_mode in null_set_queue_mode()
with the function parameter kp-arg and rearrage code that matches
nicely with this patch series.

Also, use this opportunity to print the error message with valid range.

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

Patch

diff --git a/drivers/block/null_blk/main.c b/drivers/block/null_blk/main.c
index 96ced0485e35..5325ec57287d 100644
--- a/drivers/block/null_blk/main.c
+++ b/drivers/block/null_blk/main.c
@@ -156,11 +156,15 @@  module_param_string(init_hctx, g_init_hctx_str, sizeof(g_init_hctx_str), 0444);
 MODULE_PARM_DESC(init_hctx, "Fault injection to fail hctx init. init_hctx=<interval>,<probability>,<space>,<times>");
 #endif
 
-static int g_queue_mode = NULL_Q_MQ;
-
 static int null_set_queue_mode(const char *str, const struct kernel_param *kp)
 {
-	return null_param_store_int(str, &g_queue_mode, NULL_Q_BIO, NULL_Q_MQ);
+	int ret;
+
+	ret = null_param_store_int(str, kp->arg, NULL_Q_BIO, NULL_Q_MQ);
+	if (ret)
+		pr_err("queue_mode valid values BIO: %u, MQ: %u\n",
+		       NULL_Q_BIO, NULL_Q_MQ);
+	return ret;
 }
 
 static const struct kernel_param_ops null_queue_mode_param_ops = {
@@ -168,6 +172,7 @@  static const struct kernel_param_ops null_queue_mode_param_ops = {
 	.get	= param_get_int,
 };
 
+static int g_queue_mode = NULL_Q_MQ;
 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)");