Patch "power: supply: ingenic: Fix some error handling paths in ingenic_battery_get_property()" has been added to the 6.10-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    power: supply: ingenic: Fix some error handling paths in ingenic_battery_get_property()

to the 6.10-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     power-supply-ingenic-fix-some-error-handling-paths-i.patch
and it can be found in the queue-6.10 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit 6ed1f1a2010eba25f7ed6c9d50a4eb859b66b39e
Author: Christophe JAILLET <christophe.jaillet@xxxxxxxxxx>
Date:   Sun Jun 23 07:50:32 2024 +0200

    power: supply: ingenic: Fix some error handling paths in ingenic_battery_get_property()
    
    [ Upstream commit f8b6c1eb76f73ed721facd58d0cfb08513aad34c ]
    
    If iio_read_channel_processed() fails, 'val->intval' is not updated, but it
    is still *1000 just after. So, in case of error, the *1000 accumulate and
    'val->intval' becomes erroneous.
    
    So instead of rescaling the value after the fact, use the dedicated scaling
    API. This way the result is updated only when needed. In case of error, the
    previous value is kept, unmodified.
    
    This should also reduce any inaccuracies resulting from the scaling.
    
    Finally, this is also slightly more efficient as it saves a function call
    and a multiplication.
    
    Fixes: fb24ccfbe1e0 ("power: supply: add Ingenic JZ47xx battery driver.")
    Signed-off-by: Christophe JAILLET <christophe.jaillet@xxxxxxxxxx>
    Acked-by: Artur Rojek <contact@xxxxxxxxxxxxxx>
    Link: https://lore.kernel.org/r/51e49c18574003db1e20c9299061a5ecd1661a3c.1719121781.git.christophe.jaillet@xxxxxxxxxx
    Signed-off-by: Sebastian Reichel <sebastian.reichel@xxxxxxxxxxxxx>
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/drivers/power/supply/ingenic-battery.c b/drivers/power/supply/ingenic-battery.c
index 2e7fdfde47ece..0a40f425c2772 100644
--- a/drivers/power/supply/ingenic-battery.c
+++ b/drivers/power/supply/ingenic-battery.c
@@ -31,8 +31,9 @@ static int ingenic_battery_get_property(struct power_supply *psy,
 
 	switch (psp) {
 	case POWER_SUPPLY_PROP_HEALTH:
-		ret = iio_read_channel_processed(bat->channel, &val->intval);
-		val->intval *= 1000;
+		ret = iio_read_channel_processed_scale(bat->channel,
+						       &val->intval,
+						       1000);
 		if (val->intval < info->voltage_min_design_uv)
 			val->intval = POWER_SUPPLY_HEALTH_DEAD;
 		else if (val->intval > info->voltage_max_design_uv)
@@ -41,8 +42,9 @@ static int ingenic_battery_get_property(struct power_supply *psy,
 			val->intval = POWER_SUPPLY_HEALTH_GOOD;
 		return ret;
 	case POWER_SUPPLY_PROP_VOLTAGE_NOW:
-		ret = iio_read_channel_processed(bat->channel, &val->intval);
-		val->intval *= 1000;
+		ret = iio_read_channel_processed_scale(bat->channel,
+						       &val->intval,
+						       1000);
 		return ret;
 	case POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN:
 		val->intval = info->voltage_min_design_uv;




[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux