]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
iio: adc: ad7606: protect register access
authorAngelo Dureghello <adureghello@baylibre.com>
Mon, 10 Feb 2025 16:10:57 +0000 (17:10 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 29 May 2025 09:13:30 +0000 (11:13 +0200)
[ Upstream commit 0f65f59e632d942cccffd12c36036c24eb7037eb ]

Protect register (and bus) access from concurrent
read / write. Needed in the backend operating mode.

Signed-off-by: Angelo Dureghello <adureghello@baylibre.com>
Link: https://patch.msgid.link/20250210-wip-bl-ad7606_add_backend_sw_mode-v4-7-160df18b1da7@baylibre.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/iio/adc/ad7606.c

index 0339e27f92c323ed0d8f0d1a9221a2fcc0d804f6..1c547e8d52ac0608194ba9496d8758b0ddd876d9 100644 (file)
@@ -862,7 +862,12 @@ static int ad7606_write_raw(struct iio_dev *indio_dev,
                }
                val = (val * MICRO) + val2;
                i = find_closest(val, scale_avail_uv, cs->num_scales);
+
+               ret = iio_device_claim_direct_mode(indio_dev);
+               if (ret < 0)
+                       return ret;
                ret = st->write_scale(indio_dev, ch, i + cs->reg_offset);
+               iio_device_release_direct_mode(indio_dev);
                if (ret < 0)
                        return ret;
                cs->range = i;
@@ -873,7 +878,12 @@ static int ad7606_write_raw(struct iio_dev *indio_dev,
                        return -EINVAL;
                i = find_closest(val, st->oversampling_avail,
                                 st->num_os_ratios);
+
+               ret = iio_device_claim_direct_mode(indio_dev);
+               if (ret < 0)
+                       return ret;
                ret = st->write_os(indio_dev, i);
+               iio_device_release_direct_mode(indio_dev);
                if (ret < 0)
                        return ret;
                st->oversampling = st->oversampling_avail[i];