Linux Input/HID development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Svyatoslav Ryhel" <clamor95@gmail.com>
Cc: linux-input@vger.kernel.org, linux-leds@vger.kernel.org,
	lee@kernel.org, dmitry.torokhov@gmail.com,
	devicetree@vger.kernel.org, conor+dt@kernel.org, robh@kernel.org
Subject: Re: [PATCH v10 6/7] power: supply: Add driver for ASUS Transformer battery
Date: Tue, 21 Jul 2026 10:04:22 +0000	[thread overview]
Message-ID: <20260721100423.3C9ED1F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260721095233.420823-7-clamor95@gmail.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] The bounds check for battery property reading fails to account for the 2-byte read size, allowing the second byte to be read from logically invalid padding data.
- [Medium] Battery data cache is not invalidated on system resume, causing user-space to receive potentially stale battery readings.
--

--- Patch [6]: [PATCH v10 6/7] power: supply: Add driver for ASUS Transformer battery ---
commit 576ecafdda8cdf8e2dbf1964e8a1e9097bcefa55
Author: Michał Mirosław <mirq-linux@rere.qmqm.pl>

power: supply: Add driver for ASUS Transformer battery

This commit adds a new battery driver for Asus Transformer tablets and
mobile docks. It implements one battery cell per EC controller and
supports reading battery status via I2C.

> diff --git a/drivers/power/supply/asus-transformer-ec-battery.c b/drivers/power/supply/asus-transformer-ec-battery.c
> new file mode 100644
> index 0000000000000..4c0c6d4b09e2c
> --- /dev/null
> +++ b/drivers/power/supply/asus-transformer-ec-battery.c

[ ... ]

> +static int asus_ec_battery_get_value(struct asus_ec_battery_data *priv,
> +				     enum power_supply_property psp)
> +{
> +	int ret, offs;
> +
> +	guard(mutex)(&priv->battery_lock);
> +
> +	if (psp >= ARRAY_SIZE(asus_ec_battery_prop_offs))
> +		return -EINVAL;
> +
> +	offs = asus_ec_battery_prop_offs[psp];
> +	if (!offs)
> +		return -EINVAL;
> +
> +	ret = asus_ec_battery_refresh(priv);
> +	if (ret < 0)
> +		return ret;
> +
> +	if (offs >= priv->batt_data[0])
> +		return -ENODATA;
> +
> +	return get_unaligned_le16(priv->batt_data + offs);

[Severity: Medium]
Should the bounds check account for the 2-byte read size?

If the EC returns a length where offs == priv->batt_data[0] - 1, the bounds
check offs >= priv->batt_data[0] will pass. 

Since get_unaligned_le16() reads two bytes, wouldn't it read a byte past the
logical data length and return corrupted data instead of -ENODATA?

> +}

[ ... ]

> +static int __maybe_unused asus_ec_battery_resume(struct device *dev)
> +{
> +	struct asus_ec_battery_data *priv = dev_get_drvdata(dev);
> +
> +	schedule_delayed_work(&priv->poll_work,
> +			      msecs_to_jiffies(ASUSEC_BATTERY_DATA_FRESH_MSEC));
> +
> +	return 0;
> +}

[Severity: Medium]
Should the data cache be explicitly invalidated here?

If priv->batt_data_ts is not reset on resume, and jiffies has not
sufficiently advanced past the expiration timestamp during suspend, could the
driver serve stale battery data to user-space from before the sleep?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260721095233.420823-1-clamor95@gmail.com?part=6

  reply	other threads:[~2026-07-21 10:04 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-21  9:52 [PATCH v10 0/7] mfd: Add support for Asus Transformer embedded controller Svyatoslav Ryhel
2026-07-21  9:52 ` [PATCH v10 1/7] dt-bindings: embedded-controller: document ASUS Transformer EC Svyatoslav Ryhel
2026-07-21  9:59   ` sashiko-bot
2026-07-21  9:52 ` [PATCH v10 2/7] mfd: Add driver for ASUS Transformer embedded controller Svyatoslav Ryhel
2026-07-21 10:01   ` sashiko-bot
2026-07-21  9:52 ` [PATCH v10 3/7] input: serio: Add driver for ASUS Transformer dock keyboard and touchpad Svyatoslav Ryhel
2026-07-21 10:07   ` sashiko-bot
2026-07-21  9:52 ` [PATCH v10 4/7] input: keyboard: Add driver for ASUS Transformer dock multimedia keys Svyatoslav Ryhel
2026-07-21 10:00   ` sashiko-bot
2026-07-21  9:52 ` [PATCH v10 5/7] leds: Add driver for ASUS Transformer LEDs Svyatoslav Ryhel
2026-07-21 10:02   ` sashiko-bot
2026-07-21  9:52 ` [PATCH v10 6/7] power: supply: Add driver for ASUS Transformer battery Svyatoslav Ryhel
2026-07-21 10:04   ` sashiko-bot [this message]
2026-07-21  9:52 ` [PATCH v10 7/7] power: supply: Add charger driver for Asus Transformers Svyatoslav Ryhel
2026-07-21  9:59   ` sashiko-bot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260721100423.3C9ED1F00A3A@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=clamor95@gmail.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=dmitry.torokhov@gmail.com \
    --cc=lee@kernel.org \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-leds@vger.kernel.org \
    --cc=robh@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox