linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH V2] power: supply: lp8788: Fix an error handling path in 'lp8788_charger_probe()'
@ 2020-05-09  8:23 Christophe JAILLET
  2020-05-09 23:43 ` Sebastian Reichel
  0 siblings, 1 reply; 2+ messages in thread
From: Christophe JAILLET @ 2020-05-09  8:23 UTC (permalink / raw)
  To: milo.kim, sre, anton.vorontsov
  Cc: linux-pm, linux-kernel, kernel-janitors, Christophe JAILLET

In the probe function, in case of error, resources allocated in
'lp8788_setup_adc_channel()' must be released.

This can be achieved easily by using the devm_ variant of
'iio_channel_get()'.
This has the extra benefit to simplify the remove function and to axe the
'lp8788_release_adc_channel()' function which is now useless.

Fixes: 98a276649358 ("power_supply: Add new lp8788 charger driver")
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
V2: use devm_iio_channel_get instead of iio_channel_get and simplify code
---
 drivers/power/supply/lp8788-charger.c | 18 ++----------------
 1 file changed, 2 insertions(+), 16 deletions(-)

diff --git a/drivers/power/supply/lp8788-charger.c b/drivers/power/supply/lp8788-charger.c
index 84a206f42a8e..e7931ffb7151 100644
--- a/drivers/power/supply/lp8788-charger.c
+++ b/drivers/power/supply/lp8788-charger.c
@@ -572,27 +572,14 @@ static void lp8788_setup_adc_channel(struct device *dev,
 		return;
 
 	/* ADC channel for battery voltage */
-	chan = iio_channel_get(dev, pdata->adc_vbatt);
+	chan = devm_iio_channel_get(dev, pdata->adc_vbatt);
 	pchg->chan[LP8788_VBATT] = IS_ERR(chan) ? NULL : chan;
 
 	/* ADC channel for battery temperature */
-	chan = iio_channel_get(dev, pdata->adc_batt_temp);
+	chan = devm_iio_channel_get(dev, pdata->adc_batt_temp);
 	pchg->chan[LP8788_BATT_TEMP] = IS_ERR(chan) ? NULL : chan;
 }
 
-static void lp8788_release_adc_channel(struct lp8788_charger *pchg)
-{
-	int i;
-
-	for (i = 0; i < LP8788_NUM_CHG_ADC; i++) {
-		if (!pchg->chan[i])
-			continue;
-
-		iio_channel_release(pchg->chan[i]);
-		pchg->chan[i] = NULL;
-	}
-}
-
 static ssize_t lp8788_show_charger_status(struct device *dev,
 				struct device_attribute *attr, char *buf)
 {
@@ -735,7 +722,6 @@ static int lp8788_charger_remove(struct platform_device *pdev)
 	flush_work(&pchg->charger_work);
 	lp8788_irq_unregister(pdev, pchg);
 	lp8788_psy_unregister(pchg);
-	lp8788_release_adc_channel(pchg);
 
 	return 0;
 }
-- 
2.25.1


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

* Re: [PATCH V2] power: supply: lp8788: Fix an error handling path in 'lp8788_charger_probe()'
  2020-05-09  8:23 [PATCH V2] power: supply: lp8788: Fix an error handling path in 'lp8788_charger_probe()' Christophe JAILLET
@ 2020-05-09 23:43 ` Sebastian Reichel
  0 siblings, 0 replies; 2+ messages in thread
From: Sebastian Reichel @ 2020-05-09 23:43 UTC (permalink / raw)
  To: Christophe JAILLET
  Cc: milo.kim, anton.vorontsov, linux-pm, linux-kernel, kernel-janitors

[-- Attachment #1: Type: text/plain, Size: 2292 bytes --]

Hi,

On Sat, May 09, 2020 at 10:23:23AM +0200, Christophe JAILLET wrote:
> In the probe function, in case of error, resources allocated in
> 'lp8788_setup_adc_channel()' must be released.
> 
> This can be achieved easily by using the devm_ variant of
> 'iio_channel_get()'.
> This has the extra benefit to simplify the remove function and to axe the
> 'lp8788_release_adc_channel()' function which is now useless.
> 
> Fixes: 98a276649358 ("power_supply: Add new lp8788 charger driver")
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> ---
> V2: use devm_iio_channel_get instead of iio_channel_get and simplify code
> ---

Thanks, queued.

-- Sebastian

>  drivers/power/supply/lp8788-charger.c | 18 ++----------------
>  1 file changed, 2 insertions(+), 16 deletions(-)
> 
> diff --git a/drivers/power/supply/lp8788-charger.c b/drivers/power/supply/lp8788-charger.c
> index 84a206f42a8e..e7931ffb7151 100644
> --- a/drivers/power/supply/lp8788-charger.c
> +++ b/drivers/power/supply/lp8788-charger.c
> @@ -572,27 +572,14 @@ static void lp8788_setup_adc_channel(struct device *dev,
>  		return;
>  
>  	/* ADC channel for battery voltage */
> -	chan = iio_channel_get(dev, pdata->adc_vbatt);
> +	chan = devm_iio_channel_get(dev, pdata->adc_vbatt);
>  	pchg->chan[LP8788_VBATT] = IS_ERR(chan) ? NULL : chan;
>  
>  	/* ADC channel for battery temperature */
> -	chan = iio_channel_get(dev, pdata->adc_batt_temp);
> +	chan = devm_iio_channel_get(dev, pdata->adc_batt_temp);
>  	pchg->chan[LP8788_BATT_TEMP] = IS_ERR(chan) ? NULL : chan;
>  }
>  
> -static void lp8788_release_adc_channel(struct lp8788_charger *pchg)
> -{
> -	int i;
> -
> -	for (i = 0; i < LP8788_NUM_CHG_ADC; i++) {
> -		if (!pchg->chan[i])
> -			continue;
> -
> -		iio_channel_release(pchg->chan[i]);
> -		pchg->chan[i] = NULL;
> -	}
> -}
> -
>  static ssize_t lp8788_show_charger_status(struct device *dev,
>  				struct device_attribute *attr, char *buf)
>  {
> @@ -735,7 +722,6 @@ static int lp8788_charger_remove(struct platform_device *pdev)
>  	flush_work(&pchg->charger_work);
>  	lp8788_irq_unregister(pdev, pchg);
>  	lp8788_psy_unregister(pchg);
> -	lp8788_release_adc_channel(pchg);
>  
>  	return 0;
>  }
> -- 
> 2.25.1
> 

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

end of thread, other threads:[~2020-05-09 23:43 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-09  8:23 [PATCH V2] power: supply: lp8788: Fix an error handling path in 'lp8788_charger_probe()' Christophe JAILLET
2020-05-09 23:43 ` Sebastian Reichel

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).