linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 01/14] iio: adc: sc27xx: Introduce local variable 'struct device *dev'
@ 2019-07-08 12:32 Fuqian Huang
  2019-07-14 14:50 ` Jonathan Cameron
  0 siblings, 1 reply; 2+ messages in thread
From: Fuqian Huang @ 2019-07-08 12:32 UTC (permalink / raw)
  Cc: Jonathan Cameron, linux-iio, linux-kernel, Fuqian Huang

Introduce local variable 'struct device *dev' and use it instead of
dereferencing it repeatly.

Signed-off-by: Fuqian Huang <huangfq.daxian@gmail.com>
---
 drivers/iio/adc/sc27xx_adc.c | 41 +++++++++++++++++++++--------------------
 1 file changed, 21 insertions(+), 20 deletions(-)

diff --git a/drivers/iio/adc/sc27xx_adc.c b/drivers/iio/adc/sc27xx_adc.c
index f7f7a18904b4..ec86f640e963 100644
--- a/drivers/iio/adc/sc27xx_adc.c
+++ b/drivers/iio/adc/sc27xx_adc.c
@@ -504,88 +504,89 @@ static void sc27xx_adc_free_hwlock(void *_data)
 
 static int sc27xx_adc_probe(struct platform_device *pdev)
 {
-	struct device_node *np = pdev->dev.of_node;
+	struct device *dev = &pdev->dev;
+	struct device_node *np = dev->of_node;
 	struct sc27xx_adc_data *sc27xx_data;
 	struct iio_dev *indio_dev;
 	int ret;
 
-	indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(*sc27xx_data));
+	indio_dev = devm_iio_device_alloc(dev, sizeof(*sc27xx_data));
 	if (!indio_dev)
 		return -ENOMEM;
 
 	sc27xx_data = iio_priv(indio_dev);
 
-	sc27xx_data->regmap = dev_get_regmap(pdev->dev.parent, NULL);
+	sc27xx_data->regmap = dev_get_regmap(dev->parent, NULL);
 	if (!sc27xx_data->regmap) {
-		dev_err(&pdev->dev, "failed to get ADC regmap\n");
+		dev_err(dev, "failed to get ADC regmap\n");
 		return -ENODEV;
 	}
 
 	ret = of_property_read_u32(np, "reg", &sc27xx_data->base);
 	if (ret) {
-		dev_err(&pdev->dev, "failed to get ADC base address\n");
+		dev_err(dev, "failed to get ADC base address\n");
 		return ret;
 	}
 
 	sc27xx_data->irq = platform_get_irq(pdev, 0);
 	if (sc27xx_data->irq < 0) {
-		dev_err(&pdev->dev, "failed to get ADC irq number\n");
+		dev_err(dev, "failed to get ADC irq number\n");
 		return sc27xx_data->irq;
 	}
 
 	ret = of_hwspin_lock_get_id(np, 0);
 	if (ret < 0) {
-		dev_err(&pdev->dev, "failed to get hwspinlock id\n");
+		dev_err(dev, "failed to get hwspinlock id\n");
 		return ret;
 	}
 
 	sc27xx_data->hwlock = hwspin_lock_request_specific(ret);
 	if (!sc27xx_data->hwlock) {
-		dev_err(&pdev->dev, "failed to request hwspinlock\n");
+		dev_err(dev, "failed to request hwspinlock\n");
 		return -ENXIO;
 	}
 
-	ret = devm_add_action(&pdev->dev, sc27xx_adc_free_hwlock,
+	ret = devm_add_action(dev, sc27xx_adc_free_hwlock,
 			      sc27xx_data->hwlock);
 	if (ret) {
 		sc27xx_adc_free_hwlock(sc27xx_data->hwlock);
-		dev_err(&pdev->dev, "failed to add hwspinlock action\n");
+		dev_err(dev, "failed to add hwspinlock action\n");
 		return ret;
 	}
 
 	init_completion(&sc27xx_data->completion);
-	sc27xx_data->dev = &pdev->dev;
+	sc27xx_data->dev = dev;
 
 	ret = sc27xx_adc_enable(sc27xx_data);
 	if (ret) {
-		dev_err(&pdev->dev, "failed to enable ADC module\n");
+		dev_err(dev, "failed to enable ADC module\n");
 		return ret;
 	}
 
-	ret = devm_add_action(&pdev->dev, sc27xx_adc_disable, sc27xx_data);
+	ret = devm_add_action(dev, sc27xx_adc_disable, sc27xx_data);
 	if (ret) {
 		sc27xx_adc_disable(sc27xx_data);
-		dev_err(&pdev->dev, "failed to add ADC disable action\n");
+		dev_err(dev, "failed to add ADC disable action\n");
 		return ret;
 	}
 
-	ret = devm_request_threaded_irq(&pdev->dev, sc27xx_data->irq, NULL,
+	ret = devm_request_threaded_irq(dev, sc27xx_data->irq, NULL,
 					sc27xx_adc_isr, IRQF_ONESHOT,
 					pdev->name, sc27xx_data);
 	if (ret) {
-		dev_err(&pdev->dev, "failed to request ADC irq\n");
+		dev_err(dev, "failed to request ADC irq\n");
 		return ret;
 	}
 
-	indio_dev->dev.parent = &pdev->dev;
-	indio_dev->name = dev_name(&pdev->dev);
+	indio_dev->dev.parent = dev;
+	indio_dev->name = dev_name(dev);
 	indio_dev->modes = INDIO_DIRECT_MODE;
 	indio_dev->info = &sc27xx_info;
 	indio_dev->channels = sc27xx_channels;
 	indio_dev->num_channels = ARRAY_SIZE(sc27xx_channels);
-	ret = devm_iio_device_register(&pdev->dev, indio_dev);
+	ret = devm_iio_device_register(dev, indio_dev);
 	if (ret)
-		dev_err(&pdev->dev, "could not register iio (ADC)");
+		dev_err(dev, "could not register iio (ADC)");
 
 	return ret;
 }
-- 
2.11.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH 01/14] iio: adc: sc27xx: Introduce local variable 'struct device *dev'
  2019-07-08 12:32 [PATCH 01/14] iio: adc: sc27xx: Introduce local variable 'struct device *dev' Fuqian Huang
@ 2019-07-14 14:50 ` Jonathan Cameron
  0 siblings, 0 replies; 2+ messages in thread
