diff options
Diffstat (limited to 'Documentation')
-rw-r--r-- | Documentation/filesystems/sysfs.txt | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/Documentation/filesystems/sysfs.txt b/Documentation/filesystems/sysfs.txt index dc276598a65a..4b86ec283720 100644 --- a/Documentation/filesystems/sysfs.txt +++ b/Documentation/filesystems/sysfs.txt | |||
@@ -90,7 +90,7 @@ void device_remove_file(struct device *, struct device_attribute *); | |||
90 | 90 | ||
91 | It also defines this helper for defining device attributes: | 91 | It also defines this helper for defining device attributes: |
92 | 92 | ||
93 | #define DEVICE_ATTR(_name,_mode,_show,_store) \ | 93 | #define DEVICE_ATTR(_name, _mode, _show, _store) \ |
94 | struct device_attribute dev_attr_##_name = { \ | 94 | struct device_attribute dev_attr_##_name = { \ |
95 | .attr = {.name = __stringify(_name) , .mode = _mode }, \ | 95 | .attr = {.name = __stringify(_name) , .mode = _mode }, \ |
96 | .show = _show, \ | 96 | .show = _show, \ |
@@ -99,7 +99,7 @@ struct device_attribute dev_attr_##_name = { \ | |||
99 | 99 | ||
100 | For example, declaring | 100 | For example, declaring |
101 | 101 | ||
102 | static DEVICE_ATTR(foo,0644,show_foo,store_foo); | 102 | static DEVICE_ATTR(foo, 0644, show_foo, store_foo); |
103 | 103 | ||
104 | is equivalent to doing: | 104 | is equivalent to doing: |
105 | 105 | ||
@@ -121,8 +121,8 @@ set of sysfs operations for forwarding read and write calls to the | |||
121 | show and store methods of the attribute owners. | 121 | show and store methods of the attribute owners. |
122 | 122 | ||
123 | struct sysfs_ops { | 123 | struct sysfs_ops { |
124 | ssize_t (*show)(struct kobject *, struct attribute *,char *); | 124 | ssize_t (*show)(struct kobject *, struct attribute *, char *); |
125 | ssize_t (*store)(struct kobject *,struct attribute *,const char *); | 125 | ssize_t (*store)(struct kobject *, struct attribute *, const char *); |
126 | }; | 126 | }; |
127 | 127 | ||
128 | [ Subsystems should have already defined a struct kobj_type as a | 128 | [ Subsystems should have already defined a struct kobj_type as a |
@@ -137,7 +137,7 @@ calls the associated methods. | |||
137 | 137 | ||
138 | To illustrate: | 138 | To illustrate: |
139 | 139 | ||
140 | #define to_dev_attr(_attr) container_of(_attr,struct device_attribute,attr) | 140 | #define to_dev_attr(_attr) container_of(_attr, struct device_attribute, attr) |
141 | #define to_dev(d) container_of(d, struct device, kobj) | 141 | #define to_dev(d) container_of(d, struct device, kobj) |
142 | 142 | ||
143 | static ssize_t | 143 | static ssize_t |
@@ -148,7 +148,7 @@ dev_attr_show(struct kobject * kobj, struct attribute * attr, char * buf) | |||
148 | ssize_t ret = 0; | 148 | ssize_t ret = 0; |
149 | 149 | ||
150 | if (dev_attr->show) | 150 | if (dev_attr->show) |
151 | ret = dev_attr->show(dev,buf); | 151 | ret = dev_attr->show(dev, buf); |
152 | return ret; | 152 | return ret; |
153 | } | 153 | } |
154 | 154 | ||
@@ -216,16 +216,16 @@ A very simple (and naive) implementation of a device attribute is: | |||
216 | 216 | ||
217 | static ssize_t show_name(struct device *dev, struct device_attribute *attr, char *buf) | 217 | static ssize_t show_name(struct device *dev, struct device_attribute *attr, char *buf) |
218 | { | 218 | { |
219 | return sprintf(buf,"%s\n",dev->name); | 219 | return snprintf(buf, PAGE_SIZE, "%s\n", dev->name); |
220 | } | 220 | } |
221 | 221 | ||
222 | static ssize_t store_name(struct device * dev, const char * buf) | 222 | static ssize_t store_name(struct device * dev, const char * buf) |
223 | { | 223 | { |
224 | sscanf(buf,"%20s",dev->name); | 224 | sscanf(buf, "%20s", dev->name); |
225 | return strlen(buf); | 225 | return strnlen(buf, PAGE_SIZE); |
226 | } | 226 | } |
227 | 227 | ||
228 | static DEVICE_ATTR(name,S_IRUGO,show_name,store_name); | 228 | static DEVICE_ATTR(name, S_IRUGO, show_name, store_name); |
229 | 229 | ||
230 | 230 | ||
231 | (Note that the real implementation doesn't allow userspace to set the | 231 | (Note that the real implementation doesn't allow userspace to set the |
@@ -290,7 +290,7 @@ struct device_attribute { | |||
290 | 290 | ||
291 | Declaring: | 291 | Declaring: |
292 | 292 | ||
293 | DEVICE_ATTR(_name,_str,_mode,_show,_store); | 293 | DEVICE_ATTR(_name, _str, _mode, _show, _store); |
294 | 294 | ||
295 | Creation/Removal: | 295 | Creation/Removal: |
296 | 296 | ||
@@ -310,7 +310,7 @@ struct bus_attribute { | |||
310 | 310 | ||
311 | Declaring: | 311 | Declaring: |
312 | 312 | ||
313 | BUS_ATTR(_name,_mode,_show,_store) | 313 | BUS_ATTR(_name, _mode, _show, _store) |
314 | 314 | ||
315 | Creation/Removal: | 315 | Creation/Removal: |
316 | 316 | ||
@@ -331,7 +331,7 @@ struct driver_attribute { | |||
331 | 331 | ||
332 | Declaring: | 332 | Declaring: |
333 | 333 | ||
334 | DRIVER_ATTR(_name,_mode,_show,_store) | 334 | DRIVER_ATTR(_name, _mode, _show, _store) |
335 | 335 | ||
336 | Creation/Removal: | 336 | Creation/Removal: |
337 | 337 | ||