linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alexandru Ardelean <alexandru.ardelean@analog.com>
To: <linux-iio@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Cc: <jic23@kernel.org>, Alexandru Ardelean <alexandru.ardelean@analog.com>
Subject: [PATCH 1/3] iio: dummy: convert all simple allocation devm_ variants
Date: Thu, 3 Dec 2020 11:50:03 +0200	[thread overview]
Message-ID: <20201203095005.72252-1-alexandru.ardelean@analog.com> (raw)

Since a main requirement for an IIO device is to have a parent device
object, it makes sense to attach more of the IIO device's objects to the
lifetime of the parent object, to clean up the code.
The idea is to also provide a base example that is more up-to-date with
what's going on lately with most IIO drivers.

This change tackles the simple allocations, to convert them to
device-managed calls, and tie them to the parent device.

Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
---
 drivers/iio/dummy/iio_simple_dummy.c | 29 ++++++++--------------------
 1 file changed, 8 insertions(+), 21 deletions(-)

diff --git a/drivers/iio/dummy/iio_simple_dummy.c b/drivers/iio/dummy/iio_simple_dummy.c
index c0b7ef900735..2a2e62f780a1 100644
--- a/drivers/iio/dummy/iio_simple_dummy.c
+++ b/drivers/iio/dummy/iio_simple_dummy.c
@@ -574,11 +574,9 @@ static struct iio_sw_device *iio_dummy_probe(const char *name)
 	 * parent = &client->dev;
 	 */
 
-	swd = kzalloc(sizeof(*swd), GFP_KERNEL);
-	if (!swd) {
-		ret = -ENOMEM;
-		goto error_kzalloc;
-	}
+	swd = devm_kzalloc(parent, sizeof(*swd), GFP_KERNEL);
+	if (!swd)
+		return ERR_PTR(-ENOMEM);
 	/*
 	 * Allocate an IIO device.
 	 *
@@ -587,11 +585,9 @@ static struct iio_sw_device *iio_dummy_probe(const char *name)
 	 * It also has a region (accessed by iio_priv()
 	 * for chip specific state information.
 	 */
-	indio_dev = iio_device_alloc(parent, sizeof(*st));
-	if (!indio_dev) {
-		ret = -ENOMEM;
-		goto error_ret;
-	}
+	indio_dev = devm_iio_device_alloc(parent, sizeof(*st));
+	if (!indio_dev)
+		return ERR_PTR(-ENOMEM);
 
 	st = iio_priv(indio_dev);
 	mutex_init(&st->lock);
@@ -615,7 +611,7 @@ static struct iio_sw_device *iio_dummy_probe(const char *name)
 	 *    indio_dev->name = id->name;
 	 *    indio_dev->name = spi_get_device_id(spi)->name;
 	 */
-	indio_dev->name = kstrdup(name, GFP_KERNEL);
+	indio_dev->name = devm_kstrdup(parent, name, GFP_KERNEL);
 
 	/* Provide description of available channels */
 	indio_dev->channels = iio_dummy_channels;
@@ -632,7 +628,7 @@ static struct iio_sw_device *iio_dummy_probe(const char *name)
 
 	ret = iio_simple_dummy_events_register(indio_dev);
 	if (ret < 0)
-		goto error_free_device;
+		return ERR_PTR(ret);
 
 	ret = iio_simple_dummy_configure_buffer(indio_dev);
 	if (ret < 0)
@@ -649,11 +645,6 @@ static struct iio_sw_device *iio_dummy_probe(const char *name)
 	iio_simple_dummy_unconfigure_buffer(indio_dev);
 error_unregister_events:
 	iio_simple_dummy_events_unregister(indio_dev);
-error_free_device:
-	iio_device_free(indio_dev);
-error_ret:
-	kfree(swd);
-error_kzalloc:
 	return ERR_PTR(ret);
 }
 
@@ -683,10 +674,6 @@ static int iio_dummy_remove(struct iio_sw_device *swd)
 
 	iio_simple_dummy_events_unregister(indio_dev);
 
-	/* Free all structures */
-	kfree(indio_dev->name);
-	iio_device_free(indio_dev);
-
 	return 0;
 }
 
-- 
2.27.0


             reply	other threads:[~2020-12-03  9:51 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-03  9:50 Alexandru Ardelean [this message]
2020-12-03  9:50 ` [PATCH 2/3] iio: dummy: convert events to device-managed handlers Alexandru Ardelean
2020-12-03  9:50 ` [PATCH 3/3] iio: dummy: use devm_iio_triggered_buffer_setup() for buffer setup Alexandru Ardelean
2020-12-05 16:36 ` [PATCH 1/3] iio: dummy: convert all simple allocation devm_ variants Jonathan Cameron
2020-12-07  7:22   ` Alexandru Ardelean
2020-12-13 14:22     ` Jonathan Cameron

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=20201203095005.72252-1-alexandru.ardelean@analog.com \
    --to=alexandru.ardelean@analog.com \
    --cc=jic23@kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /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).