public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] power: generic-adc-battery: use devm_kcalloc for psy->properties
@ 2014-05-16 13:12 Heiko Stübner
  2014-05-16 13:14 ` [PATCH 2/2] power: generic-adc-battery: return meaningful error when no channel available Heiko Stübner
  2014-07-07 11:46 ` [PATCH 1/2] power: generic-adc-battery: use devm_kcalloc for psy->properties Heiko Stübner
  0 siblings, 2 replies; 3+ messages in thread
From: Heiko Stübner @ 2014-05-16 13:12 UTC (permalink / raw)
  To: Dmitry Eremin-Solenikov, David Woodhouse; +Cc: linux-kernel

From: Heiko Stuebner <heiko.stuebner@bq.com>

This reduces the amount of code spent on initialization and cleanup
of the properties memory and also simplifies the error handling a bit.

Signed-off-by: Heiko Stuebner <heiko.stuebner@bq.com>
---
 drivers/power/generic-adc-battery.c | 14 ++++----------
 1 file changed, 4 insertions(+), 10 deletions(-)

diff --git a/drivers/power/generic-adc-battery.c b/drivers/power/generic-adc-battery.c
index 59a1421..540d57f 100644
--- a/drivers/power/generic-adc-battery.c
+++ b/drivers/power/generic-adc-battery.c
@@ -267,13 +267,11 @@ static int gab_probe(struct platform_device *pdev)
 	 * copying the static properties and allocating extra memory for holding
 	 * the extra configurable properties received from platform data.
 	 */
