diff options
author | Grant Likely <grant.likely@secretlab.ca> | 2009-03-06 16:05:39 -0500 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2009-06-16 00:30:23 -0400 |
commit | b22813b373749d0878e7140e9a6eadf182298709 (patch) | |
tree | 835af1d5dc204db9c36514cb21000b32abea27d4 /Documentation/driver-model/device.txt | |
parent | 3959214f971417f4162926ac52ad4cd042958caa (diff) |
Driver Core: Warn driver authors about adding device attributes
Add a blurb to the driver-model documentation about how (not) to add
extra attributes to a struct device at driver probe time.
Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
Cc: Kay Sievers <kay.sievers@vrfy.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'Documentation/driver-model/device.txt')
-rw-r--r-- | Documentation/driver-model/device.txt | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/Documentation/driver-model/device.txt b/Documentation/driver-model/device.txt index a7cbfff40d07..a124f3126b0d 100644 --- a/Documentation/driver-model/device.txt +++ b/Documentation/driver-model/device.txt | |||
@@ -162,3 +162,35 @@ device_remove_file(dev,&dev_attr_power); | |||
162 | 162 | ||
163 | The file name will be 'power' with a mode of 0644 (-rw-r--r--). | 163 | The file name will be 'power' with a mode of 0644 (-rw-r--r--). |
164 | 164 | ||
165 | Word of warning: While the kernel allows device_create_file() and | ||
166 | device_remove_file() to be called on a device at any time, userspace has | ||
167 | strict expectations on when attributes get created. When a new device is | ||
168 | registered in the kernel, a uevent is generated to notify userspace (like | ||
169 | udev) that a new device is available. If attributes are added after the | ||
170 | device is registered, then userspace won't get notified and userspace will | ||
171 | not know about the new attributes. | ||
172 | |||
173 | This is important for device driver that need to publish additional | ||
174 | attributes for a device at driver probe time. If the device driver simply | ||
175 | calls device_create_file() on the device structure passed to it, then | ||
176 | userspace will never be notified of the new attributes. Instead, it should | ||
177 | probably use class_create() and class->dev_attrs to set up a list of | ||
178 | desired attributes in the modules_init function, and then in the .probe() | ||
179 | hook, and then use device_create() to create a new device as a child | ||
180 | of the probed device. The new device will generate a new uevent and | ||
181 | properly advertise the new attributes to userspace. | ||
182 | |||
183 | For example, if a driver wanted to add the following attributes: | ||
184 | struct device_attribute mydriver_attribs[] = { | ||
185 | __ATTR(port_count, 0444, port_count_show), | ||
186 | __ATTR(serial_number, 0444, serial_number_show), | ||
187 | NULL | ||
188 | }; | ||
189 | |||
190 | Then in the module init function is would do: | ||
191 | mydriver_class = class_create(THIS_MODULE, "my_attrs"); | ||
192 | mydriver_class.dev_attr = mydriver_attribs; | ||
193 | |||
194 | And assuming 'dev' is the struct device passed into the probe hook, the driver | ||
195 | probe function would do something like: | ||
196 | create_device(&mydriver_class, dev, chrdev, &private_data, "my_name"); | ||