Skip to contentSkip to conversation

param: use ops in struct kernel_param, rather than get and set fns directly

PATCH Takashi Iwai 2 participants 4 messages Oct 30, 2009 – Nov 16, 2009 1 message not in the archive

Subsystems (7)
lore
Share & tools
lore
#1 lore raw
In reply to a message not in the archive

At Fri, 23 Oct 2009 00:51:28 +1030,

Quoted 8 lines · Rusty Russell

This is more kernel-ish, saves some space, and also allows us to expand the ops without breaking all the callers who are happy for the new members to be NULL.

The few places which defined their own param types are changed to the new scheme.

Quoted 6 lines

Since we're touching them anyway, we change get and set to take a const struct kernel_param (which they were, and will be again).

To reduce churn, module_param_call creates the ops struct so the callers don't have to change (and casts the functions to reduce warnings). The modern version which takes an ops struct is called module_param_cb.

This is nice, as it also reduces the size of struct kernel_param, so each parameter uses less footprint (who cares, though?) :)

But, just wondering whether we still need to export get/set functions. They can be called from ops now, so if any, it can be defined even as an inlinefunction or a macro.

thanks,

Takashi

#2 lore raw
Quoted 17 lines · Takashi Iwai

At Fri, 23 Oct 2009 00:51:28 +1030,

Quoted 8 lines · Rusty Russell

This is more kernel-ish, saves some space, and also allows us to expand the ops without breaking all the callers who are happy for the new members to be NULL.

The few places which defined their own param types are changed to the new scheme.

Quoted 6 lines

Since we're touching them anyway, we change get and set to take a const struct kernel_param (which they were, and will be again).

To reduce churn, module_param_call creates the ops struct so the callers don't have to change (and casts the functions to reduce warnings). The modern version which takes an ops struct is called module_param_cb.

Quoted 6 lines

This is nice, as it also reduces the size of struct kernel_param, so each parameter uses less footprint (who cares, though?) :)

But, just wondering whether we still need to export get/set functions. They can be called from ops now, so if any, it can be defined even as an inlinefunction or a macro.

My thought too, so I tried that, but many are still used like so:

	module_param_call(foo, set_foo, param_get_uint, NULL, 0644);

They can all be replaced in time with something like:

	static int param_get_foo(char *buffer, const struct kernel_param *kp)
	{
		return param_ops_uint.get(buffer, kp);
	}

But it'll take a transition period.

Thanks!
Rusty.

Quoted 6 lines

thanks,

Takashi

author Reviewed-by
#3 lore raw

At Fri, 30 Oct 2009 21:43:39 +1030,

Quoted 30 lines · Rusty Russell
Quoted 17 lines · Takashi Iwai

At Fri, 23 Oct 2009 00:51:28 +1030,

Quoted 8 lines · Rusty Russell

This is more kernel-ish, saves some space, and also allows us to expand the ops without breaking all the callers who are happy for the new members to be NULL.

The few places which defined their own param types are changed to the new scheme.

Quoted 6 lines

Since we're touching them anyway, we change get and set to take a const struct kernel_param (which they were, and will be again).

To reduce churn, module_param_call creates the ops struct so the callers don't have to change (and casts the functions to reduce warnings). The modern version which takes an ops struct is called module_param_cb.

Quoted 6 lines

This is nice, as it also reduces the size of struct kernel_param, so each parameter uses less footprint (who cares, though?) :)

But, just wondering whether we still need to export get/set functions. They can be called from ops now, so if any, it can be defined even as an inlinefunction or a macro.

My thought too, so I tried that, but many are still used like so:

	module_param_call(foo, set_foo, param_get_uint, NULL, 0644);
Quoted 7 lines

They can all be replaced in time with something like:

	static int param_get_foo(char *buffer, const struct kernel_param *kp)
	{
		return param_ops_uint.get(buffer, kp);
	}

But it'll take a transition period.

Fair enough. And, maybe these get/set should be defined as an ops explicitly so that it can be used for multiple parameters. But we can do cleanups later, of course :)

Oh, in case you need,

for all new patches.

Thanks!

Takashi

#4 lore raw
In reply to Rusty Russell

At Fri, 30 Oct 2009 21:43:39 +1030,

Quoted 30 lines · Rusty Russell
Quoted 17 lines · Takashi Iwai

At Fri, 23 Oct 2009 00:51:28 +1030,

Quoted 8 lines · Rusty Russell

This is more kernel-ish, saves some space, and also allows us to expand the ops without breaking all the callers who are happy for the new members to be NULL.

The few places which defined their own param types are changed to the new scheme.

Quoted 6 lines

Since we're touching them anyway, we change get and set to take a const struct kernel_param (which they were, and will be again).

To reduce churn, module_param_call creates the ops struct so the callers don't have to change (and casts the functions to reduce warnings). The modern version which takes an ops struct is called module_param_cb.

Quoted 6 lines

This is nice, as it also reduces the size of struct kernel_param, so each parameter uses less footprint (who cares, though?) :)

But, just wondering whether we still need to export get/set functions. They can be called from ops now, so if any, it can be defined even as an inlinefunction or a macro.

My thought too, so I tried that, but many are still used like so:

	module_param_call(foo, set_foo, param_get_uint, NULL, 0644);
Quoted 7 lines

They can all be replaced in time with something like:

	static int param_get_foo(char *buffer, const struct kernel_param *kp)
	{
		return param_ops_uint.get(buffer, kp);
	}

But it'll take a transition period.

[Removed Cc's since it's no sub-device specific issue]

Regarding the removal of exports:

