[PATCH v4 11/12] iio: filter: admv8818: add dev variable

Antoniu Miclaus posted 12 patches 1 month, 1 week ago
[PATCH v4 11/12] iio: filter: admv8818: add dev variable
Posted by Antoniu Miclaus 1 month, 1 week ago
Introduce a local struct device pointer in functions that reference
&spi->dev for device-managed resource calls and device property reads,
improving code readability.

Signed-off-by: Antoniu Miclaus <antoniu.miclaus@analog.com>
---
 drivers/iio/filter/admv8818.c | 21 +++++++++++----------
 1 file changed, 11 insertions(+), 10 deletions(-)

diff --git a/drivers/iio/filter/admv8818.c b/drivers/iio/filter/admv8818.c
index 19f823446cda..5fafd71da2b3 100644
--- a/drivers/iio/filter/admv8818.c
+++ b/drivers/iio/filter/admv8818.c
@@ -701,12 +701,12 @@ static int admv8818_init(struct admv8818_state *st)
 
 static int admv8818_clk_setup(struct admv8818_state *st)
 {
-	struct spi_device *spi = st->spi;
+	struct device *dev = &st->spi->dev;
 	int ret;
 
-	st->clkin = devm_clk_get_optional(&spi->dev, "rf_in");
+	st->clkin = devm_clk_get_optional(dev, "rf_in");
 	if (IS_ERR(st->clkin))
-		return dev_err_probe(&spi->dev, PTR_ERR(st->clkin),
+		return dev_err_probe(dev, PTR_ERR(st->clkin),
 				     "failed to get the input clock\n");
 	else if (!st->clkin)
 		return 0;
@@ -715,7 +715,7 @@ static int admv8818_clk_setup(struct admv8818_state *st)
 	if (ret)
 		return ret;
 
-	ret = devm_add_action_or_reset(&spi->dev, admv8818_clk_disable, st);
+	ret = devm_add_action_or_reset(dev, admv8818_clk_disable, st);
 	if (ret)
 		return ret;
 
@@ -724,16 +724,16 @@ static int admv8818_clk_setup(struct admv8818_state *st)
 	if (ret < 0)
 		return ret;
 
-	return devm_add_action_or_reset(&spi->dev, admv8818_clk_notifier_unreg, st);
+	return devm_add_action_or_reset(dev, admv8818_clk_notifier_unreg, st);
 }
 
 static int admv8818_read_properties(struct admv8818_state *st)
 {
-	struct spi_device *spi = st->spi;
+	struct device *dev = &st->spi->dev;
 	u32 mhz;
 	int ret;
 
-	ret = device_property_read_u32(&spi->dev, "adi,lpf-margin-mhz", &mhz);
+	ret = device_property_read_u32(dev, "adi,lpf-margin-mhz", &mhz);
 	if (ret == 0)
 		st->lpf_margin_hz = (u64)mhz * HZ_PER_MHZ;
 	else if (ret == -EINVAL)
@@ -742,7 +742,7 @@ static int admv8818_read_properties(struct admv8818_state *st)
 		return ret;
 
 
-	ret = device_property_read_u32(&spi->dev, "adi,hpf-margin-mhz", &mhz);
+	ret = device_property_read_u32(dev, "adi,hpf-margin-mhz", &mhz);
 	if (ret == 0)
 		st->hpf_margin_hz = (u64)mhz * HZ_PER_MHZ;
 	else if (ret == -EINVAL)
@@ -758,9 +758,10 @@ static int admv8818_probe(struct spi_device *spi)
 	struct iio_dev *indio_dev;
 	struct regmap *regmap;
 	struct admv8818_state *st;
+	struct device *dev = &spi->dev;
 	int ret;
 
-	indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st));
+	indio_dev = devm_iio_device_alloc(dev, sizeof(*st));
 	if (!indio_dev)
 		return -ENOMEM;
 
@@ -792,7 +793,7 @@ static int admv8818_probe(struct spi_device *spi)
 	if (ret)
 		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 admv8818_id[] = {
-- 
2.43.0