All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] iio: imu: st_lsm6dsx: Fix reading array out of bounds
@ 2020-04-09  8:58 Alexandre Bard
  2020-04-09  9:17 ` Andy Shevchenko
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Alexandre Bard @ 2020-04-09  8:58 UTC (permalink / raw)
  To: lorenzo.bianconi83; +Cc: linux-iio, Alexandre Bard

Former code was iterating through all possible IDs whereas only a few
per settings array are really available. Leading to several out of
bounds readings.

Line is now longer than 80 characters. But since it is a classic for
loop I think it is better to keep it like this than splitting it.

Signed-off-by: Alexandre Bard <alexandre.bard@netmodule.com>
---
 drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
index 84d219ae6aee..be8882ff30eb 100644
--- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
+++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
@@ -1350,7 +1350,7 @@ static int st_lsm6dsx_check_whoami(struct st_lsm6dsx_hw *hw, int id,
 	int err, i, j, data;
 
 	for (i = 0; i < ARRAY_SIZE(st_lsm6dsx_sensor_settings); i++) {
-		for (j = 0; j < ST_LSM6DSX_MAX_ID; j++) {
+		for (j = 0; j < ARRAY_SIZE(st_lsm6dsx_sensor_settings[i].id); j++) {
 			if (st_lsm6dsx_sensor_settings[i].id[j].name &&
 			    id == st_lsm6dsx_sensor_settings[i].id[j].hw_id)
 				break;
-- 
2.20.1


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

end of thread, other threads:[~2020-04-09 16:44 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-09  8:58 [PATCH] iio: imu: st_lsm6dsx: Fix reading array out of bounds Alexandre Bard
2020-04-09  9:17 ` Andy Shevchenko
2020-04-09 11:01 ` Stephan Gerhold
2020-04-09 11:50   ` Alexandre Bard
2020-04-09 11:58     ` Lorenzo Bianconi
2020-04-09 12:09     ` Stephan Gerhold
2020-04-09 12:14       ` Alexandre Bard
2020-04-09 16:44 ` Martin Kepplinger

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.