RE: [PATCH] iio: core: WARN in case sample bits do not fit storage bits

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




> -----Original Message-----
> From: Marek Vasut <marex@xxxxxxx>
> Sent: Sunday, March 20, 2022 7:16 PM
> To: linux-iio@xxxxxxxxxxxxxxx
> Cc: Marek Vasut <marex@xxxxxxx>; Andy Shevchenko
> <andriy.shevchenko@xxxxxxxxxxxxxxx>; Andy Shevchenko
> <andy.shevchenko@xxxxxxxxx>; Daniel Baluta
> <daniel.baluta@xxxxxxx>; Jonathan Cameron
> <Jonathan.Cameron@xxxxxxxxxx>
> Subject: [PATCH] iio: core: WARN in case sample bits do not fit storage
> bits
> 
> [External]
> 
> Add runtime check to verify whether storagebits are at least as big
> as shifted realbits. This should help spot broken drivers which may
> set realbits + shift above storagebits.
> 
> Signed-off-by: Marek Vasut <marex@xxxxxxx>
> Cc: Andy Shevchenko <andriy.shevchenko@xxxxxxxxxxxxxxx>
> Cc: Andy Shevchenko <andy.shevchenko@xxxxxxxxx>
> Cc: Daniel Baluta <daniel.baluta@xxxxxxx>
> Cc: Jonathan Cameron <Jonathan.Cameron@xxxxxxxxxx>
> ---

Acked-by: Nuno Sá <nuno.sa@xxxxxxxxxx>

>  drivers/iio/industrialio-buffer.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/drivers/iio/industrialio-buffer.c b/drivers/iio/industrialio-
> buffer.c
> index b078eb2f3c9de..bac1e994e7bef 100644
> --- a/drivers/iio/industrialio-buffer.c
> +++ b/drivers/iio/industrialio-buffer.c
> @@ -1629,6 +1629,11 @@ static int
> __iio_buffer_alloc_sysfs_and_mask(struct iio_buffer *buffer,
>  			if (channels[i].scan_index < 0)
>  				continue;
> 
> +			/* Verify that sample bits fit into storage */
> +			WARN_ON(channels[i].scan_type.storagebits <
> +				channels[i].scan_type.realbits +
> +				channels[i].scan_type.shift);
> +
>  			ret = iio_buffer_add_channel_sysfs(indio_dev,
> buffer,
>  							 &channels[i]);
>  			if (ret < 0)
> --
> 2.35.1





[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Input]     [Linux Kernel]     [Linux SCSI]     [X.org]

  Powered by Linux