staging: lustre: lnet: Constify kernel_param_ops structure
PATCH 1/1 staging: lustre: lnet: Constify kernel_param_ops structure
The structure is used as an argument to module_param macro. This macro calls a bunch of other macros and finally assigns the instance of the kernel_param_ops structure to the const struct kernel_param_ops* field of a variable of type kernel_param. Hence, const can be added to the structure.
Coccinelle Script:
@r disable optional_qualifier@
identifier i;
position p;
@@
static struct kernel_param_ops i@p = { ... };
@ok1@
identifier r.i;
expression e;
position p;
@@
e = i@p
@script:python s@
i << r.i;
t;
@@
coccinelle.t = i[10:];
@ok2@
declarer name module_param;
expression e1,e2;
position p;
@@module_param(e1,s.t@p,e2);
@bad@
position p != {r.p,ok1.p,ok2.p};
identifier r.i;
@@
e@i@p
@depends on !bad disable optional_qualifier@
identifier r.i;
@@
static
+const
struct kernel_param_ops i = { ... };
--- drivers/staging/lustre/lnet/libcfs/debug.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/staging/lustre/lnet/libcfs/debug.c +4 -4
@@ -80,7 +80,7 @@ static int libcfs_param_debug_mb_set(const char *val,* it needs quite a bunch of extra processing, so we define special * debugmb parameter type with corresponding methods to handle this case */ -static struct kernel_param_ops param_ops_debugmb = { +static const struct kernel_param_ops param_ops_debugmb = { .set = libcfs_param_debug_mb_set, .get = param_get_uint, };
@@ -138,7 +138,7 @@ static int param_set_console_max_delay(const char *val, libcfs_console_min_delay, INT_MAX); } -static struct kernel_param_ops param_ops_console_max_delay = { +static const struct kernel_param_ops param_ops_console_max_delay = { .set = param_set_console_max_delay, .get = param_get_delay, };
@@ -156,7 +156,7 @@ static int param_set_console_min_delay(const char *val, 1, libcfs_console_max_delay); } -static struct kernel_param_ops param_ops_console_min_delay = { +static const struct kernel_param_ops param_ops_console_min_delay = { .set = param_set_console_min_delay, .get = param_get_delay, };
@@ -188,7 +188,7 @@ static int param_set_uintpos(const char *val, const struct kernel_param *kp)return param_set_uint_minmax (val, kp,1 ,-1 ); } -static struct kernel_param_ops param_ops_uintpos = { +static const struct kernel_param_ops param_ops_uintpos = { .set = param_set_uintpos, .get = param_get_uint, };
Signature · 1 line
2.7.4
Quoted 41 lines
The structure is used as an argument to
module_parammacro. This macro calls a bunch of other macros and finally assigns the instance of thekernel_param_opsstructure to the const struct kernel_param_ops* field of a variable of typekernel_param. Hence, const can be added to the structure.Coccinelle Script:
@r disable optional_qualifier@
identifier i;
position p;
@@
static structkernel_param_opsi@p = { ... };@ok1@
identifier r.i;
expression e;
position p;
@@
e = i@p@script:python s@
i << r.i;
t;
@@
coccinelle.t = i[10:];@ok2@
declarer namemodule_param;
expression e1,e2;
position p;
@@module_param(e1,s.t@p,e2);@bad@
position p != {r.p,ok1.p,ok2.p};
identifier r.i;
@@
e@i@p
Quoted 8 lines
@depends on !bad disable optional_qualifier@
identifier r.i;
@@
static
+const
structkernel_param_opsi = { ... };Signed-off-by Gargi Sharma <[email protected]>
Quoted 48 lines
--- drivers/staging/lustre/lnet/libcfs/debug.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)drivers/staging/lustre/lnet/libcfs/debug.c +4
-4@@ -80,7 +80,7 @@ static int libcfs_param_debug_mb_set(const char *val,* it needs quite a bunch of extra processing, so we define special * debugmb parameter type with corresponding methods to handle this case */ -static struct kernel_param_ops param_ops_debugmb = { +static const struct kernel_param_ops param_ops_debugmb = { .set = libcfs_param_debug_mb_set, .get = param_get_uint, };@@ -138,7 +138,7 @@ static int param_set_console_max_delay(const char *val, libcfs_console_min_delay, INT_MAX); } -static struct kernel_param_ops param_ops_console_max_delay = { +static const struct kernel_param_ops param_ops_console_max_delay = { .set = param_set_console_max_delay, .get = param_get_delay, };@@ -156,7 +156,7 @@ static int param_set_console_min_delay(const char *val, 1, libcfs_console_max_delay); } -static struct kernel_param_ops param_ops_console_min_delay = { +static const struct kernel_param_ops param_ops_console_min_delay = { .set = param_set_console_min_delay, .get = param_get_delay, };@@ -188,7 +188,7 @@ static int param_set_uintpos(const char *val, const struct kernel_param *kp)return param_set_uint_minmax (val, kp,1 ,-1 ); } -static struct kernel_param_ops param_ops_uintpos = { +static const struct kernel_param_ops param_ops_uintpos = { .set = param_set_uintpos, .get = param_get_uint, };Signature · 1 line
2.7.4