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>,  <devicetree@vger.kernel.org>,
	<robh@kernel.org>,  <conor+dt@kernel.org>
Subject: Re: [PATCH v6 6/9] iio: accel: mma8452: Reuse existing dev pointer in mma8452_probe()
Date: Tue, 25 Aug 2026 13:15:06 +0200	[thread overview]
Message-ID: <87bjaqo3id.fsf@geanix.com> (raw)
In-Reply-To: <20260825083802.C3D821F000E9@smtp.kernel.org> (sashiko-bot@kernel.org's message of "Tue, 25 Aug 2026 08:38:02 +0000")

<sashiko-bot@kernel.org> writes:

> Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
>
> New issues:
> - [Low] Undocumented scope modification and suboptimal pointer dereferencing.
>
> Pre-existing issues:
> - [High] Device teardown accesses powered-off hardware and causes unbalanced regulator disables.
> - [Low] Unconditional assignment of PM callbacks causes dead code when PM is disabled.
> --
>
> --- Patch [6]: [PATCH v6 6/9] iio: accel: mma8452: Reuse existing dev pointer in mma8452_probe() ---
> commit 04da87f5e80c506bb658d3dd5161087ce55fa6b0
> Author: Esben Haabendal <esben@geanix.com>
>
> iio: accel: mma8452: Reuse existing dev pointer in mma8452_probe()
>
> This commit refactors mma8452_probe() to use a local 'dev' variable instead
> of repeatedly referencing &client->dev. It aims to improve code readability.
>
>> diff --git a/drivers/iio/accel/mma8452.c b/drivers/iio/accel/mma8452.c
>> index d1e8eb2a4ad3a..7ef1a9a91c31f 100644
>> --- a/drivers/iio/accel/mma8452.c
>> +++ b/drivers/iio/accel/mma8452.c
>
> [ ... ]
>
>> @@ -1801,7 +1799,8 @@ static void mma8452_remove(struct i2c_client *client)
>>  #ifdef CONFIG_PM
>>  static int mma8452_runtime_suspend(struct device *dev)
>>  {
>> -	struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
>> +	struct i2c_client *client = to_i2c_client(dev);
>> +	struct iio_dev *indio_dev = i2c_get_clientdata(client);
>>  	struct mma8452_data *data = iio_priv(indio_dev);
>>  	int ret;
>>
>> @@ -1809,7 +1808,7 @@ static int mma8452_runtime_suspend(struct device *dev)
>>  	ret = mma8452_standby(data);
>>  	mutex_unlock(&data->lock);
>>  	if (ret < 0) {
>> -		dev_err(&data->client->dev, "powering off device failed\n");
>> +		dev_err(&client->dev, "powering off device failed\n");
>
> [Severity: Low]
> The commit message states the changes are restricted to reusing the dev
> pointer in mma8452_probe(), but this modifies mma8452_runtime_suspend().
> Should the commit message be updated to reflect this scope change?
>
> Also, since the function already receives a struct device *dev parameter,
> and &client->dev evaluates to that exact same pointer, wouldn't it be
> simpler to use dev directly here rather than dereferencing client?

Yes. Using the dev pointer directly is the right thing to do.  Added for
next version.

And also, the change that adds the client pointer will be rebased into
patch 4, where the client pointer is used. Sorry about that.

>>  		return -EAGAIN;
>>  	}
>
>
> As a related note, looking at the device teardown path in mma8452_remove():
>
> static void mma8452_remove(struct i2c_client *client)
> {
> [ ... ]
> 	pm_runtime_disable(&client->dev);
> 	pm_runtime_set_suspended(&client->dev);
> [ ... ]
> 	mma8452_standby(iio_priv(indio_dev));
>
> 	regulator_disable(data->vddio_reg);
> 	regulator_disable(data->vdd_reg);
> }
>
> [Severity: High]
> This is a pre-existing issue, but does this teardown sequence access
> potentially powered-off hardware?
>
> If the device is in the RPM_SUSPENDED state when remove() is called, its
> regulators have already been disabled by mma8452_runtime_suspend(). The
> call to mma8452_standby() attempts an I2C write to the powered-off device,
> which might hang the I2C bus or cause transaction timeouts.
>
> Furthermore, unconditionally calling regulator_disable() drops the usage
> counts below zero, triggering a kernel warning for unbalanced disables.
>
> Should pm_runtime_get_sync(&client->dev) be called at the beginning of
> mma8452_remove() to ensure the hardware is active before teardown?
>
>
> Finally, regarding the PM ops assignment in the driver struct:
>
> [Severity: Low]
> This isn't a bug introduced by this patch, but does the unconditional
> assignment of &mma8452_pm_ops to the .pm field in mma8452_driver produce
> dead code when CONFIG_PM is disabled?
>
> According to the power management subsystem guidelines, this pointer should
> be wrapped in pm_ptr(&mma8452_pm_ops) to allow the compiler to eliminate
> the dead code.
>
> --
> Sashiko AI review · https://sashiko.dev/#/patchset/20260825-mma8452-open-drain-v6-0-9b252804ee80@geanix.com?part=6

  reply	other threads:[~2026-08-25 11:15 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
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 [this message]
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=87bjaqo3id.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.