Re: [PATCH v11 6/7] power: supply: Add driver for ASUS Transformer battery
From: Dmitry Torokhov
Date: Wed Oct 14 2026 - 21:41:46 EST
Hi Svyatoslav,
On Tue, Oct 13, 2026 at 08:35:02PM +0300, Svyatoslav Ryhel wrote:
> +static int asus_ec_battery_get_property(struct power_supply *psy,
> + enum power_supply_property psp,
> + union power_supply_propval *val)
> +{
> + struct asus_ec_battery_data *priv = power_supply_get_drvdata(psy);
> + int ret;
> +
> + switch (psp) {
> + case POWER_SUPPLY_PROP_PRESENT:
> + val->intval = 1;
> + break;
> +
> + default:
> + ret = asus_ec_battery_get_value(priv, psp);
> + if (ret < 0)
> + return ret;
> +
> + val->intval = (s16)ret;
> +
> + switch (psp) {
...
> + case POWER_SUPPLY_PROP_TIME_TO_EMPTY_NOW:
> + case POWER_SUPPLY_PROP_TIME_TO_FULL_NOW:
> + val->intval *= 60;
> + break;
asus_ec_battery_get_value() returns a u16 (via get_unaligned_le16()), and
unconditionally casting it with (s16)ret sign-extends unsigned 16-bit
properties >= 0x8000 into negative values.
In particular, when the battery is not discharging or not charging,
TIME_TO_EMPTY_NOW / TIME_TO_FULL_NOW report 0xffff, which (s16)ret turns
into -1 and then -60 seconds instead of an unsigned value (or -ENODATA).
Should only signed properties (like POWER_SUPPLY_PROP_CURRENT_NOW) be cast
to s16?
Thanks.
--
Dmitry