Commit 5257d80e authored by David Lechner's avatar David Lechner Committed by Jonathan Cameron
Browse files

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: e571c190 ("iio: adc: ad7606: move scale_setup as function pointer on chip-info")
Reviewed-by: default avatarNuno Sá <nuno.sa@analog.com>
Signed-off-by: default avatarDavid 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: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
parent f063a280
Loading
Loading
Loading
Loading
+8 −3
Original line number Diff line number Diff line
@@ -1236,9 +1236,11 @@ static int ad7616_sw_mode_setup(struct iio_dev *indio_dev)
	st->write_scale = ad7616_write_scale_sw;
	st->write_os = &ad7616_write_os_sw;

	if (st->bops->sw_mode_config) {
		ret = st->bops->sw_mode_config(indio_dev);
		if (ret)
			return ret;
	}

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

	if (!st->bops->sw_mode_config)
		return 0;

	return st->bops->sw_mode_config(indio_dev);
}