Skip to content

Commit

Permalink
power: supply: gpio-charger: Fix set charge current limits
Browse files Browse the repository at this point in the history
commit afc6e39e824ad0e44b2af50a97885caec8d213d1 upstream.

Fix set charge current limits for devices which allow to set the lowest
charge current limit to be greater zero. If requested charge current limit
is below lowest limit, the index equals current_limit_map_size which leads
to accessing memory beyond allocated memory.

Fixes: be2919d ("power: supply: gpio-charger: add charge-current-limit feature")
Cc: [email protected]
Signed-off-by: Dimitri Fedrau <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Sebastian Reichel <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
  • Loading branch information
Dimitri Fedrau authored and gregkh committed Jan 2, 2025
1 parent c484dba commit 13eb3ca
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions drivers/power/supply/gpio-charger.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,14 @@ static int set_charge_current_limit(struct gpio_charger *gpio_charger, int val)
if (gpio_charger->current_limit_map[i].limit_ua <= val)
break;
}

/*
* If a valid charge current limit isn't found, default to smallest
* current limitation for safety reasons.
*/
if (i >= gpio_charger->current_limit_map_size)
i = gpio_charger->current_limit_map_size - 1;

mapping = gpio_charger->current_limit_map[i];

for (i = 0; i < ndescs; i++) {
Expand Down

0 comments on commit 13eb3ca

Please sign in to comment.