Skip to content

Commit bbf6b6d

Browse files
tititiou36jic23
authored andcommitted
iio: adc: ad9467: Fix the "don't allow reading vref if not available" case
The commit in Fixes adds a special case when only one possible scale is available. If several scales are available, it sets the .read_avail field of the struct iio_info to ad9467_read_avail(). However, this field already holds this function pointer, so the code is a no-op. Use another struct iio_info instead to actually reflect the intent described in the commit message. This way, the structure to use is selected at runtime and they can be kept as const. This is safer because modifying static structs that are shared between all instances like this, based on the properties of a single instance, is asking for trouble down the road. Fixes: b92f94f ("iio: adc: ad9467: don't allow reading vref if not available") Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr> Link: https://patch.msgid.link/cc65da19e0578823d29e11996f86042e84d5715c.1733503146.git.christophe.jaillet@wanadoo.fr Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
1 parent de6a73b commit bbf6b6d

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

drivers/iio/adc/ad9467.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -895,14 +895,22 @@ static int ad9467_update_scan_mode(struct iio_dev *indio_dev,
895895
return 0;
896896
}
897897

898-
static struct iio_info ad9467_info = {
898+
static const struct iio_info ad9467_info = {
899899
.read_raw = ad9467_read_raw,
900900
.write_raw = ad9467_write_raw,
901901
.update_scan_mode = ad9467_update_scan_mode,
902902
.debugfs_reg_access = ad9467_reg_access,
903903
.read_avail = ad9467_read_avail,
904904
};
905905

906+
/* Same as above, but without .read_avail */
907+
static const struct iio_info ad9467_info_no_read_avail = {
908+
.read_raw = ad9467_read_raw,
909+
.write_raw = ad9467_write_raw,
910+
.update_scan_mode = ad9467_update_scan_mode,
911+
.debugfs_reg_access = ad9467_reg_access,
912+
};
913+
906914
static int ad9467_scale_fill(struct ad9467_state *st)
907915
{
908916
const struct ad9467_chip_info *info = st->info;
@@ -1214,11 +1222,12 @@ static int ad9467_probe(struct spi_device *spi)
12141222
}
12151223

12161224
if (st->info->num_scales > 1)
1217-
ad9467_info.read_avail = ad9467_read_avail;
1225+
indio_dev->info = &ad9467_info;
1226+
else
1227+
indio_dev->info = &ad9467_info_no_read_avail;
12181228
indio_dev->name = st->info->name;
12191229
indio_dev->channels = st->info->channels;
12201230
indio_dev->num_channels = st->info->num_channels;
1221-
indio_dev->info = &ad9467_info;
12221231

12231232
ret = ad9467_iio_backend_get(st);
12241233
if (ret)

0 commit comments

Comments
 (0)