From: Esben Haabendal <esben@geanix.com>
To: <sashiko-bot@kernel.org>
Cc: <sashiko-reviews@lists.linux.dev>, <conor+dt@kernel.org>,
<devicetree@vger.kernel.org>, <robh@kernel.org>
Subject: Re: [PATCH v6 2/9] iio: accel: mma8452: Optimize struct mma8452_data member orders
Date: Fri, 28 Aug 2026 12:00:12 +0200 [thread overview]
Message-ID: <87h5key383.fsf@geanix.com> (raw)
In-Reply-To: <20260825083858.A5F391F000E9@smtp.kernel.org> (sashiko-bot@kernel.org's message of "Tue, 25 Aug 2026 08:38:58 +0000")
<sashiko-bot@kernel.org> writes:
> Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
>
> Pre-existing issues:
> - [High] Short I2C reads lead to an uninitialized kernel stack memory leak to userspace.
> - [Medium] Runtime PM reference leak on I2C communication failure.
> - [Medium] Unbalanced regulator disable and unpowered I2C access during module removal.
> - [Medium] Data race during read-modify-write of event configuration registers.
> --
>
> --- Patch [2]: [PATCH v6 2/9] iio: accel: mma8452: Optimize struct mma8452_data member orders ---
> commit 26f60bee6a5ce9626d25a99fe80c0216eb010682
> Author: Esben Haabendal <esben@geanix.com>
>
> iio: accel: mma8452: Optimize struct mma8452_data member orders
>
> Reorder struct mma8452_data members to avoid holes.
>
>> diff --git a/drivers/iio/accel/mma8452.c b/drivers/iio/accel/mma8452.c
>> index 7d683686dd9d6..f645a5c6fd1c2 100644
>> --- a/drivers/iio/accel/mma8452.c
>> +++ b/drivers/iio/accel/mma8452.c
>> @@ -106,10 +106,7 @@ struct mma8452_data {
>> struct i2c_client *client;
>> struct mutex lock;
>> struct iio_mount_matrix orientation;
>> - u8 ctrl_reg1;
>> - u8 data_cfg;
>> const struct mma_chip_info *chip_info;
>> - int sleep_val;
>> struct regulator *vdd_reg;
>> struct regulator *vddio_reg;
>>
>> @@ -118,6 +115,10 @@ struct mma8452_data {
>> __be16 channels[3];
>> aligned_s64 ts;
>> } buffer;
>> +
>> + int sleep_val;
>> + u8 ctrl_reg1;
>> + u8 data_cfg;
>> };
>
> [Severity: Medium]
> This is a pre-existing issue, but does this early return leak the runtime PM
> reference count?
>
> drivers/iio/accel/mma8452.c:mma8452_read() {
> ...
> ret = i2c_smbus_read_i2c_block_data(data->client, MMA8452_OUT_X,
> 3 * sizeof(__be16), (u8 *)buf);
> if (ret < 0)
> return ret;
> ...
> }
>
> If i2c_smbus_read_i2c_block_data() fails, the function returns directly,
> skipping the mma8452_set_runtime_pm_state() call.
>
> A similar issue appears in mma8452_data_rdy_trigger_set_state() where a
> failure during i2c_smbus_read_byte_data() skips dropping the autosuspend
> reference if state was true.
Adressed in follow-up patch series.
> [Severity: Medium]
> This isn't a bug introduced by this patch, but during module removal, does
> mma8452_remove() execute operations on an already suspended device?
>
> drivers/iio/accel/mma8452.c:mma8452_remove() {
> ...
> pm_runtime_disable(&client->dev);
> pm_runtime_set_suspended(&client->dev);
>
> if (client->irq)
> free_irq(client->irq, indio_dev);
>
> iio_triggered_buffer_cleanup(indio_dev);
> mma8452_trigger_cleanup(indio_dev);
> mma8452_standby(iio_priv(indio_dev));
>
> regulator_disable(data->vddio_reg);
> regulator_disable(data->vdd_reg);
> ...
> }
>
> If the module is removed while the device is in a runtime-suspended state,
> pm_runtime_disable() does not wake up the device. Subsequent calls to
> mma8452_standby() and regulator_disable() are then executed on an unpowered
> device.
> [Severity: Medium]
> This is a pre-existing issue, but can concurrent sysfs writes cause a data
> race when updating event configuration registers?
>
> drivers/iio/accel/mma8452.c:mma8452_write_event_config() {
> ...
> case IIO_EV_DIR_RISING:
> val = i2c_smbus_read_byte_data(data->client, ev_regs->ev_cfg);
> if (val < 0)
> return val;
> ...
> return mma8452_change_config(data, ev_regs->ev_cfg, val);
> ...
> }
>
> The read-modify-write sequence is performed without acquiring the internal
> driver lock.
>
> If two threads concurrently write to different event attributes in sysfs,
> could the initial read and bitwise modifications race, overwriting each
> other's configuration bits?
Adressed in follow-up patch series.
> [Severity: High]
> This isn't a bug introduced by this patch, but can a short I2C read result
> in uninitialized stack memory being leaked to userspace?
>
> drivers/iio/accel/mma8452.c:mma8452_read() {
> ...
> ret = i2c_smbus_read_i2c_block_data(data->client, MMA8452_OUT_X,
> 3 * sizeof(__be16), (u8 *)buf);
> if (ret < 0)
> return ret;
>
> ret = mma8452_set_runtime_pm_state(data->client, false);
>
> return ret;
> }
>
> If i2c_smbus_read_i2c_block_data() encounters a short read, it returns a
> positive number less than the requested size. The condition ret < 0 is false,
> so the code proceeds and overwrites ret with the return value of
> mma8452_set_runtime_pm_state(), which is 0.
>
> When mma8452_read() returns 0 instead of propagating the short read:
>
> drivers/iio/accel/mma8452.c:mma8452_read_raw() {
> ...
> ret = mma8452_read(data, buffer);
> ...
> *val = sign_extend32(be16_to_cpu(
> buffer[chan->scan_index]) >> chan->scan_type.shift,
> chan->scan_type.realbits - 1);
> ...
> }
>
> Does the caller process and return the uninitialized stack memory from buffer
> via *val?
I will be converting the i2c register access to regmap in the follow-up
patch series I am working on, and the regmap API does not have this
issue, so should resolve this issue also.
> Sashiko AI review · https://sashiko.dev/#/patchset/20260825-mma8452-open-drain-v6-0-9b252804ee80@geanix.com?part=2
/Esben
next prev parent reply other threads:[~2026-08-28 10:00 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-25 8:27 [PATCH v6 0/9] io: accel: mma8452: Allow open drain interrupt pin configuration Esben Haabendal
2026-08-25 8:27 ` [PATCH v6 1/9] dt-bindings: iio: accel: mma8452: Add drive-open-drain Esben Haabendal
2026-08-25 8:27 ` [PATCH v6 2/9] iio: accel: mma8452: Optimize struct mma8452_data member orders Esben Haabendal
2026-08-25 8:38 ` sashiko-bot
2026-08-28 10:00 ` Esben Haabendal [this message]
2026-08-25 8:27 ` [PATCH v6 3/9] iio: accel: mma8452: Only apply trigger type when not set by firmware Esben Haabendal
2026-08-25 8:43 ` sashiko-bot
2026-08-28 9:48 ` Esben Haabendal
2026-08-25 8:27 ` [PATCH v6 4/9] iio: accel: mma8452: Support interrupt sharing Esben Haabendal
2026-08-25 8:42 ` sashiko-bot
2026-08-25 11:39 ` Esben Haabendal
2026-08-25 8:27 ` [PATCH v6 5/9] iio: accel: mma8452: Allow open drain interrupt pin configuration Esben Haabendal
2026-08-25 8:42 ` sashiko-bot
2026-08-25 13:26 ` Esben Haabendal
2026-08-28 9:42 ` Esben Haabendal
2026-08-25 8:27 ` [PATCH v6 6/9] iio: accel: mma8452: Reuse existing dev pointer in mma8452_probe() Esben Haabendal
2026-08-25 8:38 ` sashiko-bot
2026-08-25 11:15 ` Esben Haabendal
2026-08-28 9:40 ` Esben Haabendal
2026-08-26 7:27 ` Andy Shevchenko
2026-08-28 6:20 ` Esben Haabendal
2026-08-25 8:27 ` [PATCH v6 7/9] iio: accel: mma8452: Drop unneeded lock acquire on read Esben Haabendal
2026-08-25 8:45 ` sashiko-bot
2026-08-25 10:17 ` Joshua Crofts
2026-08-25 13:35 ` Esben Haabendal
2026-08-25 13:44 ` Joshua Crofts
2026-08-25 14:06 ` Esben Haabendal
2026-08-28 6:29 ` Esben Haabendal
2026-08-25 8:27 ` [PATCH v6 8/9] iio: accel: mma8452: Fix use-after-free bug in error error path Esben Haabendal
2026-08-25 8:41 ` sashiko-bot
2026-08-28 6:26 ` Esben Haabendal
2026-08-25 8:27 ` [PATCH v6 9/9] iio: accel: mma8452: Use proper error code when missing device model Esben Haabendal
2026-08-25 8:40 ` sashiko-bot
2026-08-28 6:27 ` Esben Haabendal
2026-08-25 10:23 ` Joshua Crofts
2026-08-25 11:00 ` Esben Haabendal
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=87h5key383.fsf@geanix.com \
--to=esben@geanix.com \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=robh@kernel.org \
--cc=sashiko-bot@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;
as well as URLs for NNTP newsgroup(s).