Linux IIO development
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Cc: lars@metafoo.de, linux-iio@vger.kernel.org,
	linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org
Subject: Re: [PATCH 2/2] iio: buffer: Move a sanity check at the beginning of 'iio_scan_mask_set()'
Date: Sat, 17 Jul 2021 17:59:25 +0100	[thread overview]
Message-ID: <20210717175925.17091e96@jic23-huawei> (raw)
In-Reply-To: <98a351adda1908c306e981b9cc86d3dbc79eb5ec.1626261211.git.christophe.jaillet@wanadoo.fr>

On Wed, 14 Jul 2021 13:14:51 +0200
Christophe JAILLET <christophe.jaillet@wanadoo.fr> wrote:

> This is more standard to have sanity checks at the entry of a function,
> instead of allocating some memory first and having to free it if a
> condition is not met.

Indeed this is silly.  I'd guess result of code evolution, but perhaps
I was crazy in the first place :)

Applied,

Thanks,

Jonathan

> 
> Shuffle code a bit to check 'masklength' before calling 'bitmap_alloc()'
> 
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> ---
>  drivers/iio/industrialio-buffer.c | 9 +++++----
>  1 file changed, 5 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/iio/industrialio-buffer.c b/drivers/iio/industrialio-buffer.c
> index 6d4776a7f002..a95cc2da56be 100644
> --- a/drivers/iio/industrialio-buffer.c
> +++ b/drivers/iio/industrialio-buffer.c
> @@ -354,13 +354,14 @@ static int iio_scan_mask_set(struct iio_dev *indio_dev,
>  	const unsigned long *mask;
>  	unsigned long *trialmask;
>  
> -	trialmask = bitmap_alloc(indio_dev->masklength, GFP_KERNEL);
> -	if (!trialmask)
> -		return -ENOMEM;
>  	if (!indio_dev->masklength) {
>  		WARN(1, "Trying to set scanmask prior to registering buffer\n");
> -		goto err_invalid_mask;
> +		return -EINVAL;
>  	}
> +
> +	trialmask = bitmap_alloc(indio_dev->masklength, GFP_KERNEL);
> +	if (!trialmask)
> +		return -ENOMEM;
>  	bitmap_copy(trialmask, buffer->scan_mask, indio_dev->masklength);
>  	set_bit(bit, trialmask);
>  


  reply	other threads:[~2021-07-17 16:57 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-14 11:14 [PATCH 1/2] iio: buffer: Save a few cycles in 'iio_scan_mask_set()' Christophe JAILLET
2021-07-14 11:14 ` [PATCH 2/2] iio: buffer: Move a sanity check at the beginning of 'iio_scan_mask_set()' Christophe JAILLET
2021-07-17 16:59   ` Jonathan Cameron [this message]
2021-07-17 16:58 ` [PATCH 1/2] iio: buffer: Save a few cycles in 'iio_scan_mask_set()' 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=20210717175925.17091e96@jic23-huawei \
    --to=jic23@kernel.org \
    --cc=christophe.jaillet@wanadoo.fr \
    --cc=kernel-janitors@vger.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