Commit f8b6c1eb authored by Christophe JAILLET's avatar Christophe JAILLET Committed by Sebastian Reichel

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

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: fb24ccfb ("power: supply: add Ingenic JZ47xx battery driver.")
Signed-off-by: default avatarChristophe JAILLET <christophe.jaillet@wanadoo.fr>
Acked-by: default avatarArtur Rojek <contact@artur-rojek.eu>
Link: https://lore.kernel.org/r/51e49c18574003db1e20c9299061a5ecd1661a3c.1719121781.git.christophe.jaillet@wanadoo.frSigned-off-by: default avatarSebastian Reichel <sebastian.reichel@collabora.com>
parent f62b267a
...@@ -31,8 +31,9 @@ static int ingenic_battery_get_property(struct power_supply *psy, ...@@ -31,8 +31,9 @@ static int ingenic_battery_get_property(struct power_supply *psy,
switch (psp) { switch (psp) {
case POWER_SUPPLY_PROP_HEALTH: case POWER_SUPPLY_PROP_HEALTH:
ret = iio_read_channel_processed(bat->channel, &val->intval); ret = iio_read_channel_processed_scale(bat->channel,
val->intval *= 1000; &val->intval,
1000);
if (val->intval < info->voltage_min_design_uv) if (val->intval < info->voltage_min_design_uv)
val->intval = POWER_SUPPLY_HEALTH_DEAD; val->intval = POWER_SUPPLY_HEALTH_DEAD;
else if (val->intval > info->voltage_max_design_uv) else if (val->intval > info->voltage_max_design_uv)
...@@ -41,8 +42,9 @@ static int ingenic_battery_get_property(struct power_supply *psy, ...@@ -41,8 +42,9 @@ static int ingenic_battery_get_property(struct power_supply *psy,
val->intval = POWER_SUPPLY_HEALTH_GOOD; val->intval = POWER_SUPPLY_HEALTH_GOOD;
return ret; return ret;
case POWER_SUPPLY_PROP_VOLTAGE_NOW: case POWER_SUPPLY_PROP_VOLTAGE_NOW:
ret = iio_read_channel_processed(bat->channel, &val->intval); ret = iio_read_channel_processed_scale(bat->channel,
val->intval *= 1000; &val->intval,
1000);
return ret; return ret;
case POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN: case POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN:
val->intval = info->voltage_min_design_uv; val->intval = info->voltage_min_design_uv;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment