From: Alexandru Ardelean Date: Mon, 21 May 2018 06:40:05 +0000 (+0300) Subject: iio: amplifiers: ad8366: move channel init before iio_device_register() X-Git-Tag: v4.18-rc1~83^2~119^2~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2636d005758928c2884ac610589f383c73919bcf;p=thirdparty%2Fkernel%2Flinux.git iio: amplifiers: ad8366: move channel init before iio_device_register() Otherwise a race condition can occur, where userspace can start operations before the channels have been properly initialized. Signed-off-by: Alexandru Ardelean Signed-off-by: Jonathan Cameron --- diff --git a/drivers/iio/amplifiers/ad8366.c b/drivers/iio/amplifiers/ad8366.c index 43667866321e3..0138337aedd10 100644 --- a/drivers/iio/amplifiers/ad8366.c +++ b/drivers/iio/amplifiers/ad8366.c @@ -161,12 +161,14 @@ static int ad8366_probe(struct spi_device *spi) indio_dev->channels = ad8366_channels; indio_dev->num_channels = ARRAY_SIZE(ad8366_channels); + ret = ad8366_write(indio_dev, 0 , 0); + if (ret < 0) + goto error_disable_reg; + ret = iio_device_register(indio_dev); if (ret) goto error_disable_reg; - ad8366_write(indio_dev, 0, 0); - return 0; error_disable_reg: