diff mbox series

power: supply: Simplify memory allocation

Message ID c09fc0b84cb046ad31bc1da67607bf0e9fa07085.1644079229.git.christophe.jaillet@wanadoo.fr
State Accepted
Commit a942f913a902e13218e3bdba3088b58124f63a44
Headers show
Series power: supply: Simplify memory allocation | expand

Commit Message

Christophe JAILLET Feb. 5, 2022, 4:40 p.m. UTC
Use devm_bitmap_zalloc() instead of hand writing it.

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
 drivers/power/supply/power_supply_hwmon.c | 15 +++------------
 1 file changed, 3 insertions(+), 12 deletions(-)

Comments

Sebastian Reichel Feb. 11, 2022, 6:50 p.m. UTC | #1
Hi,

On Sat, Feb 05, 2022 at 05:40:57PM +0100, Christophe JAILLET wrote:
> Use devm_bitmap_zalloc() instead of hand writing it.
> 
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> ---

Thanks, queued.

-- Sebastian

>  drivers/power/supply/power_supply_hwmon.c | 15 +++------------
>  1 file changed, 3 insertions(+), 12 deletions(-)
> 
> diff --git a/drivers/power/supply/power_supply_hwmon.c b/drivers/power/supply/power_supply_hwmon.c
> index bffe6d84c429..a48aa4afb828 100644
> --- a/drivers/power/supply/power_supply_hwmon.c
> +++ b/drivers/power/supply/power_supply_hwmon.c
> @@ -324,11 +324,6 @@ static const struct hwmon_chip_info power_supply_hwmon_chip_info = {
>  	.info = power_supply_hwmon_info,
>  };
>  
> -static void power_supply_hwmon_bitmap_free(void *data)
> -{
> -	bitmap_free(data);
> -}
> -
>  int power_supply_add_hwmon_sysfs(struct power_supply *psy)
>  {
>  	const struct power_supply_desc *desc = psy->desc;
> @@ -349,18 +344,14 @@ int power_supply_add_hwmon_sysfs(struct power_supply *psy)
>  	}
>  
>  	psyhw->psy = psy;
> -	psyhw->props = bitmap_zalloc(POWER_SUPPLY_PROP_TIME_TO_FULL_AVG + 1,
> -				     GFP_KERNEL);
> +	psyhw->props = devm_bitmap_zalloc(dev,
> +					  POWER_SUPPLY_PROP_TIME_TO_FULL_AVG + 1,
> +					  GFP_KERNEL);
>  	if (!psyhw->props) {
>  		ret = -ENOMEM;
>  		goto error;
>  	}
>  
> -	ret = devm_add_action_or_reset(dev, power_supply_hwmon_bitmap_free,
> -			      psyhw->props);
> -	if (ret)
> -		goto error;
> -
>  	for (i = 0; i < desc->num_properties; i++) {
>  		const enum power_supply_property prop = desc->properties[i];
>  
> -- 
> 2.32.0
>
diff mbox series

Patch

diff --git a/drivers/power/supply/power_supply_hwmon.c b/drivers/power/supply/power_supply_hwmon.c
index bffe6d84c429..a48aa4afb828 100644
--- a/drivers/power/supply/power_supply_hwmon.c
+++ b/drivers/power/supply/power_supply_hwmon.c
@@ -324,11 +324,6 @@  static const struct hwmon_chip_info power_supply_hwmon_chip_info = {
 	.info = power_supply_hwmon_info,
 };
 
-static void power_supply_hwmon_bitmap_free(void *data)
-{
-	bitmap_free(data);
-}
-
 int power_supply_add_hwmon_sysfs(struct power_supply *psy)
 {
 	const struct power_supply_desc *desc = psy->desc;
@@ -349,18 +344,14 @@  int power_supply_add_hwmon_sysfs(struct power_supply *psy)
 	}
 
 	psyhw->psy = psy;
-	psyhw->props = bitmap_zalloc(POWER_SUPPLY_PROP_TIME_TO_FULL_AVG + 1,
-				     GFP_KERNEL);
+	psyhw->props = devm_bitmap_zalloc(dev,
+					  POWER_SUPPLY_PROP_TIME_TO_FULL_AVG + 1,
+					  GFP_KERNEL);
 	if (!psyhw->props) {
 		ret = -ENOMEM;
 		goto error;
 	}
 
-	ret = devm_add_action_or_reset(dev, power_supply_hwmon_bitmap_free,
-			      psyhw->props);
-	if (ret)
-		goto error;
-
 	for (i = 0; i < desc->num_properties; i++) {
 		const enum power_supply_property prop = desc->properties[i];