Introduce a local struct device variable in ad9523_probe() to simplify
subsequent conversions and improve code readability.
No functional change.
Signed-off-by: Antoniu Miclaus <antoniu.miclaus@analog.com>
---
drivers/iio/frequency/ad9523.c | 17 +++++++++--------
1 file changed, 9 insertions(+), 8 deletions(-)
diff --git a/drivers/iio/frequency/ad9523.c b/drivers/iio/frequency/ad9523.c
index ad32eb66edca..6d15ec648280 100644
--- a/drivers/iio/frequency/ad9523.c
+++ b/drivers/iio/frequency/ad9523.c
@@ -948,17 +948,18 @@ static int ad9523_setup(struct iio_dev *indio_dev)
static int ad9523_probe(struct spi_device *spi)
{
- struct ad9523_platform_data *pdata = dev_get_platdata(&spi->dev);
+ struct device *dev = &spi->dev;
+ struct ad9523_platform_data *pdata = dev_get_platdata(dev);
struct iio_dev *indio_dev;
struct ad9523_state *st;
int ret;
if (!pdata) {
- dev_err(&spi->dev, "no platform data?\n");
+ dev_err(dev, "no platform data?\n");
return -EINVAL;
}
- indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st));
+ indio_dev = devm_iio_device_alloc(dev, sizeof(*st));
if (indio_dev == NULL)
return -ENOMEM;
@@ -966,16 +967,16 @@ static int ad9523_probe(struct spi_device *spi)
mutex_init(&st->lock);
- ret = devm_regulator_get_enable(&spi->dev, "vcc");
+ ret = devm_regulator_get_enable(dev, "vcc");
if (ret)
return ret;
- st->pwrdown_gpio = devm_gpiod_get_optional(&spi->dev, "powerdown",
+ st->pwrdown_gpio = devm_gpiod_get_optional(dev, "powerdown",
GPIOD_OUT_HIGH);
if (IS_ERR(st->pwrdown_gpio))
return PTR_ERR(st->pwrdown_gpio);
- st->reset_gpio = devm_gpiod_get_optional(&spi->dev, "reset",
+ st->reset_gpio = devm_gpiod_get_optional(dev, "reset",
GPIOD_OUT_LOW);
if (IS_ERR(st->reset_gpio))
return PTR_ERR(st->reset_gpio);
@@ -985,7 +986,7 @@ static int ad9523_probe(struct spi_device *spi)
gpiod_direction_output(st->reset_gpio, 1);
}
- st->sync_gpio = devm_gpiod_get_optional(&spi->dev, "sync",
+ st->sync_gpio = devm_gpiod_get_optional(dev, "sync",
GPIOD_OUT_HIGH);
if (IS_ERR(st->sync_gpio))
return PTR_ERR(st->sync_gpio);
@@ -1005,7 +1006,7 @@ static int ad9523_probe(struct spi_device *spi)
if (ret < 0)
return ret;
- return devm_iio_device_register(&spi->dev, indio_dev);
+ return devm_iio_device_register(dev, indio_dev);
}
static const struct spi_device_id ad9523_id[] = {
--
2.43.0
On Fri, Mar 06, 2026 at 12:24:47PM +0200, Antoniu Miclaus wrote:
> Introduce a local struct device variable in ad9523_probe() to simplify
> subsequent conversions and improve code readability.
...
> static int ad9523_probe(struct spi_device *spi)
> {
> - struct ad9523_platform_data *pdata = dev_get_platdata(&spi->dev);
> + struct device *dev = &spi->dev;
> + struct ad9523_platform_data *pdata = dev_get_platdata(dev);
It's always better to split assignment and definition when the result is going
to be validated. It makes code robust against potential changes in
between that might alter that variable / value.
struct ad9523_platform_data *pdata;
> struct iio_dev *indio_dev;
> struct ad9523_state *st;
> int ret;
pdata = dev_get_platdata(dev);
> if (!pdata) {
> - dev_err(&spi->dev, "no platform data?\n");
> + dev_err(dev, "no platform data?\n");
This line can be updated in the second patch altogether.
> return -EINVAL;
> }
...
> - st->reset_gpio = devm_gpiod_get_optional(&spi->dev, "reset",
> + st->reset_gpio = devm_gpiod_get_optional(dev, "reset",
> GPIOD_OUT_LOW);
> if (IS_ERR(st->reset_gpio))
> return PTR_ERR(st->reset_gpio);
Side note: The material to move to reset-gpio driver instead (I think we have
tons of the IIO drivers with the same).
--
With Best Regards,
Andy Shevchenko
© 2016 - 2026 Red Hat, Inc.