The __iio_device_attr_init() function initializes a device_attribute
object, but mostly it just does a lot of name creation logic.
We will want to re-use this logic for name-creation, so this change
re-purposes the __iio_device_attr_init() to be a __iio_attr_init() function
which just handles the creation of the attribute name.
Signed-off-by: Alexandru Ardelean <[email protected]>
---
Changelog v1 -> v2:
* https://lore.kernel.org/linux-iio/[email protected]/
* split away from series; I don't know when I will have time to re-visit
the entire original series, so might as well move forward a few patches
drivers/iio/industrialio-core.c | 43 +++++++++++++--------------------
1 file changed, 17 insertions(+), 26 deletions(-)
diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
index 1da7e518435a..5bfcee277879 100644
--- a/drivers/iio/industrialio-core.c
+++ b/drivers/iio/industrialio-core.c
@@ -935,22 +935,15 @@ static ssize_t iio_write_channel_info(struct device *dev,
}
static
-int __iio_device_attr_init(struct device_attribute *dev_attr,
- const char *postfix,
- struct iio_chan_spec const *chan,
- ssize_t (*readfunc)(struct device *dev,
- struct device_attribute *attr,
- char *buf),
- ssize_t (*writefunc)(struct device *dev,
- struct device_attribute *attr,
- const char *buf,
- size_t len),
- enum iio_shared_by shared_by)
+int iio_attr_init(struct attribute *attr,
+ const char *postfix,
+ struct iio_chan_spec const *chan,
+ enum iio_shared_by shared_by)
{
int ret = 0;
char *name = NULL;
char *full_postfix;
- sysfs_attr_init(&dev_attr->attr);
+ sysfs_attr_init(attr);
/* Build up postfix of <extend_name>_<modifier>_postfix */
if (chan->modified && (shared_by == IIO_SEPARATE)) {
@@ -1046,17 +1039,7 @@ int __iio_device_attr_init(struct device_attribute *dev_attr,
ret = -ENOMEM;
goto error_free_full_postfix;
}
- dev_attr->attr.name = name;
-
- if (readfunc) {
- dev_attr->attr.mode |= S_IRUGO;
- dev_attr->show = readfunc;
- }
-
- if (writefunc) {
- dev_attr->attr.mode |= S_IWUSR;
- dev_attr->store = writefunc;
- }
+ attr->name = name;
error_free_full_postfix:
kfree(full_postfix);
@@ -1089,9 +1072,7 @@ int __iio_add_chan_devattr(const char *postfix,
iio_attr = kzalloc(sizeof(*iio_attr), GFP_KERNEL);
if (iio_attr == NULL)
return -ENOMEM;
- ret = __iio_device_attr_init(&iio_attr->dev_attr,
- postfix, chan,
- readfunc, writefunc, shared_by);
+ ret = iio_attr_init(&iio_attr->dev_attr.attr, postfix, chan, shared_by);
if (ret)
goto error_iio_dev_attr_free;
iio_attr->c = chan;
@@ -1107,6 +1088,16 @@ int __iio_add_chan_devattr(const char *postfix,
}
list_add(&iio_attr->l, attr_list);
+ if (readfunc) {
+ iio_attr->dev_attr.attr.mode |= S_IRUGO;
+ iio_attr->dev_attr.show = readfunc;
+ }
+
+ if (writefunc) {
+ iio_attr->dev_attr.attr.mode |= S_IWUSR;
+ iio_attr->dev_attr.store = writefunc;
+ }
+
return 0;
error_device_attr_deinit:
--
2.27.0