From: sashiko-bot@kernel.org
To: "Esben Haabendal" <esben@geanix.com>
Cc: devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org
Subject: Re: [PATCH v3 4/6] iio: light: ltr501: Power down chip if request irq fails
Date: Tue, 04 Aug 2026 17:36:58 +0000 [thread overview]
Message-ID: <20260804173659.799FC1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260804-liteon-ltr329-v3-4-c6b768c7c745@geanix.com>
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
Pre-existing issues:
- [High] Uninitialized kernel stack memory is leaked to userspace and functional behavior is broken on Big Endian architectures due to `regmap_bulk_read()` reading into a 4-byte `int`.
- [Medium] Data race (TOCTOU) on `data->als_contr` and `data->ps_contr` between raw sysfs reads and writes.
- [Medium] Data race on `data->als_period` and `data->ps_period` between sysfs event writes and sysfs raw writes.
--
--- Patch [4]: [PATCH v3 4/6] iio: light: ltr501: Power down chip if request irq fails ---
commit 9f4c589a7c5ec63bde9127853783856ae3e751dd
Author: Esben Haabendal <esben@geanix.com>
iio: light: ltr501: Power down chip if request irq fails
This patch updates the error handling in ltr501_probe() when
devm_request_threaded_irq() fails. It ensures the chip is powered down by
jumping to the powerdown_on_error label and removes a duplicate error message.
> diff --git a/drivers/iio/light/ltr501.c b/drivers/iio/light/ltr501.c
> index 7d045be78c6df..b36bd10a02624 100644
> --- a/drivers/iio/light/ltr501.c
> +++ b/drivers/iio/light/ltr501.c
> @@ -1537,11 +1537,8 @@ static int ltr501_probe(struct i2c_client *client)
> IRQF_ONESHOT,
> "ltr501_thresh_event",
> indio_dev);
> - if (ret) {
> - dev_err(&client->dev, "request irq (%d) failed\n",
> - client->irq);
> - return ret;
> - }
> + if (ret)
> + goto powerdown_on_error;
> } else {
> indio_dev->info = data->chip_info->info_no_irq;
> }
[Severity: High]
This is a pre-existing issue, but I noticed a potential problem with
uninitialized memory when reading data on Big Endian architectures.
In ltr501_read_thresh():
int ret, thresh_data;
...
ret = regmap_bulk_read(data->regmap, LTR501_ALS_THRESH_UP,
&thresh_data, 2);
if (ret < 0)
return ret;
*val = thresh_data & LTR501_ALS_THRESH_MASK;
And in ltr501_trigger_handler():
int ret, psdata;
...
ret = regmap_bulk_read(data->regmap, LTR501_PS_DATA,
&psdata, 2);
if (ret < 0)
goto done;
scan.channels[j++] = psdata & LTR501_PS_DATA_MASK;
Could this leak up to 2 bytes of uninitialized kernel stack memory to userspace
and result in data loss on Big Endian systems? The regmap_bulk_read() call
reads 2 bytes into the MSB of the 32-bit int variables and then the code masks
the uninitialized LSBs.
Similarly, in ltr501_write_thresh():
ret = regmap_bulk_write(data->regmap, LTR501_ALS_THRESH_UP,
&val, 2);
Would this write the upper 2 bytes of the 32-bit integer on Big Endian systems,
silently passing incorrect zeroes to the hardware?
[Severity: Medium]
This is a pre-existing issue, but is there a data race on data->als_contr
between raw sysfs reads and writes?
In ltr501_read_raw(), data->als_contr is read locklessly:
i = (data->als_contr & data->chip_info->als_gain_mask)
>> data->chip_info->als_gain_shift;
While in __ltr501_write_raw(), it performs a non-atomic read-modify-write:
data->als_contr &= ~info->als_gain_mask;
data->als_contr |= i << info->als_gain_shift;
Can a concurrent read (via sysfs) during a write observe an intermediate
configuration state, leading to the driver temporarily reporting an incorrect
scale factor to userspace?
[Severity: Medium]
This isn't a bug introduced by this patch, but is there a data race on
data->als_period between sysfs event writes and sysfs raw writes?
In ltr501_write_intr_prst():
mutex_unlock(&data->lock_als);
if (ret >= 0)
data->als_period = period;
And in __ltr501_write_raw():
ret = ltr501_write_intr_prst(data, chan->type,
0, data->als_period);
Does updating data->als_period outside of the mutex lock in
ltr501_write_intr_prst() leave it unprotected against concurrent event writers
or lockless readers like __ltr501_write_raw()?
Could this lead to stale or inconsistent values being used to configure the
hardware, potentially setting incorrect sampling frequencies or interrupt
persistence counts?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260804-liteon-ltr329-v3-0-c6b768c7c745@geanix.com?part=4
next prev parent reply other threads:[~2026-08-04 17:37 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-04 17:02 [PATCH v3 0/6] iio: light: ltr501: Add ltr329 support Esben Haabendal
2026-08-04 17:02 ` [PATCH v3 1/6] dt-bindings: iio: light: ltr501: Sort compatible enum array Esben Haabendal
2026-08-05 7:14 ` Krzysztof Kozlowski
2026-08-04 17:02 ` [PATCH v3 2/6] dt-bindings: iio: light: ltr501: Add missing ltr303 compatible Esben Haabendal
2026-08-05 7:14 ` Krzysztof Kozlowski
2026-08-04 17:02 ` [PATCH v3 3/6] dt-bindings: iio: light: ltr501: Add ltr329 compatible Esben Haabendal
2026-08-04 17:16 ` sashiko-bot
2026-08-05 7:15 ` Krzysztof Kozlowski
2026-08-04 17:02 ` [PATCH v3 4/6] iio: light: ltr501: Power down chip if request irq fails Esben Haabendal
2026-08-04 17:36 ` sashiko-bot [this message]
2026-08-04 17:02 ` [PATCH v3 5/6] iio: light: ltr501: Add ltr329 driver support Esben Haabendal
2026-08-04 17:59 ` sashiko-bot
2026-08-04 17:02 ` [PATCH v3 6/6] iio: light: ltr501: Fix sorting order of device arrays Esben Haabendal
2026-08-05 17:15 ` [PATCH v3 0/6] iio: light: ltr501: Add ltr329 support Kuppuswamy Sathyanarayanan
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=20260804173659.799FC1F000E9@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