diff mbox series

power: charger-manager: fix adding of optional properties

Message ID 995cf2c7d41d4895c319b60ea4ea83e858c34cef.1588340276.git.mirq-linux@rere.qmqm.pl (mailing list archive)
State Not Applicable, archived
Headers show
Series power: charger-manager: fix adding of optional properties | expand

Commit Message

Michał Mirosław May 1, 2020, 1:39 p.m. UTC
Use num_properties to index added property.
This will prevent overwriting POWER_SUPPLY_PROP_CHARGE_NOW with
POWER_SUPPLY_PROP_CURRENT_NOW and leaving the latter entry
uninitialized.

For clarity, num_properties is initialized with length of the copied
array instead of relying on previously memcpy'd value.

Fixes: 0a46510addc7 ("power: supply: charger-manager: Prepare for const properties")
Signed-off-by: Michał Mirosław <mirq-linux@rere.qmqm.pl>
---
 drivers/power/supply/charger-manager.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Comments

Sebastian Reichel May 1, 2020, 1:51 p.m. UTC | #1
Hi,

On Fri, May 01, 2020 at 03:39:53PM +0200, Michał Mirosław wrote:
> Use num_properties to index added property.
> This will prevent overwriting POWER_SUPPLY_PROP_CHARGE_NOW with
> POWER_SUPPLY_PROP_CURRENT_NOW and leaving the latter entry
> uninitialized.
> 
> For clarity, num_properties is initialized with length of the copied
> array instead of relying on previously memcpy'd value.
> 
> Fixes: 0a46510addc7 ("power: supply: charger-manager: Prepare for const properties")
> Signed-off-by: Michał Mirosław <mirq-linux@rere.qmqm.pl>
> ---

I folded your fix directly into the charger-manager patch, which did
not yet reach linux-next. If you send the num_properties part as a
separate one, I will merge it.

-- Sebastian

>  drivers/power/supply/charger-manager.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/power/supply/charger-manager.c b/drivers/power/supply/charger-manager.c
> index a71e2ee81423..2ef53dc1f2fb 100644
> --- a/drivers/power/supply/charger-manager.c
> +++ b/drivers/power/supply/charger-manager.c
> @@ -1729,7 +1729,7 @@ static int charger_manager_probe(struct platform_device *pdev)
>  	memcpy(properties, default_charger_props,
>  		sizeof(enum power_supply_property) *
>  		ARRAY_SIZE(default_charger_props));
> -	num_properties = psy_default.num_properties;
> +	num_properties = ARRAY_SIZE(default_charger_props);
>  
>  	/* Find which optional psy-properties are available */
>  	fuel_gauge = power_supply_get_by_name(desc->psy_fuel_gauge);
> @@ -1740,14 +1740,14 @@ static int charger_manager_probe(struct platform_device *pdev)
>  	}
>  	if (!power_supply_get_property(fuel_gauge,
>  					  POWER_SUPPLY_PROP_CHARGE_NOW, &val)) {
> -		properties[cm->charger_psy_desc.num_properties] =
> +		properties[num_properties] =
>  				POWER_SUPPLY_PROP_CHARGE_NOW;
>  		num_properties++;
>  	}
>  	if (!power_supply_get_property(fuel_gauge,
>  					  POWER_SUPPLY_PROP_CURRENT_NOW,
>  					  &val)) {
> -		properties[cm->charger_psy_desc.num_properties] =
> +		properties[num_properties] =
>  				POWER_SUPPLY_PROP_CURRENT_NOW;
>  		num_properties++;
>  	}
> -- 
> 2.20.1
>
Michał Mirosław May 1, 2020, 2:15 p.m. UTC | #2
On Fri, May 01, 2020 at 03:51:09PM +0200, Sebastian Reichel wrote:
> Hi,
> 
> On Fri, May 01, 2020 at 03:39:53PM +0200, Michał Mirosław wrote:
> > Use num_properties to index added property.
> > This will prevent overwriting POWER_SUPPLY_PROP_CHARGE_NOW with
> > POWER_SUPPLY_PROP_CURRENT_NOW and leaving the latter entry
> > uninitialized.
> > 
> > For clarity, num_properties is initialized with length of the copied
> > array instead of relying on previously memcpy'd value.
> > 
> > Fixes: 0a46510addc7 ("power: supply: charger-manager: Prepare for const properties")
> > Signed-off-by: Michał Mirosław <mirq-linux@rere.qmqm.pl>
> > ---
> 
> I folded your fix directly into the charger-manager patch, which did
> not yet reach linux-next. If you send the num_properties part as a
> separate one, I will merge it.

Since your patch already changes the line, maybe you could squash first
hunk below into it?

> >  drivers/power/supply/charger-manager.c | 6 +++---
> >  1 file changed, 3 insertions(+), 3 deletions(-)
> > 
> > diff --git a/drivers/power/supply/charger-manager.c b/drivers/power/supply/charger-manager.c
> > index a71e2ee81423..2ef53dc1f2fb 100644
> > --- a/drivers/power/supply/charger-manager.c
> > +++ b/drivers/power/supply/charger-manager.c
> > @@ -1729,7 +1729,7 @@ static int charger_manager_probe(struct platform_device *pdev)
> >  	memcpy(properties, default_charger_props,
> >  		sizeof(enum power_supply_property) *
> >  		ARRAY_SIZE(default_charger_props));
> > -	num_properties = psy_default.num_properties;
> > +	num_properties = ARRAY_SIZE(default_charger_props);
> >  
> >  	/* Find which optional psy-properties are available */
> >  	fuel_gauge = power_supply_get_by_name(desc->psy_fuel_gauge);
[...]
diff mbox series

Patch

diff --git a/drivers/power/supply/charger-manager.c b/drivers/power/supply/charger-manager.c
index a71e2ee81423..2ef53dc1f2fb 100644
--- a/drivers/power/supply/charger-manager.c
+++ b/drivers/power/supply/charger-manager.c
@@ -1729,7 +1729,7 @@  static int charger_manager_probe(struct platform_device *pdev)
 	memcpy(properties, default_charger_props,
 		sizeof(enum power_supply_property) *
 		ARRAY_SIZE(default_charger_props));
-	num_properties = psy_default.num_properties;
+	num_properties = ARRAY_SIZE(default_charger_props);
 
 	/* Find which optional psy-properties are available */
 	fuel_gauge = power_supply_get_by_name(desc->psy_fuel_gauge);
@@ -1740,14 +1740,14 @@  static int charger_manager_probe(struct platform_device *pdev)
 	}
 	if (!power_supply_get_property(fuel_gauge,
 					  POWER_SUPPLY_PROP_CHARGE_NOW, &val)) {
-		properties[cm->charger_psy_desc.num_properties] =
+		properties[num_properties] =
 				POWER_SUPPLY_PROP_CHARGE_NOW;
 		num_properties++;
 	}
 	if (!power_supply_get_property(fuel_gauge,
 					  POWER_SUPPLY_PROP_CURRENT_NOW,
 					  &val)) {
-		properties[cm->charger_psy_desc.num_properties] =
+		properties[num_properties] =
 				POWER_SUPPLY_PROP_CURRENT_NOW;
 		num_properties++;
 	}