aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2013-07-18 15:48:40 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2013-07-18 15:48:40 -0400
commit7a62711aacda8887d94c40daa199b37abb1d54e1 (patch)
tree5b47f1aff3e0054df35fcb9dc34433296bf803f3 /include
parent5d88d15e932ea98862c1008a4db3ae9dfac2932a (diff)
parent08801f966571b522f0581de0fd400abdf295b16b (diff)
Merge tag 'driver-core-3.11-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core
Pull driver core patches from Greg KH: "Here are some driver core patches for 3.11-rc2. They aren't really bugfixes, but a bunch of new helper macros for drivers to properly create attribute groups, which drivers and subsystems need to fix up a ton of race issues with incorrectly creating sysfs files (binary and normal) after userspace has been told that the device is present. Also here is the ability to create binary files as attribute groups, to solve that race condition, which was impossible to do before this, so that's my fault the drivers were broken. The majority of the .c changes is indenting and moving code around a bit. It affects no existing code, but allows the large backlog of 70+ patches that I already have created to start flowing into the different subtrees, instead of having to live in my driver-core tree, causing merge nightmares in linux-next for the next few months. These were finalized too late for the -rc1 merge window, which is why they were didn't make that pull request, testing and review from others didn't happen until a few weeks ago, and then there's the whole distraction of the past few days, which prevented these from getting to you sooner, sorry about that. Oh, and there's a bugfix for the documentation build warning in here as well. All of these have been in linux-next this week, with no reported problems" * tag 'driver-core-3.11-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core: driver-core: fix new kernel-doc warning in base/platform.c sysfs: use file mode defines from stat.h sysfs: add more helper macro's for (bin_)attribute(_groups) driver core: add default groups to struct class driver core: Introduce device_create_groups sysfs: prevent warning when only using binary attributes sysfs: add support for binary attributes in groups driver core: device.h: add RW and RO attribute macros sysfs.h: add BIN_ATTR macro sysfs.h: add ATTRIBUTE_GROUPS() macro sysfs.h: add __ATTR_RW() macro
Diffstat (limited to 'include')
-rw-r--r--include/linux/device.h37
-rw-r--r--include/linux/sysfs.h64
2 files changed, 84 insertions, 17 deletions
diff --git a/include/linux/device.h b/include/linux/device.h
index bcf8c0d4cd98..22b546a58591 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -47,7 +47,11 @@ struct bus_attribute {
47}; 47};
48 48
49#define BUS_ATTR(_name, _mode, _show, _store) \ 49#define BUS_ATTR(_name, _mode, _show, _store) \
50struct bus_attribute bus_attr_##_name = __ATTR(_name, _mode, _show, _store) 50 struct bus_attribute bus_attr_##_name = __ATTR(_name, _mode, _show, _store)
51#define BUS_ATTR_RW(_name) \
52 struct bus_attribute bus_attr_##_name = __ATTR_RW(_name)
53#define BUS_ATTR_RO(_name) \
54 struct bus_attribute bus_attr_##_name = __ATTR_RO(_name)
51 55
52extern int __must_check bus_create_file(struct bus_type *, 56extern int __must_check bus_create_file(struct bus_type *,
53 struct bus_attribute *); 57 struct bus_attribute *);
@@ -261,9 +265,12 @@ struct driver_attribute {
261 size_t count); 265 size_t count);
262}; 266};
263 267
264#define DRIVER_ATTR(_name, _mode, _show, _store) \ 268#define DRIVER_ATTR(_name, _mode, _show, _store) \
265struct driver_attribute driver_attr_##_name = \ 269 struct driver_attribute driver_attr_##_name = __ATTR(_name, _mode, _show, _store)
266 __ATTR(_name, _mode, _show, _store) 270#define DRIVER_ATTR_RW(_name) \
271 struct driver_attribute driver_attr_##_name = __ATTR_RW(_name)
272#define DRIVER_ATTR_RO(_name) \
273 struct driver_attribute driver_attr_##_name = __ATTR_RO(_name)
267 274
268extern int __must_check driver_create_file(struct device_driver *driver, 275extern int __must_check driver_create_file(struct device_driver *driver,
269 const struct driver_attribute *attr); 276 const struct driver_attribute *attr);
@@ -313,6 +320,7 @@ int subsys_virtual_register(struct bus_type *subsys,
313 * @name: Name of the class. 320 * @name: Name of the class.
314 * @owner: The module owner. 321 * @owner: The module owner.
315 * @class_attrs: Default attributes of this class. 322 * @class_attrs: Default attributes of this class.
323 * @dev_groups: Default attributes of the devices that belong to the class.
316 * @dev_attrs: Default attributes of the devices belong to the class. 324 * @dev_attrs: Default attributes of the devices belong to the class.
317 * @dev_bin_attrs: Default binary attributes of the devices belong to the class. 325 * @dev_bin_attrs: Default binary attributes of the devices belong to the class.
318 * @dev_kobj: The kobject that represents this class and links it into the hierarchy. 326 * @dev_kobj: The kobject that represents this class and links it into the hierarchy.
@@ -342,7 +350,8 @@ struct class {
342 struct module *owner; 350 struct module *owner;
343 351
344 struct class_attribute *class_attrs; 352 struct class_attribute *class_attrs;
345 struct device_attribute *dev_attrs; 353 struct device_attribute *dev_attrs; /* use dev_groups instead */
354 const struct attribute_group **dev_groups;
346 struct bin_attribute *dev_bin_attrs; 355 struct bin_attribute *dev_bin_attrs;
347 struct kobject *dev_kobj; 356 struct kobject *dev_kobj;
348 357
@@ -414,8 +423,12 @@ struct class_attribute {
414 const struct class_attribute *attr); 423 const struct class_attribute *attr);
415}; 424};
416 425
417#define CLASS_ATTR(_name, _mode, _show, _store) \ 426#define CLASS_ATTR(_name, _mode, _show, _store) \
418struct class_attribute class_attr_##_name = __ATTR(_name, _mode, _show, _store) 427 struct class_attribute class_attr_##_name = __ATTR(_name, _mode, _show, _store)
428#define CLASS_ATTR_RW(_name) \
429 struct class_attribute class_attr_##_name = __ATTR_RW(_name)
430#define CLASS_ATTR_RO(_name) \
431 struct class_attribute class_attr_##_name = __ATTR_RO(_name)
419 432
420extern int __must_check class_create_file(struct class *class, 433extern int __must_check class_create_file(struct class *class,
421 const struct class_attribute *attr); 434 const struct class_attribute *attr);
@@ -423,7 +436,6 @@ extern void class_remove_file(struct class *class,
423 const struct class_attribute *attr); 436 const struct class_attribute *attr);
424 437
425/* Simple class attribute that is just a static string */ 438/* Simple class attribute that is just a static string */
426
427struct class_attribute_string { 439struct class_attribute_string {
428 struct class_attribute attr; 440 struct class_attribute attr;
429 char *str; 441 char *str;
@@ -512,6 +524,10 @@ ssize_t device_store_bool(struct device *dev, struct device_attribute *attr,
512 524
513#define DEVICE_ATTR(_name, _mode, _show, _store) \ 525#define DEVICE_ATTR(_name, _mode, _show, _store) \
514 struct device_attribute dev_attr_##_name = __ATTR(_name, _mode, _show, _store) 526 struct device_attribute dev_attr_##_name = __ATTR(_name, _mode, _show, _store)
527#define DEVICE_ATTR_RW(_name) \
528 struct device_attribute dev_attr_##_name = __ATTR_RW(_name)
529#define DEVICE_ATTR_RO(_name) \
530 struct device_attribute dev_attr_##_name = __ATTR_RO(_name)
515#define DEVICE_ULONG_ATTR(_name, _mode, _var) \ 531#define DEVICE_ULONG_ATTR(_name, _mode, _var) \
516 struct dev_ext_attribute dev_attr_##_name = \ 532 struct dev_ext_attribute dev_attr_##_name = \
517 { __ATTR(_name, _mode, device_show_ulong, device_store_ulong), &(_var) } 533 { __ATTR(_name, _mode, device_show_ulong, device_store_ulong), &(_var) }
@@ -924,6 +940,11 @@ extern __printf(5, 6)
924struct device *device_create(struct class *cls, struct device *parent, 940struct device *device_create(struct class *cls, struct device *parent,
925 dev_t devt, void *drvdata, 941 dev_t devt, void *drvdata,
926 const char *fmt, ...); 942 const char *fmt, ...);
943extern __printf(6, 7)
944struct device *device_create_with_groups(struct class *cls,
945 struct device *parent, dev_t devt, void *drvdata,
946 const struct attribute_group **groups,
947 const char *fmt, ...);
927extern void device_destroy(struct class *cls, dev_t devt); 948extern void device_destroy(struct class *cls, dev_t devt);
928 949
929/* 950/*
diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
index e2cee22f578a..9e8a9b555ad6 100644
--- a/include/linux/sysfs.h
+++ b/include/linux/sysfs.h
@@ -17,10 +17,12 @@
17#include <linux/list.h> 17#include <linux/list.h>
18#include <linux/lockdep.h> 18#include <linux/lockdep.h>
19#include <linux/kobject_ns.h> 19#include <linux/kobject_ns.h>
20#include <linux/stat.h>
20#include <linux/atomic.h> 21#include <linux/atomic.h>
21 22
22struct kobject; 23struct kobject;
23struct module; 24struct module;
25struct bin_attribute;
24enum kobj_ns_type; 26enum kobj_ns_type;
25 27
26struct attribute { 28struct attribute {
@@ -59,26 +61,28 @@ struct attribute_group {
59 umode_t (*is_visible)(struct kobject *, 61 umode_t (*is_visible)(struct kobject *,
60 struct attribute *, int); 62 struct attribute *, int);
61 struct attribute **attrs; 63 struct attribute **attrs;
64 struct bin_attribute **bin_attrs;
62}; 65};
63 66
64
65
66/** 67/**
67 * Use these macros to make defining attributes easier. See include/linux/device.h 68 * Use these macros to make defining attributes easier. See include/linux/device.h
68 * for examples.. 69 * for examples..
69 */ 70 */
70 71
71#define __ATTR(_name,_mode,_show,_store) { \ 72#define __ATTR(_name,_mode,_show,_store) { \
72 .attr = {.name = __stringify(_name), .mode = _mode }, \ 73 .attr = {.name = __stringify(_name), .mode = _mode }, \
73 .show = _show, \ 74 .show = _show, \
74 .store = _store, \ 75 .store = _store, \
75} 76}
76 77
77#define __ATTR_RO(_name) { \ 78#define __ATTR_RO(_name) { \
78 .attr = { .name = __stringify(_name), .mode = 0444 }, \ 79 .attr = { .name = __stringify(_name), .mode = S_IRUGO }, \
79 .show = _name##_show, \ 80 .show = _name##_show, \
80} 81}
81 82
83#define __ATTR_RW(_name) __ATTR(_name, (S_IWUSR | S_IRUGO), \
84 _name##_show, _name##_store)
85
82#define __ATTR_NULL { .attr = { .name = NULL } } 86#define __ATTR_NULL { .attr = { .name = NULL } }
83 87
84#ifdef CONFIG_DEBUG_LOCK_ALLOC 88#ifdef CONFIG_DEBUG_LOCK_ALLOC
@@ -92,6 +96,18 @@ struct attribute_group {
92#define __ATTR_IGNORE_LOCKDEP __ATTR 96#define __ATTR_IGNORE_LOCKDEP __ATTR
93#endif 97#endif
94 98
99#define __ATTRIBUTE_GROUPS(_name) \
100static const struct attribute_group *_name##_groups[] = { \
101 &_name##_group, \
102 NULL, \
103}
104
105#define ATTRIBUTE_GROUPS(_name) \
106static const struct attribute_group _name##_group = { \
107 .attrs = _name##_attrs, \
108}; \
109__ATTRIBUTE_GROUPS(_name)
110
95#define attr_name(_attr) (_attr).attr.name 111#define attr_name(_attr) (_attr).attr.name
96 112
97struct file; 113struct file;
@@ -121,6 +137,36 @@ struct bin_attribute {
121 */ 137 */
122#define sysfs_bin_attr_init(bin_attr) sysfs_attr_init(&(bin_attr)->attr) 138#define sysfs_bin_attr_init(bin_attr) sysfs_attr_init(&(bin_attr)->attr)
123 139
140/* macros to create static binary attributes easier */
141#define __BIN_ATTR(_name, _mode, _read, _write, _size) { \
142 .attr = { .name = __stringify(_name), .mode = _mode }, \
143 .read = _read, \
144 .write = _write, \
145 .size = _size, \
146}
147
148#define __BIN_ATTR_RO(_name, _size) { \
149 .attr = { .name = __stringify(_name), .mode = S_IRUGO }, \
150 .read = _name##_read, \
151 .size = _size, \
152}
153
154#define __BIN_ATTR_RW(_name, _size) __BIN_ATTR(_name, \
155 (S_IWUSR | S_IRUGO), _name##_read, \
156 _name##_write)
157
158#define __BIN_ATTR_NULL __ATTR_NULL
159
160#define BIN_ATTR(_name, _mode, _read, _write, _size) \
161struct bin_attribute bin_attr_##_name = __BIN_ATTR(_name, _mode, _read, \
162 _write, _size)
163
164#define BIN_ATTR_RO(_name, _size) \
165struct bin_attribute bin_attr_##_name = __BIN_ATTR_RO(_name, _size)
166
167#define BIN_ATTR_RW(_name, _size) \
168struct bin_attribute bin_attr_##_name = __BIN_ATTR_RW(_name, _size)
169
124struct sysfs_ops { 170struct sysfs_ops {
125 ssize_t (*show)(struct kobject *, struct attribute *,char *); 171 ssize_t (*show)(struct kobject *, struct attribute *,char *);
126 ssize_t (*store)(struct kobject *,struct attribute *,const char *, size_t); 172 ssize_t (*store)(struct kobject *,struct attribute *,const char *, size_t);