From: Jonathan Cameron @ 2019-07-14 14:50 UTC (permalink / raw)
  To: Fuqian Huang; +Cc: linux-iio, linux-kernel, freeman.liu

On Mon,  8 Jul 2019 20:32:21 +0800
Fuqian Huang <huangfq.daxian@gmail.com> wrote:

> Introduce local variable 'struct device *dev' and use it instead of
> dereferencing it repeatly.
> 
> Signed-off-by: Fuqian Huang <huangfq.daxian@gmail.com>

Ok, this is a fair bit of churn but probably on balance a worthwhile
little improvement.

Applied to the togreg branch of iio.git and pushed out
as testing to see if we missed anything.

+CC Freeman Liu as original author.

Thanks,

Jonathan


> ---
>  drivers/iio/adc/sc27xx_adc.c | 41 +++++++++++++++++++++--------------------
>  1 file changed, 21 insertions(+), 20 deletions(-)
> 
> diff --git a/drivers/iio/adc/sc27xx_adc.c b/drivers/iio/adc/sc27xx_adc.c
> index f7f7a18904b4..ec86f640e963 100644
> --- a/drivers/iio/adc/sc27xx_adc.c
> +++ b/drivers/iio/adc/sc27xx_adc.c
> @@ -504,88 +504,89 @@ static void sc27xx_adc_free_hwlock(void *_data)
>  
>  static int sc27xx_adc_probe(struct platform_device *pdev)
>  {
> -	struct device_node *np = pdev->dev.of_node;
> +	struct device *dev = &pdev->dev;
> +	struct device_node *np = dev->of_node;
>  	struct sc27xx_adc_data *sc27xx_data;
>  	struct iio_dev *indio_dev;
>  	int ret;
>  
> -	indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(*sc27xx_data));
> +	indio_dev = devm_iio_device_alloc(dev, sizeof(*sc27xx_data));
>  	if (!indio_dev)
>  		return -ENOMEM;
>  
>  	sc27xx_data = iio_priv(indio_dev);
>  
> -	sc27xx_data->regmap = dev_get_regmap(pdev->dev.parent, NULL);
> +	sc27xx_data->regmap = dev_get_regmap(dev->parent, NULL);
>  	if (!sc27xx_data->regmap) {
> -		dev_err(&pdev->dev, "failed to get ADC regmap\n");
> +		dev_err(dev, "failed to get ADC regmap\n");
>  		return -ENODEV;
>  	}
>  
>  	ret = of_property_read_u32(np, "reg", &sc27xx_data->base);
>  	if (ret) {
> -		dev_err(&pdev->dev, "failed to get ADC base address\n");
> +		dev_err(dev, "failed to get ADC base address\n");
>  		return ret;
>  	}
>  
>  	sc27xx_data->irq = platform_get_irq(pdev, 0);
>  	if (sc27xx_data->irq < 0) {
> -		dev_err(&pdev->dev, "failed to get ADC irq number\n");
> +		dev_err(dev, "failed to get ADC irq number\n");
>  		return sc27xx_data->irq;
>  	}
>  
>  	ret = of_hwspin_lock_get_id(np, 0);
>  	if (ret < 0) {
> -		dev_err(&pdev->dev, "failed to get hwspinlock id\n");
> +		dev_err(dev, "failed to get hwspinlock id\n");
>  		return ret;
>  	}
>  
>  	sc27xx_data->hwlock = hwspin_lock_request_specific(ret);
>  	if (!sc27xx_data->hwlock) {
> -		dev_err(&pdev->dev, "failed to request hwspinlock\n");
> +		dev_err(dev, "failed to request hwspinlock\n");
>  		return -ENXIO;
>  	}
>  
> -	ret = devm_add_action(&pdev->dev, sc27xx_adc_free_hwlock,
> +	ret = devm_add_action(dev, sc27xx_adc_free_hwlock,
>  			      sc27xx_data->hwlock);
>  	if (ret) {
>  		sc27xx_adc_free_hwlock(sc27xx_data->hwlock);
> -		dev_err(&pdev->dev, "failed to add hwspinlock action\n");
> +		dev_err(dev, "failed to add hwspinlock action\n");
>  		return ret;
>  	}
>  
>  	init_completion(&sc27xx_data->completion);
> -	sc27xx_data->dev = &pdev->dev;
> +	sc27xx_data->dev = dev;
>  
>  	ret = sc27xx_adc_enable(sc27xx_data);
>  	if (ret) {
> -		dev_err(&pdev->dev, "failed to enable ADC module\n");
> +		dev_err(dev, "failed to enable ADC module\n");
>  		return ret;
>  	}
>  
> -	ret = devm_add_action(&pdev->dev, sc27xx_adc_disable, sc27xx_data);
> +	ret = devm_add_action(dev, sc27xx_adc_disable, sc27xx_data);
>  	if (ret) {
>  		sc27xx_adc_disable(sc27xx_data);
> -		dev_err(&pdev->dev, "failed to add ADC disable action\n");
> +		dev_err(dev, "failed to add ADC disable action\n");
>  		return ret;
>  	}
>  
> -	ret = devm_request_threaded_irq(&pdev->dev, sc27xx_data->irq, NULL,
> +	ret = devm_request_threaded_irq(dev, sc27xx_data->irq, NULL,
>  					sc27xx_adc_isr, IRQF_ONESHOT,
>  					pdev->name, sc27xx_data);
>  	if (ret) {
> -		dev_err(&pdev->dev, "failed to request ADC irq\n");
> +		dev_err(dev, "failed to request ADC irq\n");
>  		return ret;
>  	}
>  
> -	indio_dev->dev.parent = &pdev->dev;
> -	indio_dev->name = dev_name(&pdev->dev);
> +	indio_dev->dev.parent = dev;
> +	indio_dev->name = dev_name(dev);
>  	indio_dev->modes = INDIO_DIRECT_MODE;
>  	indio_dev->info = &sc27xx_info;
>  	indio_dev->channels = sc27xx_channels;
>  	indio_dev->num_channels = ARRAY_SIZE(sc27xx_channels);
> -	ret = devm_iio_device_register(&pdev->dev, indio_dev);
> +	ret = devm_iio_device_register(dev, indio_dev);
>  	if (ret)
> -		dev_err(&pdev->dev, "could not register iio (ADC)");
> +		dev_err(dev, "could not register iio (ADC)");
>  
>  	return ret;
>  }


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-07-14 14:50 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-08 12:32 [PATCH 01/14] iio: adc: sc27xx: Introduce local variable 'struct device *dev' Fuqian Huang
2019-07-14 14:50 ` Jonathan Cameron

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).