[PATCH 10/12] iio: accel: kionix-kx022a: Fix array boundary check

Matti Vaittinen <[email protected]>
Newsgroups org.kernel.vger.linux-iio,org.kernel.vger.linux-kernel
Message-ID <159f1048852afc74cfc2d219298a5a6f9d70cbb4.1786347811.git.mazziesaccount@gmail.com>
From: Matti Vaittinen <[email protected]>

The driver performs a sanity check for an array size, when converting a
register value to an array index. The check incorrectly accepts the
sizeof(array) as a last index, when last valid index should be
sizeof(array) - 1.

Fix the check by bailing out when index >= sizeof(array).

Signed-off-by: Matti Vaittinen <[email protected]>
Fixes: 7c1d1677b322 ("iio: accel: Support Kionix/ROHM KX022A accelerometer")
---
 drivers/iio/accel/kionix-kx022a.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/iio/accel/kionix-kx022a.c b/drivers/iio/accel/kionix-kx022a.c
index 39485572a76b..8a13f78aeab0 100644
--- a/drivers/iio/accel/kionix-kx022a.c
+++ b/drivers/iio/accel/kionix-kx022a.c
@@ -649,7 +649,7 @@ static int kx022a_read_raw(struct iio_dev *idev,
 		if (ret)
 			return ret;
 
-		if ((regval & KX022A_MASK_ODR) >
+		if ((regval & KX022A_MASK_ODR) >=
 		    ARRAY_SIZE(kx022a_accel_samp_freq_table)) {
 			dev_err(data->dev, "Invalid ODR\n");
 			return -EINVAL;
-- 
2.55.0
signature.asc (application/pgp-signature, 488 B)
-----BEGIN PGP SIGNATURE-----

iQEzBAEBCgAdFiEEIx+f8wZb28fLKEhTeFA3/03aocUFAmp5g7gACgkQeFA3/03a
ocXo7Af+LlXYSGoycqVvzVxtYqz5E/z7dKDQNf7tuNO7ZBSNvUHVn3UxOQduHaU+
AH8rDUk3sMxN0GD9pqWREcny/l18w+SYTbYt2hk2jJ8+iCMzjLJbkzQFEvDUilia
kiIYF+cwRVfS+epiPCOeB8pb9m4VnkrVwtnMg0EsEei2ERxUeglNZZvdAy6mAoRO
KXgwT11G3oyA5yGRsk4spDsPL1+PBjAgwaM0uDvfsQhhjTCROXWyrnR92/hxO3E0
RJct6tNj0cZxQOrmjL9JpBudmPTtGmDf1daZrQMA5uvSADB5sv9rDhLCRa0aUG57
ZEmV7PrPeTucxybgBemjE5+QN5CCLg==
=j8ef
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.