Skip to content

Commit 5257d80

Browse files
dlechjic23
authored andcommitted
iio: adc: ad7606: check for NULL before calling sw_mode_config()
Check that the sw_mode_config function pointer is not NULL before calling it. Not all buses define this callback, which resulted in a NULL pointer dereference. Fixes: e571c19 ("iio: adc: ad7606: move scale_setup as function pointer on chip-info") Reviewed-by: Nuno Sá <nuno.sa@analog.com> Signed-off-by: David Lechner <dlechner@baylibre.com> Link: https://patch.msgid.link/20250318-iio-adc-ad7606-improvements-v2-1-4b605427774c@baylibre.com Cc: <Stable@vger.kernel.org> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
1 parent f063a28 commit 5257d80

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

drivers/iio/adc/ad7606.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1236,9 +1236,11 @@ static int ad7616_sw_mode_setup(struct iio_dev *indio_dev)
12361236
st->write_scale = ad7616_write_scale_sw;
12371237
st->write_os = &ad7616_write_os_sw;
12381238

1239-
ret = st->bops->sw_mode_config(indio_dev);
1240-
if (ret)
1241-
return ret;
1239+
if (st->bops->sw_mode_config) {
1240+
ret = st->bops->sw_mode_config(indio_dev);
1241+
if (ret)
1242+
return ret;
1243+
}
12421244

12431245
/* Activate Burst mode and SEQEN MODE */
12441246
return ad7606_write_mask(st, AD7616_CONFIGURATION_REGISTER,
@@ -1268,6 +1270,9 @@ static int ad7606b_sw_mode_setup(struct iio_dev *indio_dev)
12681270
st->write_scale = ad7606_write_scale_sw;
12691271
st->write_os = &ad7606_write_os_sw;
12701272

1273+
if (!st->bops->sw_mode_config)
1274+
return 0;
1275+
12711276
return st->bops->sw_mode_config(indio_dev);
12721277
}
12731278

0 commit comments

Comments
 (0)