Skip to content
Snippets Groups Projects
Commit a5eb71b2 authored by Wolfram Sang's avatar Wolfram Sang
Browse files

i2c: simplify boilerplate code for attribute groups


Declaring attribute groups can be done with macros these days, let's use
them for consistency and readability reasons. Also, put the ATTR macros
directly below the referenced functions while we are here.

Signed-off-by: default avatarWolfram Sang <wsa@the-dreams.de>
parent 90ebd0eb
No related branches found
No related tags found
No related merge requests found
...@@ -709,6 +709,7 @@ show_name(struct device *dev, struct device_attribute *attr, char *buf) ...@@ -709,6 +709,7 @@ show_name(struct device *dev, struct device_attribute *attr, char *buf)
return sprintf(buf, "%s\n", dev->type == &i2c_client_type ? return sprintf(buf, "%s\n", dev->type == &i2c_client_type ?
to_i2c_client(dev)->name : to_i2c_adapter(dev)->name); to_i2c_client(dev)->name : to_i2c_adapter(dev)->name);
} }
static DEVICE_ATTR(name, S_IRUGO, show_name, NULL);
static ssize_t static ssize_t
show_modalias(struct device *dev, struct device_attribute *attr, char *buf) show_modalias(struct device *dev, struct device_attribute *attr, char *buf)
...@@ -722,8 +723,6 @@ show_modalias(struct device *dev, struct device_attribute *attr, char *buf) ...@@ -722,8 +723,6 @@ show_modalias(struct device *dev, struct device_attribute *attr, char *buf)
return sprintf(buf, "%s%s\n", I2C_MODULE_PREFIX, client->name); return sprintf(buf, "%s%s\n", I2C_MODULE_PREFIX, client->name);
} }
static DEVICE_ATTR(name, S_IRUGO, show_name, NULL);
static DEVICE_ATTR(modalias, S_IRUGO, show_modalias, NULL); static DEVICE_ATTR(modalias, S_IRUGO, show_modalias, NULL);
static struct attribute *i2c_dev_attrs[] = { static struct attribute *i2c_dev_attrs[] = {
...@@ -732,15 +731,7 @@ static struct attribute *i2c_dev_attrs[] = { ...@@ -732,15 +731,7 @@ static struct attribute *i2c_dev_attrs[] = {
&dev_attr_modalias.attr, &dev_attr_modalias.attr,
NULL NULL
}; };
ATTRIBUTE_GROUPS(i2c_dev);
static struct attribute_group i2c_dev_attr_group = {
.attrs = i2c_dev_attrs,
};
static const struct attribute_group *i2c_dev_attr_groups[] = {
&i2c_dev_attr_group,
NULL
};
struct bus_type i2c_bus_type = { struct bus_type i2c_bus_type = {
.name = "i2c", .name = "i2c",
...@@ -752,7 +743,7 @@ struct bus_type i2c_bus_type = { ...@@ -752,7 +743,7 @@ struct bus_type i2c_bus_type = {
EXPORT_SYMBOL_GPL(i2c_bus_type); EXPORT_SYMBOL_GPL(i2c_bus_type);
static struct device_type i2c_client_type = { static struct device_type i2c_client_type = {
.groups = i2c_dev_attr_groups, .groups = i2c_dev_groups,
.uevent = i2c_device_uevent, .uevent = i2c_device_uevent,
.release = i2c_client_dev_release, .release = i2c_client_dev_release,
}; };
...@@ -1151,6 +1142,7 @@ i2c_sysfs_new_device(struct device *dev, struct device_attribute *attr, ...@@ -1151,6 +1142,7 @@ i2c_sysfs_new_device(struct device *dev, struct device_attribute *attr,
return count; return count;
} }
static DEVICE_ATTR(new_device, S_IWUSR, NULL, i2c_sysfs_new_device);
/* /*
* And of course let the users delete the devices they instantiated, if * And of course let the users delete the devices they instantiated, if
...@@ -1205,8 +1197,6 @@ i2c_sysfs_delete_device(struct device *dev, struct device_attribute *attr, ...@@ -1205,8 +1197,6 @@ i2c_sysfs_delete_device(struct device *dev, struct device_attribute *attr,
"delete_device"); "delete_device");
return res; return res;
} }
static DEVICE_ATTR(new_device, S_IWUSR, NULL, i2c_sysfs_new_device);
static DEVICE_ATTR_IGNORE_LOCKDEP(delete_device, S_IWUSR, NULL, static DEVICE_ATTR_IGNORE_LOCKDEP(delete_device, S_IWUSR, NULL,
i2c_sysfs_delete_device); i2c_sysfs_delete_device);
...@@ -1216,18 +1206,10 @@ static struct attribute *i2c_adapter_attrs[] = { ...@@ -1216,18 +1206,10 @@ static struct attribute *i2c_adapter_attrs[] = {
&dev_attr_delete_device.attr, &dev_attr_delete_device.attr,
NULL NULL
}; };
ATTRIBUTE_GROUPS(i2c_adapter);
static struct attribute_group i2c_adapter_attr_group = {
.attrs = i2c_adapter_attrs,
};
static const struct attribute_group *i2c_adapter_attr_groups[] = {
&i2c_adapter_attr_group,
NULL
};
struct device_type i2c_adapter_type = { struct device_type i2c_adapter_type = {
.groups = i2c_adapter_attr_groups, .groups = i2c_adapter_groups,
.release = i2c_adapter_dev_release, .release = i2c_adapter_dev_release,
}; };
EXPORT_SYMBOL_GPL(i2c_adapter_type); EXPORT_SYMBOL_GPL(i2c_adapter_type);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment