Linux-IIO Archive mirror
 help / color / mirror / Atom feed
From: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
To: "andriy.shevchenko@linux.intel.com" <andriy.shevchenko@linux.intel.com>
Cc: Jonathan.Cameron@huawei.com, jic23@kernel.org, lars@metafoo.de,
	linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v1 2/2] iio: core: Calculate alloc_size only once in iio_device_alloc()
Date: Sat, 9 Mar 2024 19:42:22 +0100	[thread overview]
Message-ID: <b354e05d-c699-47a7-b4e2-dd844902b85c@wanadoo.fr> (raw)
In-Reply-To: <20240304140650.977784-3-andriy.shevchenko@linux.intel.com>

Le 04/03/2024 à 15:04, Andy Shevchenko a écrit :
> No need to rewrite the value, instead use 'else' branch.
> This will also help further refactoring the code later on.
> 
> Signed-off-by: Andy Shevchenko <andriy.shevchenko-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
> ---
>   drivers/iio/industrialio-core.c | 9 ++++-----
>   1 file changed, 4 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
> index 8684ba246969..c7ad88932015 100644
> --- a/drivers/iio/industrialio-core.c
> +++ b/drivers/iio/industrialio-core.c
> @@ -1643,11 +1643,10 @@ struct iio_dev *iio_device_alloc(struct device *parent, int sizeof_priv)
>   	struct iio_dev *indio_dev;
>   	size_t alloc_size;
>   
> -	alloc_size = sizeof(struct iio_dev_opaque);
> -	if (sizeof_priv) {
> -		alloc_size = ALIGN(alloc_size, IIO_DMA_MINALIGN);
> -		alloc_size += sizeof_priv;
> -	}
> +	if (sizeof_priv)
> +		alloc_size = ALIGN(sizeof(*iio_dev_opaque), IIO_DMA_MINALIGN) + sizeof_priv;

maybe size_add() to be super-safe?

CJ

> +	else
> +		alloc_size = sizeof(*iio_dev_opaque);
>   
>   	iio_dev_opaque = kzalloc(alloc_size, GFP_KERNEL);
>   	if (!iio_dev_opaque)


  parent reply	other threads:[~2024-03-09 18:43 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-04 14:04 [PATCH v1 0/2] iio: core: Fix and cleanup to iio_device_alloc() Andy Shevchenko
2024-03-04 14:04 ` [PATCH v1 1/2] iio: core: Leave private pointer NULL when no private data supplied Andy Shevchenko
2024-03-04 14:39   ` David Lechner
2024-03-09 18:37   ` Jonathan Cameron
2024-03-04 14:04 ` [PATCH v1 2/2] iio: core: Calculate alloc_size only once in iio_device_alloc() Andy Shevchenko
2024-03-04 14:38   ` David Lechner
2024-03-09 18:42   ` Christophe JAILLET [this message]
2024-03-09 18:38 ` [PATCH v1 0/2] iio: core: Fix and cleanup to iio_device_alloc() 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=b354e05d-c699-47a7-b4e2-dd844902b85c@wanadoo.fr \
    --to=christophe.jaillet@wanadoo.fr \
    --cc=Jonathan.Cameron@huawei.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=jic23@kernel.org \
    --cc=lars@metafoo.de \
    --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 read-only IMAP folder(s) and NNTP newsgroup(s).