aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/base
diff options
context:
space:
mode:
authorGreg Kroah-Hartman <gregkh@linuxfoundation.org>2013-08-23 20:07:26 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2013-08-23 20:07:26 -0400
commitc5e064a6981603de65c61c4989856e984c7ad66d (patch)
tree723a699b6fe163c2769e99de107b5802413c174e /drivers/base
parent2581c9cc0de6eeba8d5553c98aab6e0f75d184e0 (diff)
driver core: core: use DEVICE_ATTR_RO
Use DEVICE_ATTR_RO() instead of a "raw" __ATTR macro, making it easier to audit exactly what is going on with the sysfs files. Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/base')
-rw-r--r--drivers/base/core.c39
1 files changed, 16 insertions, 23 deletions
diff --git a/drivers/base/core.c b/drivers/base/core.c
index ae1acdf21bd3..921b94184dcc 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -345,7 +345,7 @@ static const struct kset_uevent_ops device_uevent_ops = {
345 .uevent = dev_uevent, 345 .uevent = dev_uevent,
346}; 346};
347 347
348static ssize_t show_uevent(struct device *dev, struct device_attribute *attr, 348static ssize_t uevent_show(struct device *dev, struct device_attribute *attr,
349 char *buf) 349 char *buf)
350{ 350{
351 struct kobject *top_kobj; 351 struct kobject *top_kobj;
@@ -388,7 +388,7 @@ out:
388 return count; 388 return count;
389} 389}
390 390
391static ssize_t store_uevent(struct device *dev, struct device_attribute *attr, 391static ssize_t uevent_store(struct device *dev, struct device_attribute *attr,
392 const char *buf, size_t count) 392 const char *buf, size_t count)
393{ 393{
394 enum kobject_action action; 394 enum kobject_action action;
@@ -399,11 +399,9 @@ static ssize_t store_uevent(struct device *dev, struct device_attribute *attr,
399 dev_err(dev, "uevent: unknown action-string\n"); 399 dev_err(dev, "uevent: unknown action-string\n");
400 return count; 400 return count;
401} 401}
402static DEVICE_ATTR_RW(uevent);
402 403
403static struct device_attribute uevent_attr = 404static ssize_t online_show(struct device *dev, struct device_attribute *attr,
404 __ATTR(uevent, S_IRUGO | S_IWUSR, show_uevent, store_uevent);
405
406static ssize_t show_online(struct device *dev, struct device_attribute *attr,
407 char *buf) 405 char *buf)
408{ 406{
409 bool val; 407 bool val;
@@ -414,7 +412,7 @@ static ssize_t show_online(struct device *dev, struct device_attribute *attr,
414 return sprintf(buf, "%u\n", val); 412 return sprintf(buf, "%u\n", val);
415} 413}
416 414
417static ssize_t store_online(struct device *dev, struct device_attribute *attr, 415static ssize_t online_store(struct device *dev, struct device_attribute *attr,
418 const char *buf, size_t count) 416 const char *buf, size_t count)
419{ 417{
420 bool val; 418 bool val;
@@ -429,9 +427,7 @@ static ssize_t store_online(struct device *dev, struct device_attribute *attr,
429 unlock_device_hotplug(); 427 unlock_device_hotplug();
430 return ret < 0 ? ret : count; 428 return ret < 0 ? ret : count;
431} 429}
432 430static DEVICE_ATTR_RW(online);
433static struct device_attribute online_attr =
434 __ATTR(online, S_IRUGO | S_IWUSR, show_online, store_online);
435 431
436static int device_add_attributes(struct device *dev, 432static int device_add_attributes(struct device *dev,
437 struct device_attribute *attrs) 433 struct device_attribute *attrs)
@@ -531,7 +527,7 @@ static int device_add_attrs(struct device *dev)
531 goto err_remove_type_groups; 527 goto err_remove_type_groups;
532 528
533 if (device_supports_offline(dev) && !dev->offline_disabled) { 529 if (device_supports_offline(dev) && !dev->offline_disabled) {
534 error = device_create_file(dev, &online_attr); 530 error = device_create_file(dev, &dev_attr_online);
535 if (error) 531 if (error)
536 goto err_remove_type_groups; 532 goto err_remove_type_groups;
537 } 533 }
@@ -559,7 +555,7 @@ static void device_remove_attrs(struct device *dev)
559 struct class *class = dev->class; 555 struct class *class = dev->class;
560 const struct device_type *type = dev->type; 556 const struct device_type *type = dev->type;
561 557
562 device_remove_file(dev, &online_attr); 558 device_remove_file(dev, &dev_attr_online);
563 device_remove_groups(dev, dev->groups); 559 device_remove_groups(dev, dev->groups);
564 560
565 if (type) 561 if (type)
@@ -572,15 +568,12 @@ static void device_remove_attrs(struct device *dev)
572 } 568 }
573} 569}
574 570
575 571static ssize_t dev_show(struct device *dev, struct device_attribute *attr,
576static ssize_t show_dev(struct device *dev, struct device_attribute *attr,
577 char *buf) 572 char *buf)
578{ 573{
579 return print_dev_t(buf, dev->devt); 574 return print_dev_t(buf, dev->devt);
580} 575}
581 576static DEVICE_ATTR_RO(dev);
582static struct device_attribute devt_attr =
583 __ATTR(dev, S_IRUGO, show_dev, NULL);
584 577
585/* /sys/devices/ */ 578/* /sys/devices/ */
586struct kset *devices_kset; 579struct kset *devices_kset;
@@ -1084,12 +1077,12 @@ int device_add(struct device *dev)
1084 if (platform_notify) 1077 if (platform_notify)
1085 platform_notify(dev); 1078 platform_notify(dev);
1086 1079
1087 error = device_create_file(dev, &uevent_attr); 1080 error = device_create_file(dev, &dev_attr_uevent);
1088 if (error) 1081 if (error)
1089 goto attrError; 1082 goto attrError;
1090 1083
1091 if (MAJOR(dev->devt)) { 1084 if (MAJOR(dev->devt)) {
1092 error = device_create_file(dev, &devt_attr); 1085 error = device_create_file(dev, &dev_attr_dev);
1093 if (error) 1086 if (error)
1094 goto ueventattrError; 1087 goto ueventattrError;
1095 1088
@@ -1156,9 +1149,9 @@ done:
1156 device_remove_sys_dev_entry(dev); 1149 device_remove_sys_dev_entry(dev);
1157 devtattrError: 1150 devtattrError:
1158 if (MAJOR(dev->devt)) 1151 if (MAJOR(dev->devt))
1159 device_remove_file(dev, &devt_attr); 1152 device_remove_file(dev, &dev_attr_dev);
1160 ueventattrError: 1153 ueventattrError:
1161 device_remove_file(dev, &uevent_attr); 1154 device_remove_file(dev, &dev_attr_uevent);
1162 attrError: 1155 attrError:
1163 kobject_uevent(&dev->kobj, KOBJ_REMOVE); 1156 kobject_uevent(&dev->kobj, KOBJ_REMOVE);
1164 kobject_del(&dev->kobj); 1157 kobject_del(&dev->kobj);
@@ -1254,7 +1247,7 @@ void device_del(struct device *dev)
1254 if (MAJOR(dev->devt)) { 1247 if (MAJOR(dev->devt)) {
1255 devtmpfs_delete_node(dev); 1248 devtmpfs_delete_node(dev);
1256 device_remove_sys_dev_entry(dev); 1249 device_remove_sys_dev_entry(dev);
1257 device_remove_file(dev, &devt_attr); 1250 device_remove_file(dev, &dev_attr_dev);
1258 } 1251 }
1259 if (dev->class) { 1252 if (dev->class) {
1260 device_remove_class_symlinks(dev); 1253 device_remove_class_symlinks(dev);
@@ -1269,7 +1262,7 @@ void device_del(struct device *dev)
1269 klist_del(&dev->knode_class); 1262 klist_del(&dev->knode_class);
1270 mutex_unlock(&dev->class->p->mutex); 1263 mutex_unlock(&dev->class->p->mutex);
1271 } 1264 }
1272 device_remove_file(dev, &uevent_attr); 1265 device_remove_file(dev, &dev_attr_uevent);
1273 device_remove_attrs(dev); 1266 device_remove_attrs(dev);
1274 bus_remove_device(dev); 1267 bus_remove_device(dev);
1275 device_pm_remove(dev); 1268 device_pm_remove(dev);