Skip to contentSkip to conversation

: More module parameter compatibility for 2.5.52

PATCH In review Jean Tourrilhes 2 participants 6 messages Dec 17, 2002 – Dec 18, 2002 Module support

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 : More module parameter compatibility for 2.5.52

	Hi,

	I've just downloaded 2.5.52 to try the new module parameter

support. Unfortunately, the letter 'c' was not implemented, and I need it. This is used in few drivers (such as hp100, wavelan, wlan_cs...).
I've only checked that with this patch my hp100 cards load
fine, but I didn't test the various corner cases.

	Have fun...

	Jean

---------------------------------------------------------------

include/linux/moduleparam.h renamed from include/linux/moduleparam.r1.h +1 -0
diff -u -p linux/include/linux/moduleparam.r1.h linux/include/linux/moduleparam.h
@@ -25,6 +25,7 @@ struct kernel_param {
 	param_set_fn set;
 	param_get_fn get;
 	void *arg;
+	void *priv;
 };
 
 /* Special one for strings we want to copy into */
kernel/module.c renamed from kernel/module.r1.c +41 -1

62 lines not on this page · raw message

#1 lore raw
Quoted 11 lines · jt
	Hi,

	I've just downloaded 2.5.52 to try the new module parameter

support. Unfortunately, the letter 'c' was not implemented, and I need it. This is used in few drivers (such as hp100, wavelan, wlan_cs...).
I've only checked that with this patch my hp100 cards load
fine, but I didn't test the various corner cases.

	Have fun...

	Jean

Yeah, and I really should have tested this stuff properly... New (corrected) patch attached... Maybe even correct, who
knows...

Jean

---------------------------------------------------------------

include/linux/moduleparam.h renamed from include/linux/moduleparam.r1.h +3 -1
diff -u -p linux/include/linux/moduleparam.r1.h linux/include/linux/moduleparam.h
@@ -25,6 +25,7 @@ struct kernel_param {
 	param_set_fn set;
 	param_get_fn get;
 	void *arg;
+	void *priv;
 };
 
 /* Special one for strings we want to copy into */
@@ -123,5 +124,6 @@ int param_array(const char *name,
 		const char *val,
 		unsigned int min, unsigned int max,
 		void *elem, int elemsize,
-		int (*set)(const char *, struct kernel_param *kp));
+		int (*set)(const char *, struct kernel_param *kp),
+		void *priv);
 #endif /* _LINUX_MODULE_PARAM_TYPES_H */
