mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Alexandru Ardelean <alexandru.ardelean@analog.com>
To: <linux-iio@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Cc: <lars@metafoo.de>, <jic23@kernel.org>, <pmeerw@pmeerw.net>,
	"Jonathan Cameron" <Jonathan.Cameron@huawei.com>,
	Alexandru Ardelean <alexandru.ardelean@analog.com>
Subject: [PATCH v4 1/7] iio: Use an early return in iio_device_alloc to simplify code.
Date: Fri, 24 Apr 2020 07:56:36 +0300	[thread overview]
Message-ID: <20200424045642.4903-2-alexandru.ardelean@analog.com> (raw)
In-Reply-To: <20200424045642.4903-1-alexandru.ardelean@analog.com>

From: Jonathan Cameron <Jonathan.Cameron@huawei.com>

Noticed whilst reviewing Alexandru's patch to the same function.
If we simply flip the logic and return NULL immediately after memory
allocation failure we reduce the indent of the following block and
end up with more 'idiomatic' kernel code.

Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Cc: Alexandru Ardelean <alexandru.ardelean@analog.com>
Reviewed-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
---
 drivers/iio/industrialio-core.c | 46 ++++++++++++++++-----------------
 1 file changed, 23 insertions(+), 23 deletions(-)

diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
index f4daf19f2a3b..3c97090c2ab9 100644
--- a/drivers/iio/industrialio-core.c
+++ b/drivers/iio/industrialio-core.c
@@ -1492,7 +1492,7 @@ struct device_type iio_device_type = {
  **/
 struct iio_dev *iio_device_alloc(int sizeof_priv)
 {
-	struct iio_dev *dev;
+	struct iio_dev *indio_dev;
 	size_t alloc_size;
 
 	alloc_size = sizeof(struct iio_dev);
@@ -1503,30 +1503,30 @@ struct iio_dev *iio_device_alloc(int sizeof_priv)
 	/* ensure 32-byte alignment of whole construct ? */
 	alloc_size += IIO_ALIGN - 1;
 
-	dev = kzalloc(alloc_size, GFP_KERNEL);
-
-	if (dev) {
-		dev->dev.groups = dev->groups;
-		dev->dev.type = &iio_device_type;
-		dev->dev.bus = &iio_bus_type;
-		device_initialize(&dev->dev);
-		dev_set_drvdata(&dev->dev, (void *)dev);
-		mutex_init(&dev->mlock);
-		mutex_init(&dev->info_exist_lock);
-		INIT_LIST_HEAD(&dev->channel_attr_list);
-
-		dev->id = ida_simple_get(&iio_ida, 0, 0, GFP_KERNEL);
-		if (dev->id < 0) {
-			/* cannot use a dev_err as the name isn't available */
-			pr_err("failed to get device id\n");
-			kfree(dev);
-			return NULL;
-		}
-		dev_set_name(&dev->dev, "iio:device%d", dev->id);
-		INIT_LIST_HEAD(&dev->buffer_list);
+	indio_dev = kzalloc(alloc_size, GFP_KERNEL);
+	if (!indio_dev)
+		return NULL;
+
+	indio_dev->id = ida_simple_get(&iio_ida, 0, 0, GFP_KERNEL);
+	if (indio_dev->id < 0) {
+		/* cannot use a dev_err as the name isn't available */
+		pr_err("failed to get device id\n");
+		kfree(indio_dev);
+		return NULL;
 	}
 
-	return dev;
+	dev_set_name(&indio_dev->dev, "iio:device%d", indio_dev->id);
+	indio_dev->dev.groups = indio_dev->groups;
+	indio_dev->dev.type = &iio_device_type;
+	indio_dev->dev.bus = &iio_bus_type;
+	device_initialize(&indio_dev->dev);
+	dev_set_drvdata(&indio_dev->dev, (void *)indio_dev);
+	mutex_init(&indio_dev->mlock);
+	mutex_init(&indio_dev->info_exist_lock);
+	INIT_LIST_HEAD(&indio_dev->channel_attr_list);
+	INIT_LIST_HEAD(&indio_dev->buffer_list);
+
+	return indio_dev;
 }
 EXPORT_SYMBOL(iio_device_alloc);
 
-- 
2.17.1


  reply	other threads:[~2020-04-24  4:57 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-24  4:56 [PATCH v4 0/7] iio: core,buffer: re-organize chardev creation Alexandru Ardelean
2020-04-24  4:56 ` Alexandru Ardelean [this message]
2020-04-26  7:28   ` [PATCH v4 1/7] iio: Use an early return in iio_device_alloc to simplify code Ardelean, Alexandru
2020-04-24  4:56 ` [PATCH v4 2/7] iio: buffer: add back-ref from iio_buffer to iio_dev Alexandru Ardelean
2020-04-24  4:56 ` [PATCH v4 3/7] iio: core,buffer: wrap iio_buffer_put() call into iio_buffers_put() Alexandru Ardelean
2020-04-24  4:56 ` [PATCH v4 4/7] iio: core: register chardev only if needed Alexandru Ardelean
2020-04-24  4:56 ` [PATCH v4 5/7] iio: buffer,event: duplicate chardev creation for buffers & events Alexandru Ardelean
2020-04-24  4:56 ` [PATCH v4 6/7] iio: core: add simple centralized mechanism for ioctl() handlers Alexandru Ardelean
2020-04-24  4:56 ` [PATCH v4 7/7] iio: core: use new common ioctl() mechanism 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=20200424045642.4903-2-alexandru.ardelean@analog.com \
    --to=alexandru.ardelean@analog.com \
    --cc=Jonathan.Cameron@huawei.com \
    --cc=jic23@kernel.org \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pmeerw@pmeerw.net \
    /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

all inboxes | Powered by JetHome®