Skip to contentSkip to conversation

module_param: check type correctness for module_param_array

PATCH Applied Rusty Russell 2 participants 2 messages Dec 15, 2011

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

PATCH 1/15 module_param: check type correctness for module_param_array

module_param_array(), unlike its non-array cousins, didn't check the type of the variable. Fixing this found two bugs.

Cc Luca Risolia <[email protected]>
Cc Mauro Carvalho Chehab <[email protected]>
Cc Eric Piel <[email protected]>
---
 drivers/media/video/et61x251/et61x251_core.c |    4 ++--
 drivers/media/video/sn9c102/sn9c102_core.c   |    4 ++--
 drivers/mfd/janz-cmodio.c                    |    2 +-
 drivers/misc/lis3lv02d/lis3lv02d.c           |    2 ++
 include/linux/moduleparam.h                  |    1 +
 5 files changed, 8 insertions(+), 5 deletions(-)
drivers/media/video/et61x251/et61x251_core.c +2 -2
@@ -76,8 +76,8 @@ MODULE_PARM_DESC(video_nr,
 		 "\none and for every other camera."
 		 "\n");
 
-static short force_munmap[] = {[0 ... ET61X251_MAX_DEVICES-1] =
-			       ET61X251_FORCE_MUNMAP};
+static bool force_munmap[] = {[0 ... ET61X251_MAX_DEVICES-1] =
+			      ET61X251_FORCE_MUNMAP};
 module_param_array(force_munmap, bool, NULL, 0444);
 MODULE_PARM_DESC(force_munmap,
 		 "\n<0|1[,...]> Force the application to unmap previously"
drivers/media/video/sn9c102/sn9c102_core.c +2 -2
@@ -75,8 +75,8 @@ MODULE_PARM_DESC(video_nr,
 		 "\none and for every other camera."
 		 "\n");
 
-static short force_munmap[] = {[0 ... SN9C102_MAX_DEVICES-1] =
-			       SN9C102_FORCE_MUNMAP};
+static bool force_munmap[] = {[0 ... SN9C102_MAX_DEVICES-1] =
+			      SN9C102_FORCE_MUNMAP};
 module_param_array(force_munmap, bool, NULL, 0444);
 MODULE_PARM_DESC(force_munmap,
 		 " <0|1[,...]>"
drivers/mfd/janz-cmodio.c +1 -1
@@ -33,7 +33,7 @@
 
 /* Module Parameters */
 static unsigned int num_modules = CMODIO_MAX_MODULES;
-static unsigned char *modules[CMODIO_MAX_MODULES] = {
+static char *modules[CMODIO_MAX_MODULES] = {
 	"empty", "empty", "empty", "empty",
 };
 
drivers/misc/lis3lv02d/lis3lv02d.c +2 -0
@@ -111,6 +111,8 @@ static struct kernel_param_ops param_ops
 	.get = param_get_int,
 };
 
+#define param_check_axis(name, p) param_check_int(name, p)
+
 module_param_array_named(axes, lis3_dev.ac.as_array, axis, NULL, 0644);
 MODULE_PARM_DESC(axes, "Axis-mapping for x,y,z directions");
 
include/linux/moduleparam.h +1 -0
@@ -395,6 +395,7 @@ extern int param_get_invbool(char *buffe
  * module_param_named() for why this might be necessary.
  */
 #define module_param_array_named(name, array, type, nump, perm)		\
+	param_check_##type(name, &(array)[0]);				\
 	static const struct kparam_array __param_arr_##name		\
 	= { .max = ARRAY_SIZE(array), .num = nump,                      \
 	    .ops = &param_ops_##type,					\
Acked-by on v1 1/15
#1 lore raw
Quoted 11 lines · Rusty Russell

module_param_array(), unlike its non-array cousins, didn't check the type of the variable. Fixing this found two bugs.

Cc Luca Risolia <[email protected]>
Cc Mauro Carvalho Chehab <[email protected]>
Cc Eric Piel <[email protected]>
---
 drivers/media/video/et61x251/et61x251_core.c |    4 ++--
 drivers/media/video/sn9c102/sn9c102_core.c   |    4 ++--
Quoted 68 lines
 drivers/mfd/janz-cmodio.c                    |    2 +-
 drivers/misc/lis3lv02d/lis3lv02d.c           |    2 ++
 include/linux/moduleparam.h                  |    1 +
 5 files changed, 8 insertions(+), 5 deletions(-)
drivers/media/video/et61x251/et61x251_core.c +2 -2
@@ -76,8 +76,8 @@ MODULE_PARM_DESC(video_nr,
 		 "\none and for every other camera."
 		 "\n");
 
-static short force_munmap[] = {[0 ... ET61X251_MAX_DEVICES-1] =
-			       ET61X251_FORCE_MUNMAP};
+static bool force_munmap[] = {[0 ... ET61X251_MAX_DEVICES-1] =
+			      ET61X251_FORCE_MUNMAP};
 module_param_array(force_munmap, bool, NULL, 0444);
 MODULE_PARM_DESC(force_munmap,
 		 "\n<0|1[,...]> Force the application to unmap previously"
drivers/media/video/sn9c102/sn9c102_core.c +2 -2
@@ -75,8 +75,8 @@ MODULE_PARM_DESC(video_nr,
 		 "\none and for every other camera."
 		 "\n");
 
-static short force_munmap[] = {[0 ... SN9C102_MAX_DEVICES-1] =
-			       SN9C102_FORCE_MUNMAP};
+static bool force_munmap[] = {[0 ... SN9C102_MAX_DEVICES-1] =
+			      SN9C102_FORCE_MUNMAP};
 module_param_array(force_munmap, bool, NULL, 0444);
 MODULE_PARM_DESC(force_munmap,
 		 " <0|1[,...]>"
drivers/mfd/janz-cmodio.c +1 -1
@@ -33,7 +33,7 @@
 
 /* Module Parameters */
 static unsigned int num_modules = CMODIO_MAX_MODULES;
-static unsigned char *modules[CMODIO_MAX_MODULES] = {
+static char *modules[CMODIO_MAX_MODULES] = {
 	"empty", "empty", "empty", "empty",
 };
 
drivers/misc/lis3lv02d/lis3lv02d.c +2 -0
@@ -111,6 +111,8 @@ static struct kernel_param_ops param_ops
 	.get = param_get_int,
 };
 
+#define param_check_axis(name, p) param_check_int(name, p)
+
 module_param_array_named(axes, lis3_dev.ac.as_array, axis, NULL, 0644);
 MODULE_PARM_DESC(axes, "Axis-mapping for x,y,z directions");
 
include/linux/moduleparam.h +1 -0
@@ -395,6 +395,7 @@ extern int param_get_invbool(char *buffe
  * module_param_named() for why this might be necessary.
  */
 #define module_param_array_named(name, array, type, nump, perm)		\
+	param_check_##type(name, &(array)[0]);				\
 	static const struct kparam_array __param_arr_##name		\
 	= { .max = ARRAY_SIZE(array), .num = nump,                      \
 	    .ops = &param_ops_##type,					\