[3/4] power: supply: generic-adc-battery: Prepare for const properties
diff mbox series

Message ID 20200413183853.1088823-4-sebastian.reichel@collabora.com
State New
Headers show
Series
  • Add support for constant power-supply property tables
Related show

Commit Message

Sebastian Reichel April 13, 2020, 6:38 p.m. UTC
This prepares the driver to work with the properties entry
in power_supply_desc marked as const.

Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
---
 drivers/power/supply/generic-adc-battery.c | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)

Comments

Enric Balletbo i Serra April 14, 2020, 3:57 p.m. UTC | #1
Hi Sebastian,

On 13/4/20 20:38, Sebastian Reichel wrote:
> This prepares the driver to work with the properties entry
> in power_supply_desc marked as const.
> 
> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>

Reviewed-by: Enric Balletbo i Serra <enric.balletbo@collabora.com>

> ---
>  drivers/power/supply/generic-adc-battery.c | 22 +++++++++++-----------
>  1 file changed, 11 insertions(+), 11 deletions(-)
> 
> diff --git a/drivers/power/supply/generic-adc-battery.c b/drivers/power/supply/generic-adc-battery.c
> index bc462d1ec963..caa829738ef7 100644
> --- a/drivers/power/supply/generic-adc-battery.c
> +++ b/drivers/power/supply/generic-adc-battery.c
> @@ -241,6 +241,7 @@ static int gab_probe(struct platform_device *pdev)
>  	struct power_supply_desc *psy_desc;
>  	struct power_supply_config psy_cfg = {};
>  	struct gab_platform_data *pdata = pdev->dev.platform_data;
> +	enum power_supply_property *properties;
>  	int ret = 0;
>  	int chan;
>  	int index = ARRAY_SIZE(gab_props);
> @@ -268,16 +269,16 @@ 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_desc->properties = kcalloc(ARRAY_SIZE(gab_props) +
> -					ARRAY_SIZE(gab_chan_name),
> -					sizeof(*psy_desc->properties),
> -					GFP_KERNEL);
> -	if (!psy_desc->properties) {
> +	properties = kcalloc(ARRAY_SIZE(gab_props) +
> +			     ARRAY_SIZE(gab_chan_name),
> +			     sizeof(*properties),
> +			     GFP_KERNEL);
> +	if (!properties) {
>  		ret = -ENOMEM;
>  		goto first_mem_fail;
>  	}
>  
> -	memcpy(psy_desc->properties, gab_props, sizeof(gab_props));
> +	memcpy(properties, gab_props, sizeof(gab_props));
>  
>  	/*
>  	 * getting channel from iio and copying the battery properties
> @@ -294,13 +295,11 @@ static int gab_probe(struct platform_device *pdev)
>  			int index2;
>  
>  			for (index2 = 0; index2 < index; index2++) {
> -				if (psy_desc->properties[index2] ==
> -				    gab_dyn_props[chan])
> +				if (properties[index2] == gab_dyn_props[chan])
>  					break;	/* already known */
>  			}
>  			if (index2 == index)	/* really new */
> -				psy_desc->properties[index++] =
> -					gab_dyn_props[chan];
> +				properties[index++] = gab_dyn_props[chan];
>  			any = true;
>  		}
>  	}
> @@ -317,6 +316,7 @@ static int gab_probe(struct platform_device *pdev)
>  	 * as come channels may be not be supported by the device.So
>  	 * we need to take care of that.
>  	 */
> +	psy_desc->properties = properties;
>  	psy_desc->num_properties = index;
>  
>  	adc_bat->psy = power_supply_register(&pdev->dev, psy_desc, &psy_cfg);
> @@ -358,7 +358,7 @@ static int gab_probe(struct platform_device *pdev)
>  			iio_channel_release(adc_bat->channel[chan]);
>  	}
>  second_mem_fail:
> -	kfree(psy_desc->properties);
> +	kfree(properties);
>  first_mem_fail:
>  	return ret;
>  }
>

Patch
diff mbox series

diff --git a/drivers/power/supply/generic-adc-battery.c b/drivers/power/supply/generic-adc-battery.c
index bc462d1ec963..caa829738ef7 100644
--- a/drivers/power/supply/generic-adc-battery.c
+++ b/drivers/power/supply/generic-adc-battery.c
@@ -241,6 +241,7 @@  static int gab_probe(struct platform_device *pdev)
 	struct power_supply_desc *psy_desc;
 	struct power_supply_config psy_cfg = {};
 	struct gab_platform_data *pdata = pdev->dev.platform_data;
+	enum power_supply_property *properties;
 	int ret = 0;
 	int chan;
 	int index = ARRAY_SIZE(gab_props);
@@ -268,16 +269,16 @@  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_desc->properties = kcalloc(ARRAY_SIZE(gab_props) +
-					ARRAY_SIZE(gab_chan_name),
-					sizeof(*psy_desc->properties),
-					GFP_KERNEL);
-	if (!psy_desc->properties) {
+	properties = kcalloc(ARRAY_SIZE(gab_props) +
+			     ARRAY_SIZE(gab_chan_name),
+			     sizeof(*properties),
+			     GFP_KERNEL);
+	if (!properties) {
 		ret = -ENOMEM;
 		goto first_mem_fail;
 	}
 
-	memcpy(psy_desc->properties, gab_props, sizeof(gab_props));
+	memcpy(properties, gab_props, sizeof(gab_props));
 
 	/*
 	 * getting channel from iio and copying the battery properties
@@ -294,13 +295,11 @@  static int gab_probe(struct platform_device *pdev)
 			int index2;
 
 			for (index2 = 0; index2 < index; index2++) {
-				if (psy_desc->properties[index2] ==
-				    gab_dyn_props[chan])
+				if (properties[index2] == gab_dyn_props[chan])
 					break;	/* already known */
 			}
 			if (index2 == index)	/* really new */
-				psy_desc->properties[index++] =
-					gab_dyn_props[chan];
+				properties[index++] = gab_dyn_props[chan];
 			any = true;
 		}
 	}
@@ -317,6 +316,7 @@  static int gab_probe(struct platform_device *pdev)
 	 * as come channels may be not be supported by the device.So
 	 * we need to take care of that.
 	 */
+	psy_desc->properties = properties;
 	psy_desc->num_properties = index;
 
 	adc_bat->psy = power_supply_register(&pdev->dev, psy_desc, &psy_cfg);
@@ -358,7 +358,7 @@  static int gab_probe(struct platform_device *pdev)
 			iio_channel_release(adc_bat->channel[chan]);
 	}
 second_mem_fail:
-	kfree(psy_desc->properties);
+	kfree(properties);
 first_mem_fail:
 	return ret;
 }