diff options
| author | Petre Rodan <petre.rodan@subdimension.ro> | 2025-10-05 16:12:22 +0300 |
|---|---|---|
| committer | Jonathan Cameron <Jonathan.Cameron@huawei.com> | 2025-10-19 11:59:20 +0100 |
| commit | 0e3c7fd44244a1dbb925ade1a87e699bdea03dab (patch) | |
| tree | 382d7975395d983c9a66527e31c7140255275fec | |
| parent | 480f08a6892e3de415c8063121d5e198c4120ed7 (diff) | |
iio: accel: bma220: use find_match_table fct
Clean up the code a bit by using a find_match_table function.
Signed-off-by: Petre Rodan <petre.rodan@subdimension.ro>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
| -rw-r--r-- | drivers/iio/accel/bma220_core.c | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/drivers/iio/accel/bma220_core.c b/drivers/iio/accel/bma220_core.c index 6975076802a2..404fea26e3f7 100644 --- a/drivers/iio/accel/bma220_core.c +++ b/drivers/iio/accel/bma220_core.c @@ -222,11 +222,23 @@ static int bma220_read_raw(struct iio_dev *indio_dev, return -EINVAL; } +static int bma220_find_match_2dt(const int (*tbl)[2], const int n, + const int val, const int val2) +{ + int i; + + for (i = 0; i < n; i++) { + if (tbl[i][0] == val && tbl[i][1] == val2) + return i; + } + + return -EINVAL; +} + static int bma220_write_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int val, int val2, long mask) { - int i; int ret; int index = -1; struct bma220_data *data = iio_priv(indio_dev); @@ -235,12 +247,9 @@ static int bma220_write_raw(struct iio_dev *indio_dev, switch (mask) { case IIO_CHAN_INFO_SCALE: - for (i = 0; i < ARRAY_SIZE(bma220_scale_table); i++) - if (val == bma220_scale_table[i][0] && - val2 == bma220_scale_table[i][1]) { - index = i; - break; - } + index = bma220_find_match_2dt(bma220_scale_table, + ARRAY_SIZE(bma220_scale_table), + val, val2); if (index < 0) return -EINVAL; |
