summaryrefslogtreecommitdiff
path: root/drivers
diff options
context:
space:
mode:
authorJonathan Cameron <Jonathan.Cameron@huawei.com>2025-02-17 14:01:28 +0000
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2025-04-10 14:33:36 +0200
commit8bd1e8525407208b4e92dd6238ab9add4178549b (patch)
tree64f411d1534a93742ba86bda021b303eab9ba933 /drivers
parentcb385b93c87a035f9713b8e879d016bb077b8490 (diff)
downloadlinux-8bd1e8525407208b4e92dd6238ab9add4178549b.tar.gz
linux-8bd1e8525407208b4e92dd6238ab9add4178549b.tar.bz2
linux-8bd1e8525407208b4e92dd6238ab9add4178549b.zip
iio: accel: mma8452: Ensure error return on failure to matching oversampling ratio
[ Upstream commit df330c808182a8beab5d0f84a6cbc9cff76c61fc ] If a match was not found, then the write_raw() callback would return the odr index, not an error. Return -EINVAL if this occurs. To avoid similar issues in future, introduce j, a new indexing variable rather than using ret for this purpose. Fixes: 79de2ee469aa ("iio: accel: mma8452: claim direct mode during write raw") Reviewed-by: David Lechner <dlechner@baylibre.com> Link: https://patch.msgid.link/20250217140135.896574-2-jic23@kernel.org Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/iio/accel/mma8452.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/drivers/iio/accel/mma8452.c b/drivers/iio/accel/mma8452.c
index 3ba28c2ff68a..ad7b7770d526 100644
--- a/drivers/iio/accel/mma8452.c
+++ b/drivers/iio/accel/mma8452.c
@@ -711,7 +711,7 @@ static int mma8452_write_raw(struct iio_dev *indio_dev,
int val, int val2, long mask)
{
struct mma8452_data *data = iio_priv(indio_dev);
- int i, ret;
+ int i, j, ret;
ret = iio_device_claim_direct_mode(indio_dev);
if (ret)
@@ -771,14 +771,18 @@ static int mma8452_write_raw(struct iio_dev *indio_dev,
break;
case IIO_CHAN_INFO_OVERSAMPLING_RATIO:
- ret = mma8452_get_odr_index(data);
+ j = mma8452_get_odr_index(data);
for (i = 0; i < ARRAY_SIZE(mma8452_os_ratio); i++) {
- if (mma8452_os_ratio[i][ret] == val) {
+ if (mma8452_os_ratio[i][j] == val) {
ret = mma8452_set_power_mode(data, i);
break;
}
}
+ if (i == ARRAY_SIZE(mma8452_os_ratio)) {
+ ret = -EINVAL;
+ break;
+ }
break;
default:
ret = -EINVAL;