From: sashiko-bot@kernel.org
To: "Javier Carrasco" <javier.carrasco.cruz@gmail.com>
Cc: devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH v5 2/4] iio: light: add support for veml6031x00 ALS series
Date: Fri, 07 Aug 2026 14:19:22 +0000 [thread overview]
Message-ID: <20260807141922.EADFE1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260807-veml6031x00-v5-2-e60876fb3640@gmail.com>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Mixing `devm_pm_runtime_get_noresume()` with a manual `pm_runtime_put_autosuspend()` in `probe` causes a PM usage counter underflow on device unbind or probe failure.
- [High] An unprotected read-modify-write in `veml6031x00_set_power_state()` races with sysfs configuration changes, causing lost user configuration, and a lock inversion prevents a simple fix.
--
--- Patch [2]: [PATCH v5 2/4] iio: light: add support for veml6031x00 ALS series ---
commit 2cb7c39d884f4873be61de5deba3865dbd24f394
Author: Javier Carrasco <javier.carrasco.cruz@gmail.com>
iio: light: add support for veml6031x00 ALS series
These sensors provide two light channels (ALS and IR), I2C communication
and a multiplexed interrupt line to signal data ready and configurable
threshold alarms.
> diff --git a/drivers/iio/light/veml6031x00.c b/drivers/iio/light/veml6031x00.c
> new file mode 100644
> index 0000000000000..30cccda51ca08
> --- /dev/null
> +++ b/drivers/iio/light/veml6031x00.c
[ ... ]
> +static int veml6031x00_set_power_state(struct veml6031x00_data *data, bool on)
> +{
> + u8 conf[2];
> + int ret;
> +
> + ret = regmap_bulk_read(data->regmap, VEML6031X00_REG_CONF0,
> + conf, sizeof(conf));
> + if (ret)
> + return ret;
> +
> + if (on) {
> + conf[0] &= ~VEML6031X00_CONF0_SD;
> + conf[1] &= ~VEML6031X00_CONF1_IR_SD;
> + } else {
> + conf[0] |= VEML6031X00_CONF0_SD;
> + conf[1] |= VEML6031X00_CONF1_IR_SD;
> + }
> +
> + return regmap_bulk_write(data->regmap, VEML6031X00_REG_CONF0,
> + conf, sizeof(conf));
> +}
[Severity: High]
Does this unprotected read-modify-write race with concurrent sysfs configuration
updates?
Because CONF0 and CONF1 are in the volatile ranges, regmap does not protect
them with its cache lock. Concurrent regmap_field_write() calls triggered by
veml6031x00_write_raw() could change the gain or integration time between the
bulk_read and bulk_write here, causing the user configuration to be silently
overwritten and lost.
Additionally, could acquiring the scale_lock here to fix the race cause a
deadlock?
Looking at veml6031x00_single_read(), it holds the scale_lock before acquiring
the PM runtime reference:
veml6031x00_single_read()
guard(mutex)(&data->scale_lock);
...
PM_RUNTIME_ACQUIRE_AUTOSUSPEND(...)
If the autosuspend acquisition triggers veml6031x00_runtime_resume() which
then calls veml6031x00_set_power_state(), attempting to take scale_lock again
would deadlock.
[ ... ]
> +static int veml6031x00_probe(struct i2c_client *i2c)
> +{
[ ... ]
> + ret = devm_pm_runtime_set_active_enabled(&i2c->dev);
> + if (ret)
> + return dev_err_probe(&i2c->dev, ret, "Failed to enable runtime PM\n");
> +
> + ret = devm_pm_runtime_get_noresume(&i2c->dev);
> + if (ret)
> + return dev_err_probe(&i2c->dev, ret, "Failed to get runtime PM\n");
> +
> + ret = veml6031x00_validate_part_id(data);
> + if (ret)
> + return ret;
> +
> + ret = veml6031x00_hw_init(iio);
> + if (ret)
> + return ret;
> +
> + pm_runtime_put_autosuspend(&i2c->dev);
[Severity: High]
Will mixing devm_pm_runtime_get_noresume() with a manual
pm_runtime_put_autosuspend() here cause a PM usage counter underflow?
The devm_pm_runtime_get_noresume() call increments the usage counter and
registers a devres action to decrement it on unbind or probe failure.
However, the manual pm_runtime_put_autosuspend() here drops the counter back
to zero.
When the driver is subsequently unbound, the devres action will execute and
decrement the counter again to -1, which could corrupt the runtime PM state
machine and prevent the device or its parent from suspending.
> +
> + ret = devm_iio_device_register(&i2c->dev, iio);
> + if (ret)
> + return dev_err_probe(&i2c->dev, ret, "Failed to register iio device\n");
> +
> + return 0;
> +}
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260807-veml6031x00-v5-0-e60876fb3640@gmail.com?part=2
next prev parent reply other threads:[~2026-08-07 14:19 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-07 13:51 [PATCH v5 0/4] iio: light: add support for veml6031x00 ALS series Javier Carrasco
2026-08-07 13:51 ` [PATCH v5 1/4] dt-bindings: iio: light: veml6030: add " Javier Carrasco
2026-08-07 14:06 ` sashiko-bot
2026-08-07 14:34 ` Javier Carrasco
2026-08-07 15:33 ` Rob Herring (Arm)
2026-08-07 13:51 ` [PATCH v5 2/4] iio: light: add support for " Javier Carrasco
2026-08-07 14:19 ` sashiko-bot [this message]
2026-08-07 14:53 ` Javier Carrasco
2026-08-07 21:02 ` Uwe Kleine-König
2026-08-07 13:51 ` [PATCH v5 3/4] iio: light: veml6031x00: add support for triggered buffers Javier Carrasco
2026-08-07 14:49 ` sashiko-bot
2026-08-07 20:33 ` Javier Carrasco
2026-08-07 13:51 ` [PATCH v5 4/4] iio: light: veml6031x00: add support for events and trigger Javier Carrasco
2026-08-07 15:08 ` sashiko-bot
2026-08-08 6:35 ` Javier Carrasco
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=20260807141922.EADFE1F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=javier.carrasco.cruz@gmail.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