]> www.infradead.org Git - users/willy/xarray.git/commitdiff
power: ip5xxx_power: Fix uninitialized variable read
authorBence Csókás <csokas.bence@prolan.hu>
Sun, 8 Dec 2024 13:15:31 +0000 (14:15 +0100)
committerSebastian Reichel <sebastian.reichel@collabora.com>
Tue, 10 Dec 2024 00:18:44 +0000 (01:18 +0100)
The check for whether a charger supports the requested
battery voltage was incorrectly added to the
`ip5xxx_battery_get_voltage_max()` function, instead of
`set_voltage_max()`. This commit fixes it.

Reported-by: Kees Bakker <kees@ijzerbout.nl>
Closes: https://lore.kernel.org/linux-kernel/b547c228-df70-4137-9e96-175923f62404@ijzerbout.nl/
Fixes: 8584bc5df539 ("power: ip5xxx_power: Allow for more parameters to be configured")
Signed-off-by: Bence Csókás <csokas.bence@prolan.hu>
Link: https://lore.kernel.org/r/20241208131532.1028581-1-csokas.bence@prolan.hu
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
drivers/power/supply/ip5xxx_power.c

index 4bcf0ea0eb5d5ca04be0d73bf5bade8e7edc8795..c448e0ac0dfac2fff6e43d3bcb427189391bc36e 100644 (file)
@@ -367,9 +367,6 @@ static int ip5xxx_battery_get_voltage_max(struct ip5xxx *ip5xxx, int *val)
        if (ret)
                return ret;
 
-       if (*val > ip5xxx->vbat_max)
-               return -EINVAL;
-
        /*
         * It is not clear what this will return if
         * IP5XXX_CHG_CTL4_BAT_TYPE_SEL_EN is not set...
@@ -504,6 +501,9 @@ static int ip5xxx_battery_set_voltage_max(struct ip5xxx *ip5xxx, int val)
        unsigned int rval;
        int ret;
 
+       if (val > ip5xxx->vbat_max)
+               return -EINVAL;
+
        switch (val) {
        case 4200000:
                rval = IP5XXX_BAT_TYPE_4_2V;