From: sashiko-bot@kernel.org
To: "Svyatoslav Ryhel" <clamor95@gmail.com>
Cc: linux-input@vger.kernel.org, conor+dt@kernel.org,
devicetree@vger.kernel.org, dmitry.torokhov@gmail.com,
robh@kernel.org
Subject: Re: [PATCH v8 6/7] power: supply: Add driver for ASUS Transformer battery
Date: Thu, 28 May 2026 08:32:30 +0000 [thread overview]
Message-ID: <20260528083231.41EC31F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260528053203.9339-7-clamor95@gmail.com>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] Short I2C reads return a positive value that bypasses the caller's error check, leading to uninitialized data access and cache bypass.
- [Medium] Off-by-one error in length bounds check allows reading outside the valid EC payload.
--
commit 04954fc98984d98f0039fee1c123ecdf16dc2ff7
Author: Michał Mirosław <mirq-linux@rere.qmqm.pl>
power: supply: Add driver for ASUS Transformer battery
This commit adds a new driver for ASUS Transformer batteries, which implements
one battery cell per EC controller and supports reading battery status for the
pad and mobile dock.
> 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..db6331352f7d4
> --- /dev/null
> +++ b/drivers/power/supply/asus-transformer-ec-battery.c
[ ... ]
> +static int asus_ec_battery_refresh(struct asus_ec_battery_data *priv)
> +{
> + struct i2c_client *client = priv->ec->dockram;
> + struct device *dev = &client->dev;
> + int ret = 0;
> +
> + if (time_before(jiffies, priv->batt_data_ts))
> + return ret;
> +
> + memset(priv->batt_data, 0, ASUSEC_ENTRY_BUFSIZE);
> + ret = i2c_smbus_read_i2c_block_data(client, ASUSEC_DOCKRAM_BATT_CTL,
> + ASUSEC_ENTRY_SIZE, priv->batt_data);
> + if (ret < ASUSEC_ENTRY_SIZE)
> + return ret;
[Severity: Medium]
Since i2c_smbus_read_i2c_block_data() returns the number of bytes read on
success, could this return a positive value on a short read?
If this returns a positive value less than ASUSEC_ENTRY_SIZE, it bypasses
updating the batt_data_ts timestamp, which breaks the 5-second caching
mechanism and triggers an I2C transaction on every subsequent property read.
Additionally, asus_ec_battery_get_value() below only checks for errors with
if (ret < 0), which would fail to catch this positive short read value as
an error, potentially leading to the use of uninitialized data.
[ ... ]
> +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]
Does this bounds check properly account for the 16-bit read?
Since get_unaligned_le16() reads two bytes, if offs exactly equals
priv->batt_data[0] - 1, the bounds check passes. However, the second byte
read (offs + 1) would fall outside the valid payload length.
Could this silently combine one byte of valid data with a zero-padded byte
from the buffer, returning a corrupted value?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260528053203.9339-1-clamor95@gmail.com?part=6
next prev parent reply other threads:[~2026-05-28 8:32 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-28 5:31 [PATCH v8 0/7] mfd: Add support for Asus Transformer embedded controller Svyatoslav Ryhel
2026-05-28 5:31 ` [PATCH v8 1/7] dt-bindings: embedded-controller: document ASUS Transformer EC Svyatoslav Ryhel
2026-05-28 5:44 ` sashiko-bot
2026-05-28 5:31 ` [PATCH v8 2/7] mfd: Add driver for ASUS Transformer embedded controller Svyatoslav Ryhel
2026-05-28 6:16 ` sashiko-bot
2026-05-28 5:31 ` [PATCH v8 3/7] input: serio: Add driver for ASUS Transformer dock keyboard and touchpad Svyatoslav Ryhel
2026-05-28 7:06 ` sashiko-bot
2026-05-28 5:32 ` [PATCH v8 4/7] input: keyboard: Add driver for ASUS Transformer dock multimedia keys Svyatoslav Ryhel
2026-05-28 7:41 ` sashiko-bot
2026-05-28 5:32 ` [PATCH v8 5/7] leds: Add driver for ASUS Transformer LEDs Svyatoslav Ryhel
2026-05-28 5:32 ` [PATCH v8 6/7] power: supply: Add driver for ASUS Transformer battery Svyatoslav Ryhel
2026-05-28 8:32 ` sashiko-bot [this message]
2026-05-28 5:32 ` [PATCH v8 7/7] power: supply: Add charger driver for Asus Transformers Svyatoslav Ryhel
2026-05-28 8:58 ` 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=20260528083231.41EC31F000E9@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=linux-input@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