Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Esben Haabendal" <esben@geanix.com>
Cc: devicetree@vger.kernel.org, conor+dt@kernel.org, robh@kernel.org
Subject: Re: [PATCH v6 3/9] iio: accel: mma8452: Only apply trigger type when not set by firmware
Date: Tue, 25 Aug 2026 08:43:23 +0000	[thread overview]
Message-ID: <20260825084323.958231F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260825-mma8452-open-drain-v6-3-9b252804ee80@geanix.com>

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:

New issues:
- [Medium] Hardware-Software Polarity Mismatch

Pre-existing issues:
- [High] PM runtime usage counter leaks permanently on I2C read/write errors.
- [High] Hardware state is accessed over I2C before acquiring runtime PM references, failing if the device is suspended.
--

--- Patch [3]: [PATCH v6 3/9] iio: accel: mma8452: Only apply trigger type when not set by firmware ---
commit b862ff26c69f226387993dc22a2537b8dc72d9fd
Author: Esben Haabendal <esben@geanix.com>

iio: accel: mma8452: Only apply trigger type when not set by firmware

This patch modifies the mma8452 driver to only apply a default active-low
trigger type if the firmware does not specify one. This aims to improve
backward compatibility while respecting firmware configuration.

> diff --git a/drivers/iio/accel/mma8452.c b/drivers/iio/accel/mma8452.c
> index f645a5c6fd1c2..1fb43c5b0b72f 100644
> --- a/drivers/iio/accel/mma8452.c
> +++ b/drivers/iio/accel/mma8452.c

[ ... ]

> @@ -1683,9 +1683,16 @@ static int mma8452_probe(struct i2c_client *client)
>  		goto trigger_cleanup;
>  
>  	if (client->irq) {
> +		unsigned long irq_flags;
> +
> +		irq_flags = irq_get_trigger_type(client->irq);
> +		if (irq_flags == IRQ_TYPE_NONE) {
> +			dev_info(dev, "invalid irq type, setting default active low\n");
> +			irq_flags = IRQF_TRIGGER_LOW;
> +		}
> +		irq_flags |= IRQF_ONESHOT;
>  		ret = request_threaded_irq(client->irq, NULL, mma8452_interrupt,
> -					   IRQF_TRIGGER_LOW | IRQF_ONESHOT,
> -					   client->name, indio_dev);
> +					   irq_flags, client->name, indio_dev);

[Severity: Medium]
Does this configuration leave the hardware and software out of sync?

The code reads the firmware's IRQ trigger type and requests the IRQ with
it, but the actual MMA8452 sensor hardware polarity doesn't appear to be
updated. If the firmware requests an active-high or rising-edge trigger,
the host interrupt controller is configured for active-high, but the sensor
would continue to drive its default active-low signal.

Unless there is an external hardware inverter on the board, could this 
mismatch break interrupts? Should the driver read the requested trigger type
and configure the IPOL bit in CTRL_REG3 to match?

>  		if (ret)
>  			goto buffer_cleanup;
>  	}


While reviewing the I2C handling in this driver, I also noticed a couple of
other issues.

[Severity: High]
This is a pre-existing issue, but I noticed a potential leak of the runtime
PM usage counter when handling I2C errors.

In mma8452_read(), the device is woken up, incrementing the PM counter:

mma8452_read() {
    ...
    ret = mma8452_set_runtime_pm_state(data->client, true);
    ...
    ret = i2c_smbus_read_i2c_block_data(data->client, ...);
    if (ret < 0)
        return ret;
}

If the I2C read fails, the function returns immediately and bypasses the
matching mma8452_set_runtime_pm_state() false call. Could this permanently
prevent the device from re-entering autosuspend?

A similar pattern appears to exist in mma8452_write_event_config() where
an early return on a failed I2C read skips restoring the PM state.


[Severity: High]
This is a pre-existing issue, but could some I2C accesses fail if the
device is currently suspended?

In mma8452_read(), the code checks for data readiness before waking up the
device:

mma8452_read() {
    ...
    ret = mma8452_drdy(data);
    if (ret < 0)
        return ret;

    ret = mma8452_set_runtime_pm_state(data->client, true);
}

Because mma8452_drdy() executes an I2C read against the MMA8452_STATUS
register, it happens before the power regulators are enabled. If the device
has already autosuspended (after 2 seconds of inactivity), will this I2C
read hit powered-off silicon and fail?

A similar direct I2C read without a runtime PM reference seems to happen
in mma8452_read_raw() for IIO_CHAN_INFO_CALIBBIAS.

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

  reply	other threads:[~2026-08-25  8:43 UTC|newest]

Thread overview: 28+ 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-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 [this message]
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-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-26  7:27   ` Andy Shevchenko
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-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-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-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=20260825084323.958231F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=esben@geanix.com \
    --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