linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alexandru Ardelean <alexandru.ardelean@analog.com>
To: <linux-kernel@vger.kernel.org>, <linux-iio@vger.kernel.org>
Cc: <lars@metafoo.de>, <Michael.Hennerich@analog.com>,
	<jic23@kernel.org>, <nuno.sa@analog.com>,
	<dragos.bogdan@analog.com>,
	Alexandru Ardelean <alexandru.ardelean@analog.com>
Subject: [PATCH v2 05/12][RESEND] iio: core: split __iio_device_attr_init() to init only the attr object
Date: Fri, 22 Jan 2021 18:25:22 +0200	[thread overview]
Message-ID: <20210122162529.84978-6-alexandru.ardelean@analog.com> (raw)
In-Reply-To: <20210122162529.84978-1-alexandru.ardelean@analog.com>

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 <alexandru.ardelean@analog.com>
---
 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 95d66745f118..b8f7261945f5 100644
--- a/drivers/iio/industrialio-core.c
+++ b/drivers/iio/industrialio-core.c
@@ -968,22 +968,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)) {
@@ -1079,17 +1072,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);
@@ -1122,9 +1105,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;
@@ -1140,6 +1121,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.17.1


  parent reply	other threads:[~2021-01-22 16:25 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-22 16:25 [PATCH v2 00/12][RESEND] iio: core,buffer: add support for multiple IIO buffers per IIO device Alexandru Ardelean
2021-01-22 16:25 ` [PATCH v2 01/12][RESEND] iio: core: register chardev only if needed Alexandru Ardelean
2021-01-22 16:25 ` [PATCH v2 02/12][RESEND] iio: buffer: add back-ref from iio_buffer to iio_dev Alexandru Ardelean
2021-01-22 16:25 ` [PATCH v2 03/12][RESEND] iio: buffer: rework buffer & scan_elements dir creation Alexandru Ardelean
2021-01-24 18:11   ` Jonathan Cameron
2021-01-24 19:07     ` Alexandru Ardelean
2021-01-25 19:29       ` Greg Kroah-Hartman
2021-01-25 19:28     ` Greg Kroah-Hartman
2021-01-26  9:45       ` Alexandru Ardelean
2021-01-27 14:48         ` Jonathan Cameron
2021-01-22 16:25 ` [PATCH v2 04/12][RESEND] iio: buffer: add index to the first IIO buffer dir and symlink it back Alexandru Ardelean
2021-01-22 16:25 ` Alexandru Ardelean [this message]
2021-01-22 16:25 ` [PATCH v2 06/12][RESEND] iio: buffer: re-route scan_elements via it's kobj_type Alexandru Ardelean
2021-01-22 16:25 ` [PATCH v2 07/12][RESEND] iio: buffer: re-route core buffer attributes via it's new kobj_type Alexandru Ardelean
2021-01-22 16:25 ` [PATCH v2 08/12][RESEND] iio: buffer: add helper to get the IIO device to which a buffer belongs Alexandru Ardelean
2021-01-22 16:25 ` [PATCH v2 09/12][RESEND] iio: re-route all buffer attributes through new buffer kobj_type Alexandru Ardelean
2021-01-22 16:25 ` [PATCH v2 10/12][RESEND] iio: core: wrap iio device & buffer into struct for character devices Alexandru Ardelean
2021-01-22 16:25 ` [PATCH v2 11/12][RESEND] iio: buffer: introduce support for attaching more IIO buffers Alexandru Ardelean
2021-01-25 11:06   ` [kbuild] " Dan Carpenter
2021-01-22 16:25 ` [PATCH v2 12/12][RESEND] iio: buffer: add ioctl() to support opening extra buffers for IIO device Alexandru Ardelean
2021-01-24 18:38   ` Jonathan Cameron
2021-01-24 19:32     ` Alexandru Ardelean

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210122162529.84978-6-alexandru.ardelean@analog.com \
    --to=alexandru.ardelean@analog.com \
    --cc=Michael.Hennerich@analog.com \
    --cc=dragos.bogdan@analog.com \
    --cc=jic23@kernel.org \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nuno.sa@analog.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).