* [PATCH v5 1/8] dt-bindings: iio: light: ltr501: Sort compatible enum array
2026-08-17 17:08 [PATCH v5 0/8] iio: light: ltr501: Add ltr329 support Esben Haabendal
@ 2026-08-17 17:08 ` Esben Haabendal
2026-08-17 17:08 ` [PATCH v5 2/8] dt-bindings: iio: light: ltr501: Add missing ltr303 compatible Esben Haabendal
` (6 subsequent siblings)
7 siblings, 0 replies; 11+ messages in thread
From: Esben Haabendal @ 2026-08-17 17:08 UTC (permalink / raw)
To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
Rob Herring, Krzysztof Kozlowski, Conor Dooley, Nikita Travkin,
Maslov Dmitry, Kuppuswamy Sathyanarayanan, Thomas Gleixner,
Pan Chuang, Yangtao Li
Cc: Esben Haabendal, linux-iio, devicetree, linux-kernel,
Jonathan Cameron, Krzysztof Kozlowski
Restore alphabetical sorting of the properties.compatible.enum array.
Acked-by: Krzysztof Kozlowski <krzysztof.kozlowski@oss.qualcomm.com>
Acked-by: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@linux.intel.com>
Signed-off-by: Esben Haabendal <esben@geanix.com>
---
Documentation/devicetree/bindings/iio/light/liteon,ltr501.yaml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/Documentation/devicetree/bindings/iio/light/liteon,ltr501.yaml b/Documentation/devicetree/bindings/iio/light/liteon,ltr501.yaml
index c8074f180a79..480523ca3750 100644
--- a/Documentation/devicetree/bindings/iio/light/liteon,ltr501.yaml
+++ b/Documentation/devicetree/bindings/iio/light/liteon,ltr501.yaml
@@ -15,9 +15,9 @@ allOf:
properties:
compatible:
enum:
+ - liteon,ltr301
- liteon,ltr501
- liteon,ltr559
- - liteon,ltr301
reg:
maxItems: 1
--
2.55.0
^ permalink raw reply related [flat|nested] 11+ messages in thread* [PATCH v5 2/8] dt-bindings: iio: light: ltr501: Add missing ltr303 compatible
2026-08-17 17:08 [PATCH v5 0/8] iio: light: ltr501: Add ltr329 support Esben Haabendal
2026-08-17 17:08 ` [PATCH v5 1/8] dt-bindings: iio: light: ltr501: Sort compatible enum array Esben Haabendal
@ 2026-08-17 17:08 ` Esben Haabendal
2026-08-17 17:08 ` [PATCH v5 3/8] dt-bindings: iio: light: ltr501: Add ltr329 compatible Esben Haabendal
` (5 subsequent siblings)
7 siblings, 0 replies; 11+ messages in thread
From: Esben Haabendal @ 2026-08-17 17:08 UTC (permalink / raw)
To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
Rob Herring, Krzysztof Kozlowski, Conor Dooley, Nikita Travkin,
Maslov Dmitry, Kuppuswamy Sathyanarayanan, Thomas Gleixner,
Pan Chuang, Yangtao Li
Cc: Esben Haabendal, linux-iio, devicetree, linux-kernel,
Jonathan Cameron, Krzysztof Kozlowski
When support for ltr303 was back in 2021, the bindings documentation was
not updated accordingly.
Fixes: 7d71d289e1ba ("iio: light: ltr501: Added ltr303 driver support")
Acked-by: Krzysztof Kozlowski <krzysztof.kozlowski@oss.qualcomm.com>
Acked-by: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@linux.intel.com>
Signed-off-by: Esben Haabendal <esben@geanix.com>
---
Documentation/devicetree/bindings/iio/light/liteon,ltr501.yaml | 1 +
1 file changed, 1 insertion(+)
diff --git a/Documentation/devicetree/bindings/iio/light/liteon,ltr501.yaml b/Documentation/devicetree/bindings/iio/light/liteon,ltr501.yaml
index 480523ca3750..6234e2eaec2e 100644
--- a/Documentation/devicetree/bindings/iio/light/liteon,ltr501.yaml
+++ b/Documentation/devicetree/bindings/iio/light/liteon,ltr501.yaml
@@ -16,6 +16,7 @@ properties:
compatible:
enum:
- liteon,ltr301
+ - liteon,ltr303
- liteon,ltr501
- liteon,ltr559
--
2.55.0
^ permalink raw reply related [flat|nested] 11+ messages in thread* [PATCH v5 3/8] dt-bindings: iio: light: ltr501: Add ltr329 compatible
2026-08-17 17:08 [PATCH v5 0/8] iio: light: ltr501: Add ltr329 support Esben Haabendal
2026-08-17 17:08 ` [PATCH v5 1/8] dt-bindings: iio: light: ltr501: Sort compatible enum array Esben Haabendal
2026-08-17 17:08 ` [PATCH v5 2/8] dt-bindings: iio: light: ltr501: Add missing ltr303 compatible Esben Haabendal
@ 2026-08-17 17:08 ` Esben Haabendal
2026-08-17 17:08 ` [PATCH v5 4/8] iio: light: ltr501: Power down chip if request irq fails Esben Haabendal
` (4 subsequent siblings)
7 siblings, 0 replies; 11+ messages in thread
From: Esben Haabendal @ 2026-08-17 17:08 UTC (permalink / raw)
To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
Rob Herring, Krzysztof Kozlowski, Conor Dooley, Nikita Travkin,
Maslov Dmitry, Kuppuswamy Sathyanarayanan, Thomas Gleixner,
Pan Chuang, Yangtao Li
Cc: Esben Haabendal, linux-iio, devicetree, linux-kernel,
Jonathan Cameron, Krzysztof Kozlowski
LTR-329ALS-01 is an ambient light sensor similar to LTR-303ALS-01, but
without interrupt support.
Acked-by: Krzysztof Kozlowski <krzysztof.kozlowski@oss.qualcomm.com>
Acked-by: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@linux.intel.com>
Signed-off-by: Esben Haabendal <esben@geanix.com>
---
.../devicetree/bindings/iio/light/liteon,ltr501.yaml | 17 ++++++++++++++---
1 file changed, 14 insertions(+), 3 deletions(-)
diff --git a/Documentation/devicetree/bindings/iio/light/liteon,ltr501.yaml b/Documentation/devicetree/bindings/iio/light/liteon,ltr501.yaml
index 6234e2eaec2e..73c32b33d886 100644
--- a/Documentation/devicetree/bindings/iio/light/liteon,ltr501.yaml
+++ b/Documentation/devicetree/bindings/iio/light/liteon,ltr501.yaml
@@ -9,14 +9,12 @@ title: LiteON LTR501 I2C Proximity and Light sensor
maintainers:
- Nikita Travkin <nikita@trvn.ru>
-allOf:
- - $ref: ../common.yaml#
-
properties:
compatible:
enum:
- liteon,ltr301
- liteon,ltr303
+ - liteon,ltr329
- liteon,ltr501
- liteon,ltr559
@@ -37,6 +35,19 @@ required:
- compatible
- reg
+allOf:
+ - $ref: ../common.yaml#
+
+ - if:
+ properties:
+ compatible:
+ contains:
+ enum:
+ - liteon,ltr329
+ then:
+ properties:
+ interrupts: false
+
examples:
- |
#include <dt-bindings/interrupt-controller/irq.h>
--
2.55.0
^ permalink raw reply related [flat|nested] 11+ messages in thread* [PATCH v5 4/8] iio: light: ltr501: Power down chip if request irq fails
2026-08-17 17:08 [PATCH v5 0/8] iio: light: ltr501: Add ltr329 support Esben Haabendal
` (2 preceding siblings ...)
2026-08-17 17:08 ` [PATCH v5 3/8] dt-bindings: iio: light: ltr501: Add ltr329 compatible Esben Haabendal
@ 2026-08-17 17:08 ` Esben Haabendal
2026-08-17 17:18 ` sashiko-bot
2026-08-17 17:08 ` [PATCH v5 5/8] iio: light: ltr501: Drop duplicated error message Esben Haabendal
` (3 subsequent siblings)
7 siblings, 1 reply; 11+ messages in thread
From: Esben Haabendal @ 2026-08-17 17:08 UTC (permalink / raw)
To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
Rob Herring, Krzysztof Kozlowski, Conor Dooley, Nikita Travkin,
Maslov Dmitry, Kuppuswamy Sathyanarayanan, Thomas Gleixner,
Pan Chuang, Yangtao Li
Cc: Esben Haabendal, linux-iio, devicetree, linux-kernel,
Jonathan Cameron, stable, Andy Shevchenko
In case devm_request_threaded_irq() failed, we were leaving the chip
powered instead of powering it down again. Power down the chip switching
ALS and PS modes to standby.
Fixes: 7ac702b3144b ("iio: ltr501: Add interrupt support")
Cc: stable@vger.kernel.org
Acked-by: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@linux.intel.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>
Signed-off-by: Esben Haabendal <esben@geanix.com>
---
drivers/iio/light/ltr501.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/iio/light/ltr501.c b/drivers/iio/light/ltr501.c
index 7d045be78c6d..7746d374688f 100644
--- a/drivers/iio/light/ltr501.c
+++ b/drivers/iio/light/ltr501.c
@@ -1540,7 +1540,7 @@ static int ltr501_probe(struct i2c_client *client)
if (ret) {
dev_err(&client->dev, "request irq (%d) failed\n",
client->irq);
- return ret;
+ goto powerdown_on_error;
}
} else {
indio_dev->info = data->chip_info->info_no_irq;
--
2.55.0
^ permalink raw reply related [flat|nested] 11+ messages in thread* Re: [PATCH v5 4/8] iio: light: ltr501: Power down chip if request irq fails
2026-08-17 17:08 ` [PATCH v5 4/8] iio: light: ltr501: Power down chip if request irq fails Esben Haabendal
@ 2026-08-17 17:18 ` sashiko-bot
0 siblings, 0 replies; 11+ messages in thread
From: sashiko-bot @ 2026-08-17 17:18 UTC (permalink / raw)
To: Esben Haabendal; +Cc: conor+dt, robh, devicetree
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] The driver incorrectly uses pointers to local `int` variables for `regmap_bulk_read()` and `regmap_bulk_write()` when accessing 16-bit registers. On big-endian systems, this accesses the most significant bytes, leaving the least significant bytes uninitialized. This results in returning kernel stack memory to userspace (info leak) or writing invalid zeroes to the device.
--
--- Patch [4]: [PATCH v5 4/8] iio: light: ltr501: Power down chip if request irq fails ---
commit b2aeaca1f2b62b80b38b3ac186edef1f0457ea0a
Author: Esben Haabendal <esben@geanix.com>
iio: light: ltr501: Power down chip if request irq fails
In case devm_request_threaded_irq() failed, we were leaving the chip
powered instead of powering it down again. Power down the chip switching
ALS and PS modes to standby.
> diff --git a/drivers/iio/light/ltr501.c b/drivers/iio/light/ltr501.c
> index 7d045be78c6df..7746d374688fa 100644
> --- a/drivers/iio/light/ltr501.c
> +++ b/drivers/iio/light/ltr501.c
> @@ -1540,7 +1540,7 @@ static int ltr501_probe(struct i2c_client *client)
> if (ret) {
> dev_err(&client->dev, "request irq (%d) failed\n",
> client->irq);
> - return ret;
> + goto powerdown_on_error;
> }
> } else {
> indio_dev->info = data->chip_info->info_no_irq;
[Severity: High]
This isn't a bug introduced by this patch, but there are a few pre-existing
endianness issues in this file related to regmap_bulk_read() and
regmap_bulk_write().
In ltr501_trigger_handler():
if (mask & LTR501_STATUS_PS_RDY) {
ret = regmap_bulk_read(data->regmap, LTR501_PS_DATA,
&psdata, 2);
if (ret < 0)
goto done;
scan.channels[j++] = psdata & LTR501_PS_DATA_MASK;
}
Since psdata is an int, regmap_bulk_read() will populate the upper 16 bits of
the integer on big-endian systems, leaving the lower 16 bits uninitialized.
Could this cause the bitwise AND to operate on uninitialized stack memory,
which is then pushed to the IIO buffer?
A similar issue appears in ltr501_read_thresh():
case IIO_EV_DIR_RISING:
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;
Here, 2 bytes are read into the local int variable thresh_data.
Will this cause the function to return uninitialized stack memory to userspace
on big-endian architectures?
And in ltr501_write_thresh():
case IIO_EV_DIR_RISING:
mutex_lock(&data->lock_als);
ret = regmap_bulk_write(data->regmap,
LTR501_ALS_THRESH_UP,
&val, 2);
The val parameter is an int.
Might writing 2 bytes directly from it on a big-endian system send 0x0000
instead of the actual 16-bit threshold values?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260817-liteon-ltr329-v5-0-6f71ab2b0588@geanix.com?part=4
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH v5 5/8] iio: light: ltr501: Drop duplicated error message
2026-08-17 17:08 [PATCH v5 0/8] iio: light: ltr501: Add ltr329 support Esben Haabendal
` (3 preceding siblings ...)
2026-08-17 17:08 ` [PATCH v5 4/8] iio: light: ltr501: Power down chip if request irq fails Esben Haabendal
@ 2026-08-17 17:08 ` Esben Haabendal
2026-08-17 17:08 ` [PATCH v5 6/8] iio: light: ltr501: Add ltr329 driver support Esben Haabendal
` (2 subsequent siblings)
7 siblings, 0 replies; 11+ messages in thread
From: Esben Haabendal @ 2026-08-17 17:08 UTC (permalink / raw)
To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
Rob Herring, Krzysztof Kozlowski, Conor Dooley, Nikita Travkin,
Maslov Dmitry, Kuppuswamy Sathyanarayanan, Thomas Gleixner,
Pan Chuang, Yangtao Li
Cc: Esben Haabendal, linux-iio, devicetree, linux-kernel,
Jonathan Cameron, Andy Shevchenko
The dev_err() message was causing duplicated error messages, as
devm_request_threaded_irq() calls dev_err_probe() on failure.
Acked-by: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@linux.intel.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>
Signed-off-by: Esben Haabendal <esben@geanix.com>
---
drivers/iio/light/ltr501.c | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
diff --git a/drivers/iio/light/ltr501.c b/drivers/iio/light/ltr501.c
index 7746d374688f..b36bd10a0262 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);
+ if (ret)
goto powerdown_on_error;
- }
} else {
indio_dev->info = data->chip_info->info_no_irq;
}
--
2.55.0
^ permalink raw reply related [flat|nested] 11+ messages in thread* [PATCH v5 6/8] iio: light: ltr501: Add ltr329 driver support
2026-08-17 17:08 [PATCH v5 0/8] iio: light: ltr501: Add ltr329 support Esben Haabendal
` (4 preceding siblings ...)
2026-08-17 17:08 ` [PATCH v5 5/8] iio: light: ltr501: Drop duplicated error message Esben Haabendal
@ 2026-08-17 17:08 ` Esben Haabendal
2026-08-17 17:08 ` [PATCH v5 7/8] iio: light: ltr501: Fix sorting order of device arrays Esben Haabendal
2026-08-17 17:08 ` [PATCH v5 8/8] dt-bindings: iio: light: ltr501: Make proximity-near-level conditional Esben Haabendal
7 siblings, 0 replies; 11+ messages in thread
From: Esben Haabendal @ 2026-08-17 17:08 UTC (permalink / raw)
To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
Rob Herring, Krzysztof Kozlowski, Conor Dooley, Nikita Travkin,
Maslov Dmitry, Kuppuswamy Sathyanarayanan, Thomas Gleixner,
Pan Chuang, Yangtao Li
Cc: Esben Haabendal, linux-iio, devicetree, linux-kernel,
Jonathan Cameron
This adds support for the LTR-329ALS-01 chip, which is similar to
LTR-303ALS-01, except for interrupt, which LTR-329ALS-01 chip does not
have.
Reviewed-by: Nuno Sá <nuno.sa@analog.com>
Acked-by: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@linux.intel.com>
Signed-off-by: Esben Haabendal <esben@geanix.com>
---
drivers/iio/light/ltr501.c | 47 ++++++++++++++++++++++++++++++++++++++++------
1 file changed, 41 insertions(+), 6 deletions(-)
diff --git a/drivers/iio/light/ltr501.c b/drivers/iio/light/ltr501.c
index b36bd10a0262..51ab387f24a3 100644
--- a/drivers/iio/light/ltr501.c
+++ b/drivers/iio/light/ltr501.c
@@ -9,6 +9,7 @@
* TODO: IR LED characteristics
*/
+#include <linux/array_size.h>
#include <linux/module.h>
#include <linux/i2c.h>
#include <linux/err.h>
@@ -94,6 +95,7 @@ enum {
ltr559,
ltr301,
ltr303,
+ ltr329,
};
struct ltr501_gain {
@@ -140,6 +142,7 @@ struct ltr501_chip_info {
u8 als_mode_active;
u8 als_gain_mask;
u8 als_gain_shift;
+ bool no_irq_support;
struct iio_chan_spec const *channels;
const int no_channels;
const struct iio_info *info;
@@ -178,6 +181,11 @@ static const struct ltr501_samp_table ltr501_ps_samp_table[] = {
{500000, 2000000}
};
+static bool ltr501_has_irq_support(const struct ltr501_chip_info *info)
+{
+ return !info->no_irq_support;
+}
+
static int ltr501_match_samp_freq(const struct ltr501_samp_table *tab,
int len, int val, int val2)
{
@@ -821,6 +829,9 @@ static int __ltr501_write_raw(struct iio_dev *indio_dev,
if (ret < 0)
return ret;
+ if (!ltr501_has_irq_support(info))
+ return ret;
+
/* update persistence count when changing frequency */
ret = ltr501_write_intr_prst(data, chan->type,
0, data->als_period);
@@ -840,6 +851,9 @@ static int __ltr501_write_raw(struct iio_dev *indio_dev,
if (ret < 0)
return ret;
+ if (!ltr501_has_irq_support(info))
+ return ret;
+
/* update persistence count when changing frequency */
ret = ltr501_write_intr_prst(data, chan->type,
0, data->ps_period);
@@ -1257,6 +1271,18 @@ static const struct ltr501_chip_info ltr501_chip_info_tbl[] = {
.channels = ltr301_channels,
.no_channels = ARRAY_SIZE(ltr301_channels),
},
+ [ltr329] = {
+ .partid = 0x0A,
+ .als_gain = ltr559_als_gain_tbl,
+ .als_gain_tbl_size = ARRAY_SIZE(ltr559_als_gain_tbl),
+ .als_mode_active = BIT(0),
+ .als_gain_mask = BIT(2) | BIT(3) | BIT(4),
+ .als_gain_shift = 2,
+ .no_irq_support = true,
+ .info_no_irq = <r301_info_no_irq,
+ .channels = ltr301_channels,
+ .no_channels = ARRAY_SIZE(ltr301_channels),
+ },
};
static int ltr501_write_contr(struct ltr501_data *data, u8 als_val, u8 ps_val)
@@ -1369,13 +1395,15 @@ static int ltr501_init(struct ltr501_data *data)
data->ps_contr = status | LTR501_CONTR_ACTIVE;
- ret = ltr501_read_intr_prst(data, IIO_INTENSITY, &data->als_period);
- if (ret < 0)
- return ret;
+ if (ltr501_has_irq_support(data->chip_info)) {
+ ret = ltr501_read_intr_prst(data, IIO_INTENSITY, &data->als_period);
+ if (ret < 0)
+ return ret;
- ret = ltr501_read_intr_prst(data, IIO_PROXIMITY, &data->ps_period);
- if (ret < 0)
- return ret;
+ ret = ltr501_read_intr_prst(data, IIO_PROXIMITY, &data->ps_period);
+ if (ret < 0)
+ return ret;
+ }
return ltr501_write_contr(data, data->als_contr, data->ps_contr);
}
@@ -1530,6 +1558,11 @@ static int ltr501_probe(struct i2c_client *client)
if (ret < 0)
return ret;
+ if (!ltr501_has_irq_support(data->chip_info) && client->irq > 0) {
+ client->irq = 0;
+ dev_warn(&client->dev, "chip doesn't support IRQ");
+ }
+
if (client->irq > 0) {
ret = devm_request_threaded_irq(&client->dev, client->irq,
NULL, ltr501_interrupt_handler,
@@ -1601,6 +1634,7 @@ static const struct i2c_device_id ltr501_id[] = {
{ .name = "ltr559", .driver_data = ltr559 },
{ .name = "ltr301", .driver_data = ltr301 },
{ .name = "ltr303", .driver_data = ltr303 },
+ { .name = "ltr329", .driver_data = ltr329 },
{ }
};
MODULE_DEVICE_TABLE(i2c, ltr501_id);
@@ -1610,6 +1644,7 @@ static const struct of_device_id ltr501_of_match[] = {
{ .compatible = "liteon,ltr559", },
{ .compatible = "liteon,ltr301", },
{ .compatible = "liteon,ltr303", },
+ { .compatible = "liteon,ltr329", },
{ }
};
MODULE_DEVICE_TABLE(of, ltr501_of_match);
--
2.55.0
^ permalink raw reply related [flat|nested] 11+ messages in thread* [PATCH v5 7/8] iio: light: ltr501: Fix sorting order of device arrays
2026-08-17 17:08 [PATCH v5 0/8] iio: light: ltr501: Add ltr329 support Esben Haabendal
` (5 preceding siblings ...)
2026-08-17 17:08 ` [PATCH v5 6/8] iio: light: ltr501: Add ltr329 driver support Esben Haabendal
@ 2026-08-17 17:08 ` Esben Haabendal
2026-08-17 17:21 ` sashiko-bot
2026-08-17 17:08 ` [PATCH v5 8/8] dt-bindings: iio: light: ltr501: Make proximity-near-level conditional Esben Haabendal
7 siblings, 1 reply; 11+ messages in thread
From: Esben Haabendal @ 2026-08-17 17:08 UTC (permalink / raw)
To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
Rob Herring, Krzysztof Kozlowski, Conor Dooley, Nikita Travkin,
Maslov Dmitry, Kuppuswamy Sathyanarayanan, Thomas Gleixner,
Pan Chuang, Yangtao Li
Cc: Esben Haabendal, linux-iio, devicetree, linux-kernel,
Jonathan Cameron, Andy Shevchenko
Using alphanumerical sort order for these should help reduce merge
conflicts.
The 0 assignment to the first entry is not needed, as the first entry will
always be 0. The main thing is to keep the values here in sync with the
elements in ltr501_chip_info_tbl[].
Acked-by: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@linux.intel.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>
Signed-off-by: Esben Haabendal <esben@geanix.com>
---
drivers/iio/light/ltr501.c | 68 +++++++++++++++++++++++-----------------------
1 file changed, 34 insertions(+), 34 deletions(-)
diff --git a/drivers/iio/light/ltr501.c b/drivers/iio/light/ltr501.c
index 51ab387f24a3..d9b68da2452b 100644
--- a/drivers/iio/light/ltr501.c
+++ b/drivers/iio/light/ltr501.c
@@ -91,11 +91,11 @@ struct ltr501_samp_table {
#define LTR501_RESERVED_GAIN -1
enum {
- ltr501 = 0,
- ltr559,
ltr301,
ltr303,
ltr329,
+ ltr501,
+ ltr559,
};
struct ltr501_gain {
@@ -1219,34 +1219,6 @@ static const struct iio_info ltr301_info = {
};
static const struct ltr501_chip_info ltr501_chip_info_tbl[] = {
- [ltr501] = {
- .partid = 0x08,
- .als_gain = ltr501_als_gain_tbl,
- .als_gain_tbl_size = ARRAY_SIZE(ltr501_als_gain_tbl),
- .ps_gain = ltr501_ps_gain_tbl,
- .ps_gain_tbl_size = ARRAY_SIZE(ltr501_ps_gain_tbl),
- .als_mode_active = BIT(0) | BIT(1),
- .als_gain_mask = BIT(3),
- .als_gain_shift = 3,
- .info = <r501_info,
- .info_no_irq = <r501_info_no_irq,
- .channels = ltr501_channels,
- .no_channels = ARRAY_SIZE(ltr501_channels),
- },
- [ltr559] = {
- .partid = 0x09,
- .als_gain = ltr559_als_gain_tbl,
- .als_gain_tbl_size = ARRAY_SIZE(ltr559_als_gain_tbl),
- .ps_gain = ltr559_ps_gain_tbl,
- .ps_gain_tbl_size = ARRAY_SIZE(ltr559_ps_gain_tbl),
- .als_mode_active = BIT(0),
- .als_gain_mask = BIT(2) | BIT(3) | BIT(4),
- .als_gain_shift = 2,
- .info = <r501_info,
- .info_no_irq = <r501_info_no_irq,
- .channels = ltr501_channels,
- .no_channels = ARRAY_SIZE(ltr501_channels),
- },
[ltr301] = {
.partid = 0x08,
.als_gain = ltr501_als_gain_tbl,
@@ -1283,6 +1255,34 @@ static const struct ltr501_chip_info ltr501_chip_info_tbl[] = {
.channels = ltr301_channels,
.no_channels = ARRAY_SIZE(ltr301_channels),
},
+ [ltr501] = {
+ .partid = 0x08,
+ .als_gain = ltr501_als_gain_tbl,
+ .als_gain_tbl_size = ARRAY_SIZE(ltr501_als_gain_tbl),
+ .ps_gain = ltr501_ps_gain_tbl,
+ .ps_gain_tbl_size = ARRAY_SIZE(ltr501_ps_gain_tbl),
+ .als_mode_active = BIT(0) | BIT(1),
+ .als_gain_mask = BIT(3),
+ .als_gain_shift = 3,
+ .info = <r501_info,
+ .info_no_irq = <r501_info_no_irq,
+ .channels = ltr501_channels,
+ .no_channels = ARRAY_SIZE(ltr501_channels),
+ },
+ [ltr559] = {
+ .partid = 0x09,
+ .als_gain = ltr559_als_gain_tbl,
+ .als_gain_tbl_size = ARRAY_SIZE(ltr559_als_gain_tbl),
+ .ps_gain = ltr559_ps_gain_tbl,
+ .ps_gain_tbl_size = ARRAY_SIZE(ltr559_ps_gain_tbl),
+ .als_mode_active = BIT(0),
+ .als_gain_mask = BIT(2) | BIT(3) | BIT(4),
+ .als_gain_shift = 2,
+ .info = <r501_info,
+ .info_no_irq = <r501_info_no_irq,
+ .channels = ltr501_channels,
+ .no_channels = ARRAY_SIZE(ltr501_channels),
+ },
};
static int ltr501_write_contr(struct ltr501_data *data, u8 als_val, u8 ps_val)
@@ -1630,21 +1630,21 @@ static const struct acpi_device_id ltr_acpi_match[] = {
MODULE_DEVICE_TABLE(acpi, ltr_acpi_match);
static const struct i2c_device_id ltr501_id[] = {
- { .name = "ltr501", .driver_data = ltr501 },
- { .name = "ltr559", .driver_data = ltr559 },
{ .name = "ltr301", .driver_data = ltr301 },
{ .name = "ltr303", .driver_data = ltr303 },
{ .name = "ltr329", .driver_data = ltr329 },
+ { .name = "ltr501", .driver_data = ltr501 },
+ { .name = "ltr559", .driver_data = ltr559 },
{ }
};
MODULE_DEVICE_TABLE(i2c, ltr501_id);
static const struct of_device_id ltr501_of_match[] = {
- { .compatible = "liteon,ltr501", },
- { .compatible = "liteon,ltr559", },
{ .compatible = "liteon,ltr301", },
{ .compatible = "liteon,ltr303", },
{ .compatible = "liteon,ltr329", },
+ { .compatible = "liteon,ltr501", },
+ { .compatible = "liteon,ltr559", },
{ }
};
MODULE_DEVICE_TABLE(of, ltr501_of_match);
--
2.55.0
^ permalink raw reply related [flat|nested] 11+ messages in thread* Re: [PATCH v5 7/8] iio: light: ltr501: Fix sorting order of device arrays
2026-08-17 17:08 ` [PATCH v5 7/8] iio: light: ltr501: Fix sorting order of device arrays Esben Haabendal
@ 2026-08-17 17:21 ` sashiko-bot
0 siblings, 0 replies; 11+ messages in thread
From: sashiko-bot @ 2026-08-17 17:21 UTC (permalink / raw)
To: Esben Haabendal; +Cc: robh, conor+dt, devicetree
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] regmap_bulk_read and regmap_bulk_write are called with pointers to 32-bit integers, causing uninitialized memory reads and broken writes on big-endian architectures.
--
--- Patch [7]: [PATCH v5 7/8] iio: light: ltr501: Fix sorting order of device arrays ---
commit f69f1a2e0acaf6c0331bd3c3b614102addd48332
Author: Esben Haabendal <esben@geanix.com>
iio: light: ltr501: Fix sorting order of device arrays
This commit reorders the device array initializations in the ltr501 driver
to use alphanumerical sort order. This helps keep the elements in sync
across different tables and reduces merge conflicts.
> diff --git a/drivers/iio/light/ltr501.c b/drivers/iio/light/ltr501.c
> index 51ab387f24a32..d9b68da2452ba 100644
> --- a/drivers/iio/light/ltr501.c
> +++ b/drivers/iio/light/ltr501.c
[ ... ]
[Severity: High]
This is a pre-existing issue, but does ltr501_read_thresh() leak uninitialized
kernel stack memory to userspace on big-endian systems?
drivers/iio/light/ltr501.c:ltr501_read_thresh() {
...
int ret, thresh_data;
switch (chan->type) {
case IIO_INTENSITY:
switch (dir) {
case IIO_EV_DIR_RISING:
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;
...
}
Because regmap_bulk_read() reads only 2 bytes into the 32-bit int thresh_data,
the lower 16 bits remain uninitialized stack garbage on big-endian systems.
Masking with LTR501_ALS_THRESH_MASK then discards the valid device data and
exposes the uninitialized memory to userspace via the IIO sysfs interface.
Similarly, could ltr501_write_thresh() also be writing 0 instead of the target
threshold on big-endian architectures?
drivers/iio/light/ltr501.c:ltr501_write_thresh() {
...
case IIO_EV_DIR_RISING:
mutex_lock(&data->lock_als);
ret = regmap_bulk_write(data->regmap,
LTR501_ALS_THRESH_UP,
&val, 2);
mutex_unlock(&data->lock_als);
return ret;
...
}
Writing 2 bytes from a 32-bit int on big-endian systems writes the top
2 bytes, which are likely 0, rather than the actual threshold value.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260817-liteon-ltr329-v5-0-6f71ab2b0588@geanix.com?part=7
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH v5 8/8] dt-bindings: iio: light: ltr501: Make proximity-near-level conditional
2026-08-17 17:08 [PATCH v5 0/8] iio: light: ltr501: Add ltr329 support Esben Haabendal
` (6 preceding siblings ...)
2026-08-17 17:08 ` [PATCH v5 7/8] iio: light: ltr501: Fix sorting order of device arrays Esben Haabendal
@ 2026-08-17 17:08 ` Esben Haabendal
7 siblings, 0 replies; 11+ messages in thread
From: Esben Haabendal @ 2026-08-17 17:08 UTC (permalink / raw)
To: Jonathan Cameron, David Lechner, Nuno Sá, Andy Shevchenko,
Rob Herring, Krzysztof Kozlowski, Conor Dooley, Nikita Travkin,
Maslov Dmitry, Kuppuswamy Sathyanarayanan, Thomas Gleixner,
Pan Chuang, Yangtao Li
Cc: Esben Haabendal, linux-iio, devicetree, linux-kernel,
Jonathan Cameron
The proxmity-near-level attribute is only supported by ltr501 and ltr559
chips.
Signed-off-by: Esben Haabendal <esben@geanix.com>
---
.../devicetree/bindings/iio/light/liteon,ltr501.yaml | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/Documentation/devicetree/bindings/iio/light/liteon,ltr501.yaml b/Documentation/devicetree/bindings/iio/light/liteon,ltr501.yaml
index 73c32b33d886..20abd7da080d 100644
--- a/Documentation/devicetree/bindings/iio/light/liteon,ltr501.yaml
+++ b/Documentation/devicetree/bindings/iio/light/liteon,ltr501.yaml
@@ -48,6 +48,18 @@ allOf:
properties:
interrupts: false
+ - if:
+ properties:
+ compatible:
+ contains:
+ enum:
+ - liteon,ltr301
+ - liteon,ltr303
+ - liteon,ltr329
+ then:
+ properties:
+ proximity-near-level: false
+
examples:
- |
#include <dt-bindings/interrupt-controller/irq.h>
--
2.55.0
^ permalink raw reply related [flat|nested] 11+ messages in thread