aboutsummaryrefslogtreecommitdiffstats
path: root/net/core
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2013-09-03 14:37:15 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2013-09-03 14:37:15 -0400
commit542a086ac72fb193cbc1b996963a572269e57743 (patch)
treeb137c08037cca4ffc8a156a891a01113b3b8edce /net/core
parent1d1fdd95df681f0c065d90ffaafa215a0e8825e2 (diff)
parent1eeeef153c02f5856ec109fa532eb5f31c39f85c (diff)
Merge tag 'driver-core-3.12-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core
Pull driver core patches from Greg KH: "Here's the big driver core pull request for 3.12-rc1. Lots of tiny changes here fixing up the way sysfs attributes are created, to try to make drivers simpler, and fix a whole class race conditions with creations of device attributes after the device was announced to userspace. All the various pieces are acked by the different subsystem maintainers" * tag 'driver-core-3.12-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core: (119 commits) firmware loader: fix pending_fw_head list corruption drivers/base/memory.c: introduce help macro to_memory_block dynamic debug: line queries failing due to uninitialized local variable sysfs: sysfs_create_groups returns a value. debugfs: provide debugfs_create_x64() when disabled rbd: convert bus code to use bus_groups firmware: dcdbas: use binary attribute groups sysfs: add sysfs_create/remove_groups for when SYSFS is not enabled driver core: add #include <linux/sysfs.h> to core files. HID: convert bus code to use dev_groups Input: serio: convert bus code to use drv_groups Input: gameport: convert bus code to use drv_groups driver core: firmware: use __ATTR_RW() driver core: core: use DEVICE_ATTR_RO driver core: bus: use DRIVER_ATTR_WO() driver core: create write-only attribute macros for devices and drivers sysfs: create __ATTR_WO() driver-core: platform: convert bus code to use dev_groups workqueue: convert bus code to use dev_groups MEI: convert bus code to use dev_groups ...
Diffstat (limited to 'net/core')
-rw-r--r--net/core/net-sysfs.c136
1 files changed, 75 insertions, 61 deletions
diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
index 981fed397d1d..707c3134ddf2 100644
--- a/net/core/net-sysfs.c
+++ b/net/core/net-sysfs.c
@@ -60,12 +60,19 @@ static ssize_t format_##field(const struct net_device *net, char *buf) \
60{ \ 60{ \
61 return sprintf(buf, format_string, net->field); \ 61 return sprintf(buf, format_string, net->field); \
62} \ 62} \
63static ssize_t show_##field(struct device *dev, \ 63static ssize_t field##_show(struct device *dev, \
64 struct device_attribute *attr, char *buf) \ 64 struct device_attribute *attr, char *buf) \
65{ \ 65{ \
66 return netdev_show(dev, attr, buf, format_##field); \ 66 return netdev_show(dev, attr, buf, format_##field); \
67} 67} \
68
69#define NETDEVICE_SHOW_RO(field, format_string) \
70NETDEVICE_SHOW(field, format_string); \
71static DEVICE_ATTR_RO(field)
68 72
73#define NETDEVICE_SHOW_RW(field, format_string) \
74NETDEVICE_SHOW(field, format_string); \
75static DEVICE_ATTR_RW(field)
69 76
70/* use same locking and permission rules as SIF* ioctl's */ 77/* use same locking and permission rules as SIF* ioctl's */
71static ssize_t netdev_store(struct device *dev, struct device_attribute *attr, 78static ssize_t netdev_store(struct device *dev, struct device_attribute *attr,
@@ -96,16 +103,16 @@ static ssize_t netdev_store(struct device *dev, struct device_attribute *attr,
96 return ret; 103 return ret;
97} 104}
98 105
99NETDEVICE_SHOW(dev_id, fmt_hex); 106NETDEVICE_SHOW_RO(dev_id, fmt_hex);
100NETDEVICE_SHOW(addr_assign_type, fmt_dec); 107NETDEVICE_SHOW_RO(addr_assign_type, fmt_dec);
101NETDEVICE_SHOW(addr_len, fmt_dec); 108NETDEVICE_SHOW_RO(addr_len, fmt_dec);
102NETDEVICE_SHOW(iflink, fmt_dec); 109NETDEVICE_SHOW_RO(iflink, fmt_dec);
103NETDEVICE_SHOW(ifindex, fmt_dec); 110NETDEVICE_SHOW_RO(ifindex, fmt_dec);
104NETDEVICE_SHOW(type, fmt_dec); 111NETDEVICE_SHOW_RO(type, fmt_dec);
105NETDEVICE_SHOW(link_mode, fmt_dec); 112NETDEVICE_SHOW_RO(link_mode, fmt_dec);
106 113
107/* use same locking rules as GIFHWADDR ioctl's */ 114/* use same locking rules as GIFHWADDR ioctl's */
108static ssize_t show_address(struct device *dev, struct device_attribute *attr, 115static ssize_t address_show(struct device *dev, struct device_attribute *attr,
109 char *buf) 116 char *buf)
110{ 117{
111 struct net_device *net = to_net_dev(dev); 118 struct net_device *net = to_net_dev(dev);
@@ -117,15 +124,17 @@ static ssize_t show_address(struct device *dev, struct device_attribute *attr,
117 read_unlock(&dev_base_lock); 124 read_unlock(&dev_base_lock);
118 return ret; 125 return ret;
119} 126}
127static DEVICE_ATTR_RO(address);
120 128
121static ssize_t show_broadcast(struct device *dev, 129static ssize_t broadcast_show(struct device *dev,
122 struct device_attribute *attr, char *buf) 130 struct device_attribute *attr, char *buf)
123{ 131{
124 struct net_device *net = to_net_dev(dev); 132 struct net_device *net = to_net_dev(dev);
125 if (dev_isalive(net)) 133 if (dev_isalive(net))
126 return sysfs_format_mac(buf, net->broadcast, net->addr_len); 134 return sysfs_format_mac(buf, net->broadcast, net->addr_len);
127 return -EINVAL; 135 return -EINVAL;
128} 136}
137static DEVICE_ATTR_RO(broadcast);
129 138
130static int change_carrier(struct net_device *net, unsigned long new_carrier) 139static int change_carrier(struct net_device *net, unsigned long new_carrier)
131{ 140{
@@ -134,13 +143,13 @@ static int change_carrier(struct net_device *net, unsigned long new_carrier)
134 return dev_change_carrier(net, (bool) new_carrier); 143 return dev_change_carrier(net, (bool) new_carrier);
135} 144}
136 145
137static ssize_t store_carrier(struct device *dev, struct device_attribute *attr, 146static ssize_t carrier_store(struct device *dev, struct device_attribute *attr,
138 const char *buf, size_t len) 147 const char *buf, size_t len)
139{ 148{
140 return netdev_store(dev, attr, buf, len, change_carrier); 149 return netdev_store(dev, attr, buf, len, change_carrier);
141} 150}
142 151
143static ssize_t show_carrier(struct device *dev, 152static ssize_t carrier_show(struct device *dev,
144 struct device_attribute *attr, char *buf) 153 struct device_attribute *attr, char *buf)
145{ 154{
146 struct net_device *netdev = to_net_dev(dev); 155 struct net_device *netdev = to_net_dev(dev);
@@ -149,8 +158,9 @@ static ssize_t show_carrier(struct device *dev,
149 } 158 }
150 return -EINVAL; 159 return -EINVAL;
151} 160}
161static DEVICE_ATTR_RW(carrier);
152 162
153static ssize_t show_speed(struct device *dev, 163static ssize_t speed_show(struct device *dev,
154 struct device_attribute *attr, char *buf) 164 struct device_attribute *attr, char *buf)
155{ 165{
156 struct net_device *netdev = to_net_dev(dev); 166 struct net_device *netdev = to_net_dev(dev);
@@ -167,8 +177,9 @@ static ssize_t show_speed(struct device *dev,
167 rtnl_unlock(); 177 rtnl_unlock();
168 return ret; 178 return ret;
169} 179}
180static DEVICE_ATTR_RO(speed);
170 181
171static ssize_t show_duplex(struct device *dev, 182static ssize_t duplex_show(struct device *dev,
172 struct device_attribute *attr, char *buf) 183 struct device_attribute *attr, char *buf)
173{ 184{
174 struct net_device *netdev = to_net_dev(dev); 185 struct net_device *netdev = to_net_dev(dev);
@@ -198,8 +209,9 @@ static ssize_t show_duplex(struct device *dev,
198 rtnl_unlock(); 209 rtnl_unlock();
199 return ret; 210 return ret;
200} 211}
212static DEVICE_ATTR_RO(duplex);
201 213
202static ssize_t show_dormant(struct device *dev, 214static ssize_t dormant_show(struct device *dev,
203 struct device_attribute *attr, char *buf) 215 struct device_attribute *attr, char *buf)
204{ 216{
205 struct net_device *netdev = to_net_dev(dev); 217 struct net_device *netdev = to_net_dev(dev);
@@ -209,6 +221,7 @@ static ssize_t show_dormant(struct device *dev,
209 221
210 return -EINVAL; 222 return -EINVAL;
211} 223}
224static DEVICE_ATTR_RO(dormant);
212 225
213static const char *const operstates[] = { 226static const char *const operstates[] = {
214 "unknown", 227 "unknown",
@@ -220,7 +233,7 @@ static const char *const operstates[] = {
220 "up" 233 "up"
221}; 234};
222 235
223static ssize_t show_operstate(struct device *dev, 236static ssize_t operstate_show(struct device *dev,
224 struct device_attribute *attr, char *buf) 237 struct device_attribute *attr, char *buf)
225{ 238{
226 const struct net_device *netdev = to_net_dev(dev); 239 const struct net_device *netdev = to_net_dev(dev);
@@ -237,35 +250,33 @@ static ssize_t show_operstate(struct device *dev,
237 250
238 return sprintf(buf, "%s\n", operstates[operstate]); 251 return sprintf(buf, "%s\n", operstates[operstate]);
239} 252}
253static DEVICE_ATTR_RO(operstate);
240 254
241/* read-write attributes */ 255/* read-write attributes */
242NETDEVICE_SHOW(mtu, fmt_dec);
243 256
244static int change_mtu(struct net_device *net, unsigned long new_mtu) 257static int change_mtu(struct net_device *net, unsigned long new_mtu)
245{ 258{
246 return dev_set_mtu(net, (int) new_mtu); 259 return dev_set_mtu(net, (int) new_mtu);
247} 260}
248 261
249static ssize_t store_mtu(struct device *dev, struct device_attribute *attr, 262static ssize_t mtu_store(struct device *dev, struct device_attribute *attr,
250 const char *buf, size_t len) 263 const char *buf, size_t len)
251{ 264{
252 return netdev_store(dev, attr, buf, len, change_mtu); 265 return netdev_store(dev, attr, buf, len, change_mtu);
253} 266}
254 267NETDEVICE_SHOW_RW(mtu, fmt_dec);
255NETDEVICE_SHOW(flags, fmt_hex);
256 268
257static int change_flags(struct net_device *net, unsigned long new_flags) 269static int change_flags(struct net_device *net, unsigned long new_flags)
258{ 270{
259 return dev_change_flags(net, (unsigned int) new_flags); 271 return dev_change_flags(net, (unsigned int) new_flags);
260} 272}
261 273
262static ssize_t store_flags(struct device *dev, struct device_attribute *attr, 274static ssize_t flags_store(struct device *dev, struct device_attribute *attr,
263 const char *buf, size_t len) 275 const char *buf, size_t len)
264{ 276{
265 return netdev_store(dev, attr, buf, len, change_flags); 277 return netdev_store(dev, attr, buf, len, change_flags);
266} 278}
267 279NETDEVICE_SHOW_RW(flags, fmt_hex);
268NETDEVICE_SHOW(tx_queue_len, fmt_ulong);
269 280
270static int change_tx_queue_len(struct net_device *net, unsigned long new_len) 281static int change_tx_queue_len(struct net_device *net, unsigned long new_len)
271{ 282{
@@ -273,7 +284,7 @@ static int change_tx_queue_len(struct net_device *net, unsigned long new_len)
273 return 0; 284 return 0;
274} 285}
275 286
276static ssize_t store_tx_queue_len(struct device *dev, 287static ssize_t tx_queue_len_store(struct device *dev,
277 struct device_attribute *attr, 288 struct device_attribute *attr,
278 const char *buf, size_t len) 289 const char *buf, size_t len)
279{ 290{
@@ -282,8 +293,9 @@ static ssize_t store_tx_queue_len(struct device *dev,
282 293
283 return netdev_store(dev, attr, buf, len, change_tx_queue_len); 294 return netdev_store(dev, attr, buf, len, change_tx_queue_len);
284} 295}
296NETDEVICE_SHOW_RW(tx_queue_len, fmt_ulong);
285 297
286static ssize_t store_ifalias(struct device *dev, struct device_attribute *attr, 298static ssize_t ifalias_store(struct device *dev, struct device_attribute *attr,
287 const char *buf, size_t len) 299 const char *buf, size_t len)
288{ 300{
289 struct net_device *netdev = to_net_dev(dev); 301 struct net_device *netdev = to_net_dev(dev);
@@ -306,7 +318,7 @@ static ssize_t store_ifalias(struct device *dev, struct device_attribute *attr,
306 return ret < 0 ? ret : len; 318 return ret < 0 ? ret : len;
307} 319}
308 320
309static ssize_t show_ifalias(struct device *dev, 321static ssize_t ifalias_show(struct device *dev,
310 struct device_attribute *attr, char *buf) 322 struct device_attribute *attr, char *buf)
311{ 323{
312 const struct net_device *netdev = to_net_dev(dev); 324 const struct net_device *netdev = to_net_dev(dev);
@@ -319,8 +331,7 @@ static ssize_t show_ifalias(struct device *dev,
319 rtnl_unlock(); 331 rtnl_unlock();
320 return ret; 332 return ret;
321} 333}
322 334static DEVICE_ATTR_RW(ifalias);
323NETDEVICE_SHOW(group, fmt_dec);
324 335
325static int change_group(struct net_device *net, unsigned long new_group) 336static int change_group(struct net_device *net, unsigned long new_group)
326{ 337{
@@ -328,35 +339,37 @@ static int change_group(struct net_device *net, unsigned long new_group)
328 return 0; 339 return 0;
329} 340}
330 341
331static ssize_t store_group(struct device *dev, struct device_attribute *attr, 342static ssize_t group_store(struct device *dev, struct device_attribute *attr,
332 const char *buf, size_t len) 343 const char *buf, size_t len)
333{ 344{
334 return netdev_store(dev, attr, buf, len, change_group); 345 return netdev_store(dev, attr, buf, len, change_group);
335} 346}
336 347NETDEVICE_SHOW(group, fmt_dec);
337static struct device_attribute net_class_attributes[] = { 348static DEVICE_ATTR(netdev_group, S_IRUGO | S_IWUSR, group_show, group_store);
338 __ATTR(addr_assign_type, S_IRUGO, show_addr_assign_type, NULL), 349
339 __ATTR(addr_len, S_IRUGO, show_addr_len, NULL), 350static struct attribute *net_class_attrs[] = {
340 __ATTR(dev_id, S_IRUGO, show_dev_id, NULL), 351 &dev_attr_netdev_group.attr,
341 __ATTR(ifalias, S_IRUGO | S_IWUSR, show_ifalias, store_ifalias), 352 &dev_attr_type.attr,
342 __ATTR(iflink, S_IRUGO, show_iflink, NULL), 353 &dev_attr_dev_id.attr,
343 __ATTR(ifindex, S_IRUGO, show_ifindex, NULL), 354 &dev_attr_iflink.attr,
344 __ATTR(type, S_IRUGO, show_type, NULL), 355 &dev_attr_ifindex.attr,
345 __ATTR(link_mode, S_IRUGO, show_link_mode, NULL), 356 &dev_attr_addr_assign_type.attr,
346 __ATTR(address, S_IRUGO, show_address, NULL), 357 &dev_attr_addr_len.attr,
347 __ATTR(broadcast, S_IRUGO, show_broadcast, NULL), 358 &dev_attr_link_mode.attr,
348 __ATTR(carrier, S_IRUGO | S_IWUSR, show_carrier, store_carrier), 359 &dev_attr_address.attr,
349 __ATTR(speed, S_IRUGO, show_speed, NULL), 360 &dev_attr_broadcast.attr,
350 __ATTR(duplex, S_IRUGO, show_duplex, NULL), 361 &dev_attr_speed.attr,
351 __ATTR(dormant, S_IRUGO, show_dormant, NULL), 362 &dev_attr_duplex.attr,
352 __ATTR(operstate, S_IRUGO, show_operstate, NULL), 363 &dev_attr_dormant.attr,
353 __ATTR(mtu, S_IRUGO | S_IWUSR, show_mtu, store_mtu), 364 &dev_attr_operstate.attr,
354 __ATTR(flags, S_IRUGO | S_IWUSR, show_flags, store_flags), 365 &dev_attr_ifalias.attr,
355 __ATTR(tx_queue_len, S_IRUGO | S_IWUSR, show_tx_queue_len, 366 &dev_attr_carrier.attr,
356 store_tx_queue_len), 367 &dev_attr_mtu.attr,
357 __ATTR(netdev_group, S_IRUGO | S_IWUSR, show_group, store_group), 368 &dev_attr_flags.attr,
358 {} 369 &dev_attr_tx_queue_len.attr,
370 NULL,
359}; 371};
372ATTRIBUTE_GROUPS(net_class);
360 373
361/* Show a given an attribute in the statistics group */ 374/* Show a given an attribute in the statistics group */
362static ssize_t netstat_show(const struct device *d, 375static ssize_t netstat_show(const struct device *d,
@@ -382,13 +395,13 @@ static ssize_t netstat_show(const struct device *d,
382 395
383/* generate a read-only statistics attribute */ 396/* generate a read-only statistics attribute */
384#define NETSTAT_ENTRY(name) \ 397#define NETSTAT_ENTRY(name) \
385static ssize_t show_##name(struct device *d, \ 398static ssize_t name##_show(struct device *d, \
386 struct device_attribute *attr, char *buf) \ 399 struct device_attribute *attr, char *buf) \
387{ \ 400{ \
388 return netstat_show(d, attr, buf, \ 401 return netstat_show(d, attr, buf, \
389 offsetof(struct rtnl_link_stats64, name)); \ 402 offsetof(struct rtnl_link_stats64, name)); \
390} \ 403} \
391static DEVICE_ATTR(name, S_IRUGO, show_##name, NULL) 404static DEVICE_ATTR_RO(name)
392 405
393NETSTAT_ENTRY(rx_packets); 406NETSTAT_ENTRY(rx_packets);
394NETSTAT_ENTRY(tx_packets); 407NETSTAT_ENTRY(tx_packets);
@@ -457,6 +470,9 @@ static struct attribute_group wireless_group = {
457 .attrs = wireless_attrs, 470 .attrs = wireless_attrs,
458}; 471};
459#endif 472#endif
473
474#else /* CONFIG_SYSFS */
475#define net_class_groups NULL
460#endif /* CONFIG_SYSFS */ 476#endif /* CONFIG_SYSFS */
461 477
462#ifdef CONFIG_RPS 478#ifdef CONFIG_RPS
@@ -1229,9 +1245,7 @@ static const void *net_namespace(struct device *d)
1229static struct class net_class = { 1245static struct class net_class = {
1230 .name = "net", 1246 .name = "net",
1231 .dev_release = netdev_release, 1247 .dev_release = netdev_release,
1232#ifdef CONFIG_SYSFS 1248 .dev_groups = net_class_groups,
1233 .dev_attrs = net_class_attributes,
1234#endif /* CONFIG_SYSFS */
1235 .dev_uevent = netdev_uevent, 1249 .dev_uevent = netdev_uevent,
1236 .ns_type = &net_ns_type_operations, 1250 .ns_type = &net_ns_type_operations,
1237 .namespace = net_namespace, 1251 .namespace = net_namespace,