Skip to contentSkip to conversation

Am I paranoid or is everyone out to break my kernel builds (Breakage in drivers/pcmcia)

DISCUSSION Russell King 3 participants 6 messages Oct 21, 2004 Module support

lore
Share & tools
lore
#0 lore raw

It would appear that this change:

-module_param_array(irq_list, int, irq_list_count, 0444); +module_param_array(irq_list, int, &irq_list_count, 0444);

given:

static int irq_list[16];
static int irq_list_count;

breaks PCMCIA drivers. Why?

#define module_param_array(name, type, num, perm) \
module_param_array_named(name, name, type, num, perm)

#define module_param_array_named(name, array, type, num, perm)          \
        static struct kparam_array __param_arr_##name                   \
        = { ARRAY_SIZE(array), &num, param_set_##type, param_get_##type,\
            sizeof(array[0]), array };                                  \
        module_param_call(name, param_array_set, param_array_get,       \
                          &__param_arr_##name, perm)

Take special note of the '&' before 'num' in the above initialiser, and check the structure:

struct kparam_array

{
        unsigned int max;
        unsigned int *num;
        param_set_fn set;
        param_get_fn get;
        unsigned int elemsize;
        void *elem;
};

Therefore, module_param_array() does _NOT_ take a pointer to an integer. Rusty - please fix.

Signature · 4 lines
Russell King
 Linux kernel    2.6 ARM Linux   - http://www.arm.linux.org.uk/
 maintainer of:  2.6 PCMCIA      - http://pcmcia.arm.linux.org.uk/
                 2.6 Serial core
#1 lore raw
Quoted 23 lines · Russell King

It would appear that this change:

(quoted diff) +1 -1
-module_param_array(irq_list, int, irq_list_count, 0444);
+module_param_array(irq_list, int, &irq_list_count, 0444);

given:

static int irq_list[16];
static int irq_list_count;

breaks PCMCIA drivers. Why?

#define module_param_array(name, type, num, perm) \
module_param_array_named(name, name, type, num, perm)

#define module_param_array_named(name, array, type, num, perm)          \
        static struct kparam_array __param_arr_##name                   \
        = { ARRAY_SIZE(array), &num, param_set_##type, param_get_##type,\
            sizeof(array[0]), array };                                  \
        module_param_call(name, param_array_set, param_array_get,       \
                          &__param_arr_##name, perm)
Quoted 2 lines

Take special note of the '&' before 'num' in the above initialiser, and check the structure:

Something's out of whack with your tree. You should have:

#define module_param_array_named(name, array, type, nump, perm)		\
	static struct kparam_array __param_arr_##name			\
	= { ARRAY_SIZE(array), nump, param_set_##type, param_get_##type,\
	    sizeof(array[0]), array };					\
	module_param_call(name, param_array_set, param_array_get, 	\
			  &__param_arr_##name, perm)
#5 lore raw
In reply to Russell King
Quoted 15 lines · Russell King

It would appear that this change:

(quoted diff) +1 -1
-module_param_array(irq_list, int, irq_list_count, 0444);
+module_param_array(irq_list, int, &irq_list_count, 0444);

given:

static int irq_list[16];
static int irq_list_count;

breaks PCMCIA drivers. Why?

#define module_param_array(name, type, num, perm) \
module_param_array_named(name, name, type, num, perm)

Quoted 6 lines
#define module_param_array_named(name, array, type, num, perm)          \
        static struct kparam_array __param_arr_##name                   \
        = { ARRAY_SIZE(array), &num, param_set_##type, param_get_##type,\
            sizeof(array[0]), array };                                  \
        module_param_call(name, param_array_set, param_array_get,       \
                          &__param_arr_##name, perm)

I'm confused. Andrew, what happened to this part of my patch?

include/linux/moduleparam.h +5 -5
diff -urpN --exclude TAGS -X /home/rusty/devel/kernel/kernel-patches/current-dontdiff --minimal .22800-linux-2.6-bk/include/linux/moduleparam.h .22800-linux-2.6-bk.updated/include/linux/moduleparam.h
@@ -129,16 +129,16 @@ extern int param_set_invbool(const char 
 extern int param_get_invbool(char *buffer, struct kernel_param *kp);
 #define param_check_invbool(name, p) __param_check(name, p, int)
 
-/* Comma-separated array: num is set to number they actually specified. */
-#define module_param_array_named(name, array, type, num, perm)		\
+/* Comma-separated array: *nump is set to number they actually specified. */
+#define module_param_array_named(name, array, type, nump, perm)		\
 	static struct kparam_array __param_arr_##name			\
-	= { ARRAY_SIZE(array), &num, param_set_##type, param_get_##type,\
+	= { ARRAY_SIZE(array), nump, param_set_##type, param_get_##type,\
 	    sizeof(array[0]), array };					\
 	module_param_call(name, param_array_set, param_array_get, 	\
 			  &__param_arr_##name, perm)
 
-#define module_param_array(name, type, num, perm)		\
-	module_param_array_named(name, name, type, num, perm)
+#define module_param_array(name, type, nump, perm)		\
+	module_param_array_named(name, name, type, nump, perm)
 
 extern int param_array_set(const char *val, struct kernel_param *kp);
 extern int param_array_get(char *buffer, struct kernel_param *kp);

Rusty.

Signature · 1 line
Anyone who quotes me in their signature is an idiot -- Rusty Russell
#2 lore raw
In reply to Andrew Morton
Quoted 5 lines · Andrew Morton
Quoted 2 lines · Russell King

Take special note of the '&' before 'num' in the above initialiser, and check the structure:

Something's out of whack with your tree. You should have:

Ok, but what's the point of the change? If it's to indicate that we're returning a value, shouldn't the other module_param* macros also be fixed in the same way, or do we just like special cases?

Signature · 4 lines
Russell King
 Linux kernel    2.6 ARM Linux   - http://www.arm.linux.org.uk/
 maintainer of:  2.6 PCMCIA      - http://pcmcia.arm.linux.org.uk/
                 2.6 Serial core
#3 lore raw
Quoted 11 lines · Russell King
Quoted 5 lines · Andrew Morton
Quoted 2 lines · Russell King

Take special note of the '&' before 'num' in the above initialiser, and check the structure:

Something's out of whack with your tree. You should have:

Ok, but what's the point of the change? If it's to indicate that we're returning a value, shouldn't the other module_param* macros also be fixed in the same way, or do we just like special cases?

<rusty>
module_param_array() takes a variable to put the number of elements in. Looking through the uses, many people don't care, so they declare a dummy or share one variable between several parameters. The latter is problematic because sysfs uses that number to decide how many to display.

The solution is to change the variable arg to a pointer, and if the pointer is NULL, use the "max" value. This change is fairly small, but fixing up the callers is a lot of (trivial) churn.
</rusty>

#4 lore raw
In reply to Russell King
Quoted 10 lines · Russell King
Quoted 5 lines · Andrew Morton
Quoted 2 lines · Russell King

Take special note of the '&' before 'num' in the above initialiser, and check the structure:

Something's out of whack with your tree. You should have:

Ok, but what's the point of the change? If it's to indicate that we're returning a value, shouldn't the other module_param* macros also be fixed in the same way, or do we just like special cases?

Only module_param_array() sets a number: the number of elements in the array. By making that arg a pointer, we can put "NULL" there, since it turned out many people didn't care how many elements there were (and were overloading the same variable for all their arrays, which breaks printing in sysfs).

Hope that helps,
Rusty.

Signature · 1 line
Anyone who quotes me in their signature is an idiot -- Rusty Russell