All of lore.kernel.org
 help / color / mirror / Atom feed
From: Esben Haabendal <esben@geanix.com>
To: <sashiko-bot@kernel.org>
Cc: <sashiko-reviews@lists.linux.dev>,  <robh@kernel.org>,
	<conor+dt@kernel.org>,  <devicetree@vger.kernel.org>
Subject: Re: [PATCH v6 5/9] iio: accel: mma8452: Allow open drain interrupt pin configuration
Date: Tue, 25 Aug 2026 15:26:06 +0200	[thread overview]
Message-ID: <8733w2nxg1.fsf@geanix.com> (raw)
In-Reply-To: <20260825084232.C01211F000E9@smtp.kernel.org> (sashiko-bot@kernel.org's message of "Tue, 25 Aug 2026 08:42:32 +0000")

<sashiko-bot@kernel.org> writes:

> Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider:
>
> Pre-existing issues:
> - [High] Critical device register configurations are lost after a runtime suspend/resume cycle because `mma8452_runtime_resume` fails to restore them.
> - [High] Sysfs read/write callbacks and write_raw paths access the device hardware over I2C without waking it from runtime suspend.
> - [High] The `mma8452_remove()` function accesses unpowered I2C registers and causes unbalanced regulator disables if the device is runtime suspended.
> - [High] `mma8452_runtime_resume` modifies device active state and configuration registers without holding `data->lock`, causing a TOCTOU race with `mma8452_change_config`.
> - [High] Read-modify-write operations on I2C registers in sysfs operations are performed without holding `data->lock`.
> --
>
> --- Patch [5]: [PATCH v6 5/9] iio: accel: mma8452: Allow open drain interrupt pin configuration ---
> commit 0eb3a6b1fa62842d47690cc795da7896eb5b7153
> Author: Esben Haabendal <esben@geanix.com>
> Subject: iio: accel: mma8452: Allow open drain interrupt pin configuration
>
> This commit introduces the ability to configure the interrupt pin of mma8452
> chips in open-drain mode. It reads the "drive-open-drain" property during
> probe and updates the hardware configuration accordingly.
>
>> diff --git a/drivers/iio/accel/mma8452.c b/drivers/iio/accel/mma8452.c
>> index 8eb97e6793d6f..d1e8eb2a4ad3a 100644
>> --- a/drivers/iio/accel/mma8452.c
>> +++ b/drivers/iio/accel/mma8452.c
> [ ... ]
>> @@ -1829,6 +1853,10 @@ static int mma8452_runtime_resume(struct device *dev)
>>
>>  	WRITE_ONCE(data->suspended, false);
>>
>> +	ret = mma8452_set_interrupt_pin_mode(data);
>> +	if (ret)
>> +		goto runtime_resume_failed;
>> +
>>  	ret = mma8452_active(data);
>>  	if (ret < 0)
>>  		goto runtime_resume_failed;
>
> [Severity: High]
> This is a pre-existing issue, but does mma8452_runtime_resume() fail to
> restore critical configurations?
>
> When the device autosuspends, mma8452_runtime_suspend() disables the VDD
> regulator, which cuts power to the chip and loses volatile register state.
> Upon resume, only CTRL_REG1 and CTRL_REG3 are restored.
>
> Are essential configurations set during probe (like DATA_CFG, TRANSIENT_THS,
> CTRL_REG4 for interrupt enables, and CTRL_REG5) lost after the first
> autosuspend?

Yes, I think they are lost. Looks like suspend/resume is not fully
implemented in this driver.

> [Severity: High]
> This is a pre-existing issue, but does mma8452_runtime_resume() introduce a
> race condition by not holding data->lock?
>
> The device state is modified to ACTIVE outside of the mutex lock here. If a
> concurrent sysfs write checks mma8452_is_active() and sees STANDBY, could
> this activation occur just before the I2C write executes?
>
> Would this cause the hardware to silently ignore the write since the device
> was unexpectedly transitioned to ACTIVE mode?

Yes. That sounds like something that could happen. But even more, all
the sysfs attributes does not even try to resume the device if it is
suspended. Which is also your next comment/issue.

So as mentioned above, suspend/resume implementation in this driver
seems very much incomplete.

> [Severity: High]
> This is a pre-existing issue, but do the sysfs read/write callbacks and
> write_raw paths access the device hardware over I2C without waking it from
> runtime suspend?
>
> drivers/iio/accel/mma8452.c:mma8452_write_raw() {
>     ...
> 	if (!iio_device_claim_direct(indio_dev))
> 		return -EBUSY;
>
> 	ret = __mma8452_write_raw(indio_dev, chan, val, val2, mask);
>     ...
> }
>
> Functions like mma8452_write_raw() and mma8452_show_hp_cutoff_avail() do
> direct I2C accesses without wrapping the operation in
> pm_runtime_resume_and_get() and pm_runtime_put().
>
> If the device is autosuspended, will the unpowered chip fail to ACK the
> transfers and return -EREMOTEIO?

Probably will.

> [Severity: High]
> This is a pre-existing issue, but does mma8452_remove() access unpowered I2C
> registers and cause unbalanced regulator disables?
>
> drivers/iio/accel/mma8452.c:mma8452_remove() {
>     ...
> 	mma8452_standby(iio_priv(indio_dev));
>
> 	regulator_disable(data->vddio_reg);
> 	regulator_disable(data->vdd_reg);
>     ...
> }
>
> If the device is runtime suspended, the vdd and vddio regulators are already
> disabled. Since pm_runtime_disable() does not wake the device,
> mma8452_remove() unconditionally calls mma8452_standby() which will time out
> on an unpowered bus.
>
> Will the subsequent unconditional regulator_disable() calls drive the usage
> counts below zero?

Yes and yes.

> [Severity: High]
> This is a pre-existing issue, but are read-modify-write operations on I2C
> registers in sysfs operations performed without holding data->lock?

Yes. But I don't think the data->lock is supposed to be used for this
purpose. It looks like the purpose is to protect the ACTIVE/STANDBY
state handling in mma8452_change_config().

>
> 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;
>     ...
> }
>
> In functions like mma8452_write_event_config(), an I2C read of the
> configuration register happens completely outside data->lock.
>
> If two threads execute this concurrently, could they both read the old
> state, modify different bits, and serialize on mma8452_change_config(),
> causing the second thread to unconditionally overwrite the first thread's
> modifications?

Looks like a bug. I will try to write up a fix for this and all the
other similar race conditions that this driver seems to have quite a few
of.

/Esben

>
> --
> Sashiko AI review · https://sashiko.dev/#/patchset/20260825-mma8452-open-drain-v6-0-9b252804ee80@geanix.com?part=5

  reply	other threads:[~2026-08-25 13:26 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
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 [this message]
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=8733w2nxg1.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.