summaryrefslogtreecommitdiffstats
path: root/drivers/power
diff options
context:
space:
mode:
authorDimitri Fedrau <dimitri.fedrau@liebherr.com>2024-12-09 11:46:15 +0100
committerSebastian Reichel <sebastian.reichel@collabora.com>2024-12-10 02:51:24 +0100
commitafc6e39e824ad0e44b2af50a97885caec8d213d1 (patch)
treec14e765a18753d6d53bdb5edc667a3b48b29e39e /drivers/power
parentLinux 6.13-rc1 (diff)
downloadlinux-afc6e39e824ad0e44b2af50a97885caec8d213d1.tar.xz
linux-afc6e39e824ad0e44b2af50a97885caec8d213d1.zip
power: supply: gpio-charger: Fix set charge current limits
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: be2919d8355e ("power: supply: gpio-charger: add charge-current-limit feature") Cc: stable@vger.kernel.org Signed-off-by: Dimitri Fedrau <dimitri.fedrau@liebherr.com> Link: https://lore.kernel.org/r/20241209-fix-charge-current-limit-v1-1-760d9b8f2af3@liebherr.com Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
Diffstat (limited to 'drivers/power')
-rw-r--r--drivers/power/supply/gpio-charger.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/drivers/power/supply/gpio-charger.c b/drivers/power/supply/gpio-charger.c
index 68212b39785b..6139f736ecbe 100644
--- a/drivers/power/supply/gpio-charger.c
+++ b/drivers/power/supply/gpio-charger.c
@@ -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++) {