Re: [PATCH v11 6/7] power: supply: Add driver for ASUS Transformer battery
From: Svyatoslav Ryhel
Date: Thu Oct 15 2026 - 03:51:20 EST
чт, 15 жовт. 2026 р. о 04:38 Dmitry Torokhov <dmitry.torokhov@xxxxxxxxx> пише:
>
> 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.
>
You have a point. I assume that using val->intval = ret * 60 should be
acceptable.
> --
> Dmitry