2009-07-11 11:03:26

by Robert P. J. Day

[permalink] [raw]
Subject: what means "module_param(channel_mask, channel_mask, 0644)"?


researching my next newbie column about module parameters and i ran
across the following:

drivers/input/misc/ati_remote2.c:module_param(channel_mask, channel_mask, 0644);
drivers/input/misc/ati_remote2.c:module_param(mode_mask, mode_mask, 0644);

i have no idea what it means to have the second (type) field of
module_param() simply repeat the name of the parameter. is this some
strange magic? those two names don't *appear* to be typedef'ed
anywhere i can see.

rday
--

========================================================================
Robert P. J. Day Waterloo, Ontario, CANADA

Linux Consulting, Training and Annoying Kernel Pedantry.

Web page: http://crashcourse.ca
Twitter: http://twitter.com/rpjday
"Kernel Newbie Corner" column @ linux.com: http://cli.gs/WG6WYX
========================================================================


2009-07-11 11:09:47

by Robert P. J. Day

[permalink] [raw]
Subject: Re: what means "module_param(channel_mask, channel_mask, 0644)"?

On Sat, 11 Jul 2009, Robert P. J. Day wrote:

> researching my next newbie column about module parameters and i
> ran across the following:
>
> drivers/input/misc/ati_remote2.c:module_param(channel_mask, channel_mask, 0644);
> drivers/input/misc/ati_remote2.c:module_param(mode_mask, mode_mask, 0644);
>
> i have no idea what it means to have the second (type) field of
> module_param() simply repeat the name of the parameter. is this
> some strange magic? those two names don't *appear* to be typedef'ed
> anywhere i can see.

i should have added that the reason i ran across this was that i was
curious if anyone was using User Defined Parameter Types as explained
here:

http://docs.blackfin.uclinux.org/doku.php?id=linux-kernel:module_parameters

so i did a quick grep for any invocations of module_param() whose type
wasn't one of the standard int, boot, short, ... etc ... and those two
hits above showed up, which confused me.

so ... *is* anyone taking advantage of user-defined module parameter
types? not as i can tell, but maybe i just missed it.

rday
--

========================================================================
Robert P. J. Day Waterloo, Ontario, CANADA

Linux Consulting, Training and Annoying Kernel Pedantry.

Web page: http://crashcourse.ca
Twitter: http://twitter.com/rpjday
"Kernel Newbie Corner" column @ linux.com: http://cli.gs/WG6WYX
========================================================================

2009-07-11 12:43:13

by Robert P. J. Day

[permalink] [raw]
Subject: Re: what means "module_param(channel_mask, channel_mask, 0644)"?

On Sat, 11 Jul 2009, Paul Bolle wrote:

> On Sat, 2009-07-11 at 07:01 -0400, Robert P. J. Day wrote:
> > researching my next newbie column about module parameters and i ran
> > across the following:
> >
> > drivers/input/misc/ati_remote2.c:module_param(channel_mask, channel_mask, 0644);
> > drivers/input/misc/ati_remote2.c:module_param(mode_mask, mode_mask, 0644);
> >
> > i have no idea what it means to have the second (type) field of
> > module_param() simply repeat the name of the parameter. is this some
> > strange magic? those two names don't *appear* to be typedef'ed
> > anywhere i can see.
>
> See include/linux/moduleparam.h:
> /* Helper functions: type is byte, short, ushort, int, uint, long,
> ulong, charp, bool or invbool, or XXX if you define param_get_XXX,
> param_set_XXX and param_check_XXX. */
> #define module_param_named(name, value, type, perm) \
> param_check_##type(name, &(value)); \
> module_param_call(name, param_set_##type, param_get_##type, &value, perm); \
> __MODULE_PARM_TYPE(name, #type)
>
> #define module_param(name, type, perm) \
> module_param_named(name, name, type, perm)
>
> And in drivers/input/misc/ati_remote2.c we find:
> #define param_check_channel_mask(name, p) __param_check(name, p, unsigned in
> #define param_set_channel_mask ati_remote2_set_channel_mask
> #define param_get_channel_mask ati_remote2_get_channel_mask
> module_param(channel_mask, channel_mask, 0644);
> [...]
> #define param_check_mode_mask(name, p) __param_check(name, p, unsigned int)
> #define param_set_mode_mask ati_remote2_set_mode_mask
> #define param_get_mode_mask ati_remote2_get_mode_mask
> module_param(mode_mask, mode_mask, 0644);
>
> To me that looks like two implementations of the three param_*_XXX
> functions described in the comment quoted above.
>
> Does that answer your question?

yup. i was looking for something like that, i guess i just missed
it. thanks.

rday
--

========================================================================
Robert P. J. Day Waterloo, Ontario, CANADA

Linux Consulting, Training and Annoying Kernel Pedantry.

Web page: http://crashcourse.ca
Twitter: http://twitter.com/rpjday
"Kernel Newbie Corner" column @ linux.com: http://cli.gs/WG6WYX
========================================================================

2009-07-11 12:57:47

by Paul Bolle

[permalink] [raw]
Subject: Re: what means "module_param(channel_mask, channel_mask, 0644)"?

On Sat, 2009-07-11 at 07:01 -0400, Robert P. J. Day wrote:
> researching my next newbie column about module parameters and i ran
> across the following:
>
> drivers/input/misc/ati_remote2.c:module_param(channel_mask, channel_mask, 0644);
> drivers/input/misc/ati_remote2.c:module_param(mode_mask, mode_mask, 0644);
>
> i have no idea what it means to have the second (type) field of
> module_param() simply repeat the name of the parameter. is this some
> strange magic? those two names don't *appear* to be typedef'ed
> anywhere i can see.

See include/linux/moduleparam.h:
/* Helper functions: type is byte, short, ushort, int, uint, long,
ulong, charp, bool or invbool, or XXX if you define param_get_XXX,
param_set_XXX and param_check_XXX. */
#define module_param_named(name, value, type, perm) \
param_check_##type(name, &(value)); \
module_param_call(name, param_set_##type, param_get_##type, &value, perm); \
__MODULE_PARM_TYPE(name, #type)

#define module_param(name, type, perm) \
module_param_named(name, name, type, perm)

And in drivers/input/misc/ati_remote2.c we find:
#define param_check_channel_mask(name, p) __param_check(name, p, unsigned in
#define param_set_channel_mask ati_remote2_set_channel_mask
#define param_get_channel_mask ati_remote2_get_channel_mask
module_param(channel_mask, channel_mask, 0644);
[...]
#define param_check_mode_mask(name, p) __param_check(name, p, unsigned int)
#define param_set_mode_mask ati_remote2_set_mode_mask
#define param_get_mode_mask ati_remote2_get_mode_mask
module_param(mode_mask, mode_mask, 0644);

To me that looks like two implementations of the three param_*_XXX
functions described in the comment quoted above.

Does that answer your question?

Regards,


Paul Bolle