From: Jonathan Cameron <jic23@kernel.org>
To: Alexandru Ardelean <alexandru.ardelean@analog.com>
Cc: <linux-iio@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] iio: core: fail early in iio_device_alloc() if we can't get a device id
Date: Sat, 18 Apr 2020 16:25:55 +0100 [thread overview]
Message-ID: <20200418162555.4b6f4b8d@archlinux> (raw)
In-Reply-To: <20200416123331.68790-1-alexandru.ardelean@analog.com>
On Thu, 16 Apr 2020 15:33:31 +0300
Alexandru Ardelean <alexandru.ardelean@analog.com> wrote:
> This change moves the 'ida_simple_get()' call to be the first one in
> iio_device_alloc(). It cleans up the error path a bit as we don't need to
> call any kfree(dev) anymore. We allocate an IIO device only if we have
> managed to obtain a device ID.
We just threw away an ID if the kzalloc then fails (or am I missing something?)
With that fixed I can't see this as being much of an improvement.
Either way one allocation needs to be tidied up.
Jonathan
>
> Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
> ---
> drivers/iio/industrialio-core.c | 19 ++++++++++---------
> 1 file changed, 10 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
> index f4daf19f2a3b..7c1d8a3ab2f3 100644
> --- a/drivers/iio/industrialio-core.c
> +++ b/drivers/iio/industrialio-core.c
> @@ -1494,6 +1494,14 @@ struct iio_dev *iio_device_alloc(int sizeof_priv)
> {
> struct iio_dev *dev;
> size_t alloc_size;
> + int id;
> +
> + id = ida_simple_get(&iio_ida, 0, 0, GFP_KERNEL);
> + if (id < 0) {
> + /* cannot use a dev_err as the name isn't available */
> + pr_err("failed to get device id\n");
> + return NULL;
> + }
>
> alloc_size = sizeof(struct iio_dev);
> if (sizeof_priv) {
> @@ -1506,6 +1514,8 @@ struct iio_dev *iio_device_alloc(int sizeof_priv)
> dev = kzalloc(alloc_size, GFP_KERNEL);
>
> if (dev) {
> + dev->id = id;
> + dev_set_name(&dev->dev, "iio:device%d", dev->id);
> dev->dev.groups = dev->groups;
> dev->dev.type = &iio_device_type;
> dev->dev.bus = &iio_bus_type;
> @@ -1514,15 +1524,6 @@ struct iio_dev *iio_device_alloc(int sizeof_priv)
> 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);
> }
>
next prev parent reply other threads:[~2020-04-18 15:26 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-04-16 12:33 [PATCH] iio: core: fail early in iio_device_alloc() if we can't get a device id Alexandru Ardelean
2020-04-18 15:25 ` Jonathan Cameron [this message]
2020-04-18 16:28 ` Ardelean, Alexandru
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=20200418162555.4b6f4b8d@archlinux \
--to=jic23@kernel.org \
--cc=alexandru.ardelean@analog.com \
--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