Re: driverfs API Updates

Rusty Russell (rusty@rustcorp.com.au)
Thu, 8 Aug 2002 13:44:07 +1000


On Mon, 5 Aug 2002 12:17:13 -0700 (PDT)
Patrick Mochel <mochel@osdl.org> wrote:
> I've also created a macro[1] for defining device attributes, that goes
> like this:
>
> DEVICE_ATTR(name,"strname",mode,show,store);
>
> This will create a structure by the name of 'dev_attr_##name', where
> ##name is the first parameter, which can then be passed to
> device_create_file(). [2]

Hi Patrick,
I'll grab 2.5.31 when it comes out and play with it.

Personally, I would get rid of the "strname" (make it implied by the variable
name), and use type instead of show & store, eg:

DEVICE_ATTR(frobbable, O_RDWR, int);

This means you can (1) check that frobbable is actually an int at compile
time (__check_int), (2) you can use __show_int and __store_int as standard
routines, and (3) you can use your own types by:

#define __check_frobbable_t(x) ((void)((&x) == (frobbable_t *)0)
/* Define show_frobbable and store_frobbable here */

DEVICE_ATTR(frobbable, O_RDWR, frobbable_t);

This ties into alot of other projects such as event logging, etc.

Rusty.
PS. yeah yeah, I'll send code RSN.

-- 
   there are those who do and those who hang on and you don't see too
   many doers quoting their contemporaries.  -- Larry McVoy
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/