2011-06-29 18:53:57

by johnlinn

[permalink] [raw]
Subject: using a single sysfs show function for multiple device attributes

In a platform driver, I'm trying to use a single function for multiple device attributes and use the attr input to ID which attribute.

After the driver is up and running, the sysfs attributes exist. In my show function getting a device_attribute as an input, I never see the device attribute (attr) having anything in it (all 0s). I see the attr pointer be valid, but pointing to all 0's.

I don't see others using the attr input, but it seems like the way to ID which attribute is being accessed so that one show function can be used for many attributes.

I'm sure it's obvious, but I don't see what I'm doing wrong.

Thanks,
John


2011-06-29 20:02:07

by Andi Kleen

[permalink] [raw]
Subject: Re: using a single sysfs show function for multiple device attributes

[email protected] writes:
>
> I'm sure it's obvious, but I don't see what I'm doing wrong.

The standard way is to define your own attribute structure that
has the standard attribute as the first entry and use container_of()
to get at the "parent" object.

(basically poor man's OO inheritance)

-Andi
--
[email protected] -- Speaking for myself only