Skip to content

Commit 36a44e0

Browse files
dlechjic23
authored andcommitted
iio: adc: ad7173: fix using shared static info struct
Fix a possible race condition during driver probe in the ad7173 driver due to using a shared static info struct. If more that one instance of the driver is probed at the same time, some of the info could be overwritten by the other instance, leading to incorrect operation. To fix this, make the static info struct const so that it is read-only and make a copy of the info struct for each instance of the driver that can be modified. Reported-by: Uwe Kleine-König <u.kleine-koenig@baylibre.com> Fixes: 76a1e6a ("iio: adc: ad7173: add AD7173 driver") Signed-off-by: David Lechner <dlechner@baylibre.com> Tested-by: Guillaume Ranquet <granquet@baylibre.com> Link: https://patch.msgid.link/20241127-iio-adc-ad7313-fix-non-const-info-struct-v2-1-b6d7022b7466@baylibre.com Cc: <Stable@vger.kernel.org> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
1 parent 2a8e340 commit 36a44e0

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

drivers/iio/adc/ad7173.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ struct ad7173_channel {
200200

201201
struct ad7173_state {
202202
struct ad_sigma_delta sd;
203+
struct ad_sigma_delta_info sigma_delta_info;
203204
const struct ad7173_device_info *info;
204205
struct ad7173_channel *channels;
205206
struct regulator_bulk_data regulators[3];
@@ -753,7 +754,7 @@ static int ad7173_disable_one(struct ad_sigma_delta *sd, unsigned int chan)
753754
return ad_sd_write_reg(sd, AD7173_REG_CH(chan), 2, 0);
754755
}
755756

756-
static struct ad_sigma_delta_info ad7173_sigma_delta_info = {
757+
static const struct ad_sigma_delta_info ad7173_sigma_delta_info = {
757758
.set_channel = ad7173_set_channel,
758759
.append_status = ad7173_append_status,
759760
.disable_all = ad7173_disable_all,
@@ -1403,7 +1404,7 @@ static int ad7173_fw_parse_device_config(struct iio_dev *indio_dev)
14031404
if (ret < 0)
14041405
return dev_err_probe(dev, ret, "Interrupt 'rdy' is required\n");
14051406

1406-
ad7173_sigma_delta_info.irq_line = ret;
1407+
st->sigma_delta_info.irq_line = ret;
14071408

14081409
return ad7173_fw_parse_channel_config(indio_dev);
14091410
}
@@ -1436,8 +1437,9 @@ static int ad7173_probe(struct spi_device *spi)
14361437
spi->mode = SPI_MODE_3;
14371438
spi_setup(spi);
14381439

1439-
ad7173_sigma_delta_info.num_slots = st->info->num_configs;
1440-
ret = ad_sd_init(&st->sd, indio_dev, spi, &ad7173_sigma_delta_info);
1440+
st->sigma_delta_info = ad7173_sigma_delta_info;
1441+
st->sigma_delta_info.num_slots = st->info->num_configs;
1442+
ret = ad_sd_init(&st->sd, indio_dev, spi, &st->sigma_delta_info);
14411443
if (ret)
14421444
return ret;
14431445

0 commit comments

Comments
 (0)