Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

staging: iio: ad9832: allocate data before using

The regulator changes assigned data to an uninitialized pointer:

drivers/staging/iio/frequency/ad9832.c: In function 'ad9832_probe':
drivers/staging/iio/frequency/ad9832.c:214:11: error: 'st' may be used uninitialized in this function [-Werror=maybe-uninitialized]

This moves the allocation of the 'st' structure before its first
use, as it should have been.

Fixes: 43a07e48af44 ("staging: iio: ad9832: clean-up regulator 'reg'")
Fixes: a98461d79ba5 ("staging: iio: ad9832: add DVDD regulator")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>

authored by

Arnd Bergmann and committed by
Jonathan Cameron
6826fdbd 993403b9

+7 -7
+7 -7
drivers/staging/iio/frequency/ad9832.c
··· 211 211 return -ENODEV; 212 212 } 213 213 214 + indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st)); 215 + if (!indio_dev) 216 + return -ENOMEM; 217 + 218 + spi_set_drvdata(spi, indio_dev); 219 + st = iio_priv(indio_dev); 220 + 214 221 st->avdd = devm_regulator_get(&spi->dev, "avdd"); 215 222 if (IS_ERR(st->avdd)) 216 223 return PTR_ERR(st->avdd); ··· 240 233 goto error_disable_avdd; 241 234 } 242 235 243 - indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st)); 244 - if (!indio_dev) { 245 - ret = -ENOMEM; 246 - goto error_disable_dvdd; 247 - } 248 - spi_set_drvdata(spi, indio_dev); 249 - st = iio_priv(indio_dev); 250 236 st->mclk = pdata->mclk; 251 237 st->spi = spi; 252 238