提交 c5e064a6 编写于 作者: G Greg Kroah-Hartman

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: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
上级 2581c9cc
...@@ -345,7 +345,7 @@ static const struct kset_uevent_ops device_uevent_ops = { ...@@ -345,7 +345,7 @@ static const struct kset_uevent_ops device_uevent_ops = {
.uevent = dev_uevent, .uevent = dev_uevent,
}; };
static ssize_t show_uevent(struct device *dev, struct device_attribute *attr, static ssize_t uevent_show(struct device *dev, struct device_attribute *attr,
char *buf) char *buf)
{ {
struct kobject *top_kobj; struct kobject *top_kobj;
...@@ -388,7 +388,7 @@ static ssize_t show_uevent(struct device *dev, struct device_attribute *attr, ...@@ -388,7 +388,7 @@ static ssize_t show_uevent(struct device *dev, struct device_attribute *attr,
return count; return count;
} }
static ssize_t store_uevent(struct device *dev, struct device_attribute *attr, static ssize_t uevent_store(struct device *dev, struct device_attribute *attr,
const char *buf, size_t count) const char *buf, size_t count)
{ {
enum kobject_action action; enum kobject_action action;
...@@ -399,11 +399,9 @@ static ssize_t store_uevent(struct device *dev, struct device_attribute *attr, ...@@ -399,11 +399,9 @@ static ssize_t store_uevent(struct device *dev, struct device_attribute *attr,
dev_err(dev, "uevent: unknown action-string\n"); dev_err(dev, "uevent: unknown action-string\n");
return count; return count;
} }
static DEVICE_ATTR_RW(uevent);
static struct device_attribute uevent_attr = static ssize_t online_show(struct device *dev, struct device_attribute *attr,
__ATTR(uevent, S_IRUGO | S_IWUSR, show_uevent, store_uevent);
static ssize_t show_online(struct device *dev, struct device_attribute *attr,
char *buf) char *buf)
{ {
bool val; bool val;
...@@ -414,7 +412,7 @@ static ssize_t show_online(struct device *dev, struct device_attribute *attr, ...@@ -414,7 +412,7 @@ static ssize_t show_online(struct device *dev, struct device_attribute *attr,
return sprintf(buf, "%u\n", val); return sprintf(buf, "%u\n", val);
} }
static ssize_t store_online(struct device *dev, struct device_attribute *attr, static ssize_t online_store(struct device *dev, struct device_attribute *attr,
const char *buf, size_t count) const char *buf, size_t count)
{ {
bool val; bool val;
...@@ -429,9 +427,7 @@ static ssize_t store_online(struct device *dev, struct device_attribute *attr, ...@@ -429,9 +427,7 @@ static ssize_t store_online(struct device *dev, struct device_attribute *attr,
unlock_device_hotplug(); unlock_device_hotplug();
return ret < 0 ? ret : count; return ret < 0 ? ret : count;
} }
static DEVICE_ATTR_RW(online);
static struct device_attribute online_attr =
__ATTR(online, S_IRUGO | S_IWUSR, show_online, store_online);
static int device_add_attributes(struct device *dev, static int device_add_attributes(struct device *dev,
struct device_attribute *attrs) struct device_attribute *attrs)
...@@ -531,7 +527,7 @@ static int device_add_attrs(struct device *dev) ...@@ -531,7 +527,7 @@ static int device_add_attrs(struct device *dev)
goto err_remove_type_groups; goto err_remove_type_groups;
if (device_supports_offline(dev) && !dev->offline_disabled) { if (device_supports_offline(dev) && !dev->offline_disabled) {
error = device_create_file(dev, &online_attr); error = device_create_file(dev, &dev_attr_online);
if (error) if (error)
goto err_remove_type_groups; goto err_remove_type_groups;
} }
...@@ -559,7 +555,7 @@ static void device_remove_attrs(struct device *dev) ...@@ -559,7 +555,7 @@ static void device_remove_attrs(struct device *dev)
struct class *class = dev->class; struct class *class = dev->class;
const struct device_type *type = dev->type; const struct device_type *type = dev->type;
device_remove_file(dev, &online_attr); device_remove_file(dev, &dev_attr_online);
device_remove_groups(dev, dev->groups); device_remove_groups(dev, dev->groups);
if (type) if (type)
...@@ -572,15 +568,12 @@ static void device_remove_attrs(struct device *dev) ...@@ -572,15 +568,12 @@ static void device_remove_attrs(struct device *dev)
} }
} }
static ssize_t dev_show(struct device *dev, struct device_attribute *attr,
static ssize_t show_dev(struct device *dev, struct device_attribute *attr,
char *buf) char *buf)
{ {
return print_dev_t(buf, dev->devt); return print_dev_t(buf, dev->devt);
} }
static DEVICE_ATTR_RO(dev);
static struct device_attribute devt_attr =
__ATTR(dev, S_IRUGO, show_dev, NULL);
/* /sys/devices/ */ /* /sys/devices/ */
struct kset *devices_kset; struct kset *devices_kset;
...@@ -1084,12 +1077,12 @@ int device_add(struct device *dev) ...@@ -1084,12 +1077,12 @@ int device_add(struct device *dev)
if (platform_notify) if (platform_notify)
platform_notify(dev); platform_notify(dev);
error = device_create_file(dev, &uevent_attr); error = device_create_file(dev, &dev_attr_uevent);
if (error) if (error)
goto attrError; goto attrError;
if (MAJOR(dev->devt)) { if (MAJOR(dev->devt)) {
error = device_create_file(dev, &devt_attr); error = device_create_file(dev, &dev_attr_dev);
if (error) if (error)
goto ueventattrError; goto ueventattrError;
...@@ -1156,9 +1149,9 @@ int device_add(struct device *dev) ...@@ -1156,9 +1149,9 @@ int device_add(struct device *dev)
device_remove_sys_dev_entry(dev); device_remove_sys_dev_entry(dev);
devtattrError: devtattrError:
if (MAJOR(dev->devt)) if (MAJOR(dev->devt))
device_remove_file(dev, &devt_attr); device_remove_file(dev, &dev_attr_dev);
ueventattrError: ueventattrError:
device_remove_file(dev, &uevent_attr); device_remove_file(dev, &dev_attr_uevent);
attrError: attrError:
kobject_uevent(&dev->kobj, KOBJ_REMOVE); kobject_uevent(&dev->kobj, KOBJ_REMOVE);
kobject_del(&dev->kobj); kobject_del(&dev->kobj);
...@@ -1254,7 +1247,7 @@ void device_del(struct device *dev) ...@@ -1254,7 +1247,7 @@ void device_del(struct device *dev)
if (MAJOR(dev->devt)) { if (MAJOR(dev->devt)) {
devtmpfs_delete_node(dev); devtmpfs_delete_node(dev);
device_remove_sys_dev_entry(dev); device_remove_sys_dev_entry(dev);
device_remove_file(dev, &devt_attr); device_remove_file(dev, &dev_attr_dev);
} }
if (dev->class) { if (dev->class) {
device_remove_class_symlinks(dev); device_remove_class_symlinks(dev);
...@@ -1269,7 +1262,7 @@ void device_del(struct device *dev) ...@@ -1269,7 +1262,7 @@ void device_del(struct device *dev)
klist_del(&dev->knode_class); klist_del(&dev->knode_class);
mutex_unlock(&dev->class->p->mutex); mutex_unlock(&dev->class->p->mutex);
} }
device_remove_file(dev, &uevent_attr); device_remove_file(dev, &dev_attr_uevent);
device_remove_attrs(dev); device_remove_attrs(dev);
bus_remove_device(dev); bus_remove_device(dev);
device_pm_remove(dev); device_pm_remove(dev);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册