lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20210717175925.17091e96@jic23-huawei>
Date:   Sat, 17 Jul 2021 17:59:25 +0100
From:   Jonathan Cameron <jic23@...nel.org>
To:     Christophe JAILLET <christophe.jaillet@...adoo.fr>
Cc:     lars@...afoo.de, linux-iio@...r.kernel.org,
        linux-kernel@...r.kernel.org, kernel-janitors@...r.kernel.org
Subject: Re: [PATCH 2/2] iio: buffer: Move a sanity check at the beginning
 of 'iio_scan_mask_set()'

On Wed, 14 Jul 2021 13:14:51 +0200
Christophe JAILLET <christophe.jaillet@...adoo.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@...adoo.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);
>  

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