]> www.infradead.org Git - linux.git/commit
power: supply: ingenic: Fix some error handling paths in ingenic_battery_get_property()
authorChristophe JAILLET <christophe.jaillet@wanadoo.fr>
Sun, 23 Jun 2024 05:50:32 +0000 (07:50 +0200)
committerSebastian Reichel <sebastian.reichel@collabora.com>
Wed, 26 Jun 2024 13:16:57 +0000 (15:16 +0200)
commitf8b6c1eb76f73ed721facd58d0cfb08513aad34c
treecf5bb5944435b7ffe7835853411f840fb1fe644d
parentf62b267adcac33c64a26ec55973dad92bc8a8358
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: fb24ccfbe1e0 ("power: supply: add Ingenic JZ47xx battery driver.")
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Acked-by: Artur Rojek <contact@artur-rojek.eu>
Link: https://lore.kernel.org/r/51e49c18574003db1e20c9299061a5ecd1661a3c.1719121781.git.christophe.jaillet@wanadoo.fr
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
drivers/power/supply/ingenic-battery.c