Re: [PATCH 3/4] iio: frequency: ad9523: add dev variable

From: Andy Shevchenko

Date: Fri Mar 06 2026 - 09:48:57 EST


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