Skip to content

Commit 06c3a41

Browse files
dlechsmb49
authored andcommitted
iio: adc: ad7606: check for NULL before calling sw_mode_config()
BugLink: https://bugs.launchpad.net/bugs/2115266 [ Upstream commit 5257d80e22bf27009d6742e4c174f42cfe54e425 ] 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> Signed-off-by: Sasha Levin <sashal@kernel.org> CVE-2025-38025 Signed-off-by: Manuel Diewald <manuel.diewald@canonical.com> Signed-off-by: Stefan Bader <stefan.bader@canonical.com>
1 parent 2e1d5e0 commit 06c3a41

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
@@ -1228,9 +1228,11 @@ static int ad7616_sw_mode_setup(struct iio_dev *indio_dev)
12281228
st->write_scale = ad7616_write_scale_sw;
12291229
st->write_os = &ad7616_write_os_sw;
12301230

1231-
ret = st->bops->sw_mode_config(indio_dev);
1232-
if (ret)
1233-
return ret;
1231+
if (st->bops->sw_mode_config) {
1232+
ret = st->bops->sw_mode_config(indio_dev);
1233+
if (ret)
1234+
return ret;
1235+
}
12341236

12351237
/* Activate Burst mode and SEQEN MODE */
12361238
return ad7606_write_mask(st, AD7616_CONFIGURATION_REGISTER,
@@ -1261,6 +1263,9 @@ static int ad7606b_sw_mode_setup(struct iio_dev *indio_dev)
12611263
st->write_scale = ad7606_write_scale_sw;
12621264
st->write_os = &ad7606_write_os_sw;
12631265

1266+
if (!st->bops->sw_mode_config)
1267+
return 0;
1268+
12641269
return st->bops->sw_mode_config(indio_dev);
12651270
}
12661271

0 commit comments

Comments
 (0)