kernel/params.c renamed from kernel/params.r1.c +4 -2
diff -u -p linux/kernel/params.r1.c linux/kernel/params.c
@@ -228,7 +228,8 @@ int param_array(const char *name,
 		const char *val,
 		unsigned int min, unsigned int max,
 		void *elem, int elemsize,
-		int (*set)(const char *, struct kernel_param *kp))
+		int (*set)(const char *, struct kernel_param *kp),
+		void *priv)
 {
 	int ret;
 	unsigned int count = 0;
@@ -237,6 +238,7 @@ int param_array(const char *name,
 	/* Get the name right for errors. */
 	kp.name = name;
 	kp.arg = elem;
+	kp.priv = priv;
 
 	/* No equals sign? */
 	if (!val) {
@@ -285,7 +287,7 @@ int param_set_intarray(const char *val, 
 	/* Grab min and max as first two elements */
 	array = kp->arg;
 	return param_array(kp->name, val, array[0], array[1], &array[2],
-			   sizeof(int), param_set_int);
+			   sizeof(int), param_set_int, NULL);
 }
 
 int param_get_intarray(char *buffer, struct kernel_param *kp)
kernel/module.c renamed from kernel/module.r1.c +44 -5

77 lines not on this page · raw message

#2 lore raw
In reply to Jean Tourrilhes

In message <[email protected]> you write:

Quoted 5 lines
	Hi,

	I've just downloaded 2.5.52 to try the new module parameter

support. Unfortunately, the letter 'c' was not implemented, and I need it. This is used in few drivers (such as hp100, wavelan, wlan_cs...).

Cool, an undocumented type! And they have explit sizes, and they're used in arrays. Just wonderful.

I prefer the fix below. Does it work for you?

Rusty.
--
Anyone who quotes me in their sig is an idiot. -- Rusty Russell.

Name: Implement c in MODULE_PARM compatibility wedge
Author: Rusty Russell and Jean Tourrilhes
Status: Experimental

D: The "c" MODULE_PARM type was missing, as pointed out by Jean Tourrilhes.

kernel/module.c +31 -1
diff -urNp --exclude TAGS -X /home/rusty/current-dontdiff --minimal linux-2.5.52/kernel/module.c working-2.5.52-cparam/kernel/module.c
@@ -569,10 +569,19 @@ static int param_string(const char *name
 	return 0;
 }
 
+/* Bounds checking done below */
+static int obsparm_copy_string(const char *val, struct kernel_param *kp)
+{
+	strcpy(kp->arg, val);
+	return 0;
+}
+
 extern int set_obsolete(const char *val, struct kernel_param *kp)
 {
 	unsigned int min, max;
-	char *p, *endp;
+	unsigned int size, maxsize;
+	char *endp;
+	const char *p;
 	struct obsolete_modparm *obsparm = kp->arg;
 
 	if (!val) {
@@ -605,8 +614,29 @@ extern int set_obsolete(const char *val,
 				   sizeof(long), param_set_long);
 	case 's':
 		return param_string(kp->name, val, min, max, obsparm->addr);
+
+	case 'c':
+		/* Undocumented: 1-5c50 means 1-5 strings of up to 49 chars,
+		   and the decl is "char xxx[5][50];" */
+		p = endp+1;
+		maxsize = simple_strtol(p, &endp, 10);
+		/* We check lengths here (yes, this is a hack). */
+		p = val;
+		while (p[size = strcspn(p, ",")]) {
+			if (size >= maxsize) 
+				goto oversize;
+			p += size+1;
+		}
+		if (size >= maxsize) 
+			goto oversize;
+		return param_array(kp->name, val, min, max, obsparm->addr,
+				   maxsize, obsparm_copy_string);
 	}
 	printk(KERN_ERR "Unknown obsolete parameter type %s\n", obsparm->type);
+	return -EINVAL;
+ oversize:
+	printk(KERN_ERR
+	       "Parameter %s doesn't fit in %u chars.\n", kp->name, maxsize);
 	return -EINVAL;
 }
 
#3 lore raw
Quoted 9 lines · Rusty Russell

In message <[email protected]> you write:

Quoted 5 lines
	Hi,

	I've just downloaded 2.5.52 to try the new module parameter

support. Unfortunately, the letter 'c' was not implemented, and I need it. This is used in few drivers (such as hp100, wavelan, wlan_cs...).

Cool, an undocumented type! And they have explit sizes, and they're used in arrays. Just wonderful.

I can only say that they are more efficient than 's'...

Quoted 3 lines

I prefer the fix below. Does it work for you?

Rusty.

With all due respect, your fix is quite ugly.
And think about it this way : your new param architecture is
supposed to be flexible and supposed to allow modules to get parameters in any shape or form. But, on the other hand, it's impossible to implement something as simple as 'c' without ugly hacks.
Maybe we can deduct from this that the new param API is not
flexible enough and that the simple addition of an opaque type (priv) can have some value. From personal experience, most APIs that didn't had mechanism to pass private data between an entity and the entity handlers ended up regretting it and having to add it back at some point.

	Have fun...

	Jean
#4 lore raw

In message <[email protected]> you write:

Quoted 6 lines · Rusty Russell
Quoted 3 lines

I prefer the fix below. Does it work for you?

Rusty.

With all due respect, your fix is quite ugly.

Yes.

Quoted 4 lines

And think about it this way : your new param architecture is
supposed to be flexible and supposed to allow modules to get parameters in any shape or form. But, on the other hand, it's impossible to implement something as simple as 'c' without ugly hacks.

'c' is trivial. 1-20c50, which is a the two dimensional array of variable bounds, which is outside the scope of current param_array implementation (which was designed to handle 1d arrays).

Quoted 3 lines

Maybe we can deduct from this that the new param API is not
flexible enough and that the simple addition of an opaque type (priv) can have some value.

They *do* have a mechanism to pass extra parameters (kp->arg), it's just that the standard "param_array" code already uses it to hand the address of the variable. Your patch added a second one.

The new param code was not meant to do *everything*, it was meant to add type safety and unification of boot and module parameters, and allow extensibility.

I think you're confusing "param_array() doesn't handle 2d arrays" with "infrastructure not powerful enough". Since __module_param_call() is functionally equivalent to __setup(), the second one seems unlikely.

Writing such an extension is a job for the next mail...

Does that clarify?
Rusty.
--
Anyone who quotes me in their sig is an idiot. -- Rusty Russell.

#5 lore raw
Quoted 8 lines · Rusty Russell

I think you're confusing "param_array() doesn't handle 2d arrays" with "infrastructure not powerful enough". Since __module_param_call() is functionally equivalent to __setup(), the second one seems unlikely.

Writing such an extension is a job for the next mail...

Does that clarify?

Perfect.

Quoted 1 line

Rusty.

Good luck...

Jean