I found that static inline functions can be used also as pointers. So, expanding them in moduleparam.h seems working actually as is.

A test patch is below. I just did a short build-test, though.

thanks,

Takashi

===
From: Takashi Iwai <[email protected]>
Subject: param: use static inline functions for param_{get|set}_*()

Instead of exporting each param_{get|set}_*() function, expand it as a static inline function to call the ops.{get|set}. Since static inline functions can be used as function pointers, the currently existing codes work as they are.

---

include/linux/moduleparam.h +31 -22
index 893549c..00baae9 100644
@@ -283,50 +283,53 @@ static inline void destroy_params(const struct kernel_param *params,
 #define __param_check(name, p, type) \
 	static inline type *__check_##name(void) { return(p); }
 
+/* Define param_get_xxx() and param_set_xxx() for compatibility.
+ * They are defined as inline functions so that they can be used also
+ * as function pointers.
+ */
+#define DEFINE_PARAM_GET_SET(name) \
+	static inline int param_set_##name(const char *val, \
+					   const struct kernel_param *kp) \
+	{ return param_ops_##name.set(val, kp); } \
+	static inline int param_get_##name(char *buffer, \
+					   const struct kernel_param *kp) \
+	{ return param_ops_##name.get(buffer, kp); }
+
 extern struct kernel_param_ops param_ops_byte;
-extern int param_set_byte(const char *val, const struct kernel_param *kp);
-extern int param_get_byte(char *buffer, const struct kernel_param *kp);
+DEFINE_PARAM_GET_SET(byte);
 #define param_check_byte(name, p) __param_check(name, p, unsigned char)
 
 extern struct kernel_param_ops param_ops_short;
-extern int param_set_short(const char *val, const struct kernel_param *kp);
-extern int param_get_short(char *buffer, const struct kernel_param *kp);
+DEFINE_PARAM_GET_SET(short);
 #define param_check_short(name, p) __param_check(name, p, short)
 
 extern struct kernel_param_ops param_ops_ushort;
-extern int param_set_ushort(const char *val, const struct kernel_param *kp);
-extern int param_get_ushort(char *buffer, const struct kernel_param *kp);
+DEFINE_PARAM_GET_SET(ushort);
 #define param_check_ushort(name, p) __param_check(name, p, unsigned short)
 
 extern struct kernel_param_ops param_ops_int;
-extern int param_set_int(const char *val, const struct kernel_param *kp);
-extern int param_get_int(char *buffer, const struct kernel_param *kp);
+DEFINE_PARAM_GET_SET(int);
 #define param_check_int(name, p) __param_check(name, p, int)
 
 extern struct kernel_param_ops param_ops_uint;
-extern int param_set_uint(const char *val, const struct kernel_param *kp);
-extern int param_get_uint(char *buffer, const struct kernel_param *kp);
+DEFINE_PARAM_GET_SET(uint);
 #define param_check_uint(name, p) __param_check(name, p, unsigned int)
 
 extern struct kernel_param_ops param_ops_long;
-extern int param_set_long(const char *val, const struct kernel_param *kp);
-extern int param_get_long(char *buffer, const struct kernel_param *kp);
+DEFINE_PARAM_GET_SET(long);
 #define param_check_long(name, p) __param_check(name, p, long)
 
 extern struct kernel_param_ops param_ops_ulong;
-extern int param_set_ulong(const char *val, const struct kernel_param *kp);
-extern int param_get_ulong(char *buffer, const struct kernel_param *kp);
+DEFINE_PARAM_GET_SET(ulong);
 #define param_check_ulong(name, p) __param_check(name, p, unsigned long)
 
 extern struct kernel_param_ops param_ops_charp;
-extern int param_set_charp(const char *val, const struct kernel_param *kp);
-extern int param_get_charp(char *buffer, const struct kernel_param *kp);
+DEFINE_PARAM_GET_SET(charp);
 #define param_check_charp(name, p) __param_check(name, p, char *)
 
 /* For historical reasons "bool" parameters can be (unsigned) "int". */
 extern struct kernel_param_ops param_ops_bool;
-extern int param_set_bool(const char *val, const struct kernel_param *kp);
-extern int param_get_bool(char *buffer, const struct kernel_param *kp);
+DEFINE_PARAM_GET_SET(bool);
 #define param_check_bool(name, p)					\
 	static inline void __check_##name(void)				\
 	{								\
@@ -336,8 +339,7 @@ extern int param_get_bool(char *buffer, const struct kernel_param *kp);
 	}
 
 extern struct kernel_param_ops param_ops_invbool;
-extern int param_set_invbool(const char *val, const struct kernel_param *kp);
-extern int param_get_invbool(char *buffer, const struct kernel_param *kp);
+DEFINE_PARAM_GET_SET(invbool);
 #define param_check_invbool(name, p) __param_check(name, p, bool)
 
 /**
@@ -380,8 +382,15 @@ extern int param_get_invbool(char *buffer, const struct kernel_param *kp);
 extern struct kernel_param_ops param_array_ops;
 
 extern struct kernel_param_ops param_ops_string;
-extern int param_set_copystring(const char *val, const struct kernel_param *);
-extern int param_get_string(char *buffer, const struct kernel_param *kp);
+static inline int param_set_copystring(const char *val,
+				       const struct kernel_param *kp)
+{
+	return param_ops_string.set(val, kp);
+}
+static inline int param_get_string(char *buffer, const struct kernel_param *kp)
+{
+	return param_ops_string.get(buffer, kp);
+}
 
 /* for exporting parameters in /sys/parameters */
 
kernel/params.c +21 -31

150 lines not on this page · raw message