-	psy->properties = kcalloc(ARRAY_SIZE(gab_props) +
+	psy->properties = devm_kcalloc(&pdev->dev, ARRAY_SIZE(gab_props) +
 					ARRAY_SIZE(gab_chan_name),
 					sizeof(*psy->properties), GFP_KERNEL);
-	if (!psy->properties) {
-		ret = -ENOMEM;
-		goto first_mem_fail;
-	}
+	if (!psy->properties)
+		return -ENOMEM;
 
 	memcpy(psy->properties, gab_props, sizeof(gab_props));
 	properties = (enum power_supply_property *)
@@ -301,7 +299,7 @@ static int gab_probe(struct platform_device *pdev)
 	/* none of the channels are supported so let's bail out */
 	if (index == 0) {
 		ret = -ENODEV;
-		goto second_mem_fail;
+		return ret;
 	}
 
 	/*
@@ -348,9 +346,6 @@ err_reg_fail:
 		if (adc_bat->channel[chan])
 			iio_channel_release(adc_bat->channel[chan]);
 	}
-second_mem_fail:
-	kfree(psy->properties);
-first_mem_fail:
 	return ret;
 }
 
@@ -372,7 +367,6 @@ static int gab_remove(struct platform_device *pdev)
 			iio_channel_release(adc_bat->channel[chan]);
 	}
 
-	kfree(adc_bat->psy.properties);
 	cancel_delayed_work(&adc_bat->bat_work);
 	return 0;
 }
-- 
1.9.0



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

* [PATCH 2/2] power: generic-adc-battery: return meaningful error when no channel available
  2014-05-16 13:12 [PATCH 1/2] power: generic-adc-battery: use devm_kcalloc for psy->properties Heiko Stübner
@ 2014-05-16 13:14 ` Heiko Stübner
  2014-07-07 11:46 ` [PATCH 1/2] power: generic-adc-battery: use devm_kcalloc for psy->properties Heiko Stübner
  1 sibling, 0 replies; 3+ messages in thread
From: Heiko Stübner @ 2014-05-16 13:14 UTC (permalink / raw)
  To: Dmitry Eremin-Solenikov, David Woodhouse; +Cc: linux-kernel

From: Heiko Stuebner <heiko.stuebner@bq.com>

When no channel was found the driver currently always returns -ENODEV. This
hides the actual error which is available in ret from the kernel and disables
for example -EPROBE_DEFER handling.

Signed-off-by: Heiko Stuebner <heiko.stuebner@bq.com>
---
 drivers/power/generic-adc-battery.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/power/generic-adc-battery.c b/drivers/power/generic-adc-battery.c
index 540d57f..02f434b 100644
--- a/drivers/power/generic-adc-battery.c
+++ b/drivers/power/generic-adc-battery.c
@@ -297,10 +297,8 @@ static int gab_probe(struct platform_device *pdev)
 	}
 
 	/* none of the channels are supported so let's bail out */
-	if (index == 0) {
-		ret = -ENODEV;
+	if (index == 0)
 		return ret;
-	}
 
 	/*
 	 * Total number of properties is equal to static properties
-- 
1.9.0



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

* Re: [PATCH 1/2] power: generic-adc-battery: use devm_kcalloc for psy->properties
  2014-05-16 13:12 [PATCH 1/2] power: generic-adc-battery: use devm_kcalloc for psy->properties Heiko Stübner
  2014-05-16 13:14 ` [PATCH 2/2] power: generic-adc-battery: return meaningful error when no channel available Heiko Stübner
@ 2014-07-07 11:46 ` Heiko Stübner
  1 sibling, 0 replies; 3+ messages in thread
From: Heiko Stübner @ 2014-07-07 11:46 UTC (permalink / raw)
  To: Dmitry Eremin-Solenikov; +Cc: David Woodhouse, linux-kernel

Am Freitag, 16. Mai 2014, 15:12:50 schrieb Heiko Stübner:
> From: Heiko Stuebner <heiko.stuebner@bq.com>
> 
> This reduces the amount of code spent on initialization and cleanup
> of the properties memory and also simplifies the error handling a bit.
> 
> Signed-off-by: Heiko Stuebner <heiko.stuebner@bq.com>

any comments on these two patches?


Thanks
Heiko

> ---
>  drivers/power/generic-adc-battery.c | 14 ++++----------
>  1 file changed, 4 insertions(+), 10 deletions(-)
> 
> diff --git a/drivers/power/generic-adc-battery.c
> b/drivers/power/generic-adc-battery.c index 59a1421..540d57f 100644
> --- a/drivers/power/generic-adc-battery.c
> +++ b/drivers/power/generic-adc-battery.c
> @@ -267,13 +267,11 @@ static int gab_probe(struct platform_device *pdev)
>  	 * copying the static properties and allocating extra memory for holding
>  	 * the extra configurable properties received from platform data.
>  	 */
> -	psy->properties = kcalloc(ARRAY_SIZE(gab_props) +
> +	psy->properties = devm_kcalloc(&pdev->dev, ARRAY_SIZE(gab_props) +
>  					ARRAY_SIZE(gab_chan_name),
>  					sizeof(*psy->properties), GFP_KERNEL);
> -	if (!psy->properties) {
> -		ret = -ENOMEM;
> -		goto first_mem_fail;
> -	}
> +	if (!psy->properties)
> +		return -ENOMEM;
> 
>  	memcpy(psy->properties, gab_props, sizeof(gab_props));
>  	properties = (enum power_supply_property *)
> @@ -301,7 +299,7 @@ static int gab_probe(struct platform_device *pdev)
>  	/* none of the channels are supported so let's bail out */
>  	if (index == 0) {
>  		ret = -ENODEV;
> -		goto second_mem_fail;
> +		return ret;
>  	}
> 
>  	/*
> @@ -348,9 +346,6 @@ err_reg_fail:
>  		if (adc_bat->channel[chan])
>  			iio_channel_release(adc_bat->channel[chan]);
>  	}
> -second_mem_fail:
> -	kfree(psy->properties);
> -first_mem_fail:
>  	return ret;
>  }
> 
> @@ -372,7 +367,6 @@ static int gab_remove(struct platform_device *pdev)
>  			iio_channel_release(adc_bat->channel[chan]);
>  	}
> 
> -	kfree(adc_bat->psy.properties);
>  	cancel_delayed_work(&adc_bat->bat_work);
>  	return 0;
>  }


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

end of thread, other threads:[~2014-07-07 11:45 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-05-16 13:12 [PATCH 1/2] power: generic-adc-battery: use devm_kcalloc for psy->properties Heiko Stübner
2014-05-16 13:14 ` [PATCH 2/2] power: generic-adc-battery: return meaningful error when no channel available Heiko Stübner
2014-07-07 11:46 ` [PATCH 1/2] power: generic-adc-battery: use devm_kcalloc for psy->properties Heiko Stübner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox