All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] iio: core: WARN in case sample bits do not fit storage bits
@ 2022-03-20 18:15 Marek Vasut
  2022-03-21  9:08 ` Sa, Nuno
  2022-03-21 10:40 ` Andy Shevchenko
  0 siblings, 2 replies; 11+ messages in thread
From: Marek Vasut @ 2022-03-20 18:15 UTC (permalink / raw)
  To: linux-iio
  Cc: Marek Vasut, Andy Shevchenko, Andy Shevchenko, Daniel Baluta,
	Jonathan Cameron

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@denx.de>
Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Andy Shevchenko <andy.shevchenko@gmail.com>
Cc: Daniel Baluta <daniel.baluta@nxp.com>
Cc: Jonathan Cameron <Jonathan.Cameron@huawei.com>
---
 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


^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2022-03-22 11:17 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-20 18:15 [PATCH] iio: core: WARN in case sample bits do not fit storage bits Marek Vasut
2022-03-21  9:08 ` Sa, Nuno
2022-03-21 10:40 ` Andy Shevchenko
2022-03-21 14:46   ` Marek Vasut
2022-03-21 16:10     ` Andy Shevchenko
2022-03-21 19:46       ` Marek Vasut
2022-03-22  7:43         ` Nuno Sá
2022-03-22  9:49           ` Andy Shevchenko
2022-03-22  9:57             ` Marek Vasut
2022-03-22 10:10               ` Nuno Sá
2022-03-22 11:17                 ` Marek Vasut

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.