All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/3] leds: lp50xx: Fix component bounds checks and read default-intensity
@ 2026-12-02 13:50 Tobias Johansson
  2026-12-02 13:50 ` [PATCH v2 1/3] leds: lp50xx: Use an unsigned component index Tobias Johansson
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Tobias Johansson @ 2026-12-02 13:50 UTC (permalink / raw)
  To: Lee Jones, Pavel Machek, Jacek Anaszewski, Johan Adolfsson,
	Dan Murphy
  Cc: linux-leds, linux-kernel, Pavel Machek, kernel, Tobias Johansson,
	Sashiko

This series fixes two pre-existing bounds-check issues in the LP50xx
devicetree parsing path and adds support for reading the
default-intensity property for multicolor components.

The first patch makes the component index unsigned so that firmware reg
values with the high bit set cannot bypass the upper-bound check.

The second patch rejects more than three component child nodes, preventing
num_colors from exceeding the allocation used by the brightness and
multicolor sysfs paths even when component reg values are repeated.

The third patch reads the optional default-intensity property for each
component so configured RGB intensities are applied when brightness is
set, without requiring userspace to write multi_intensity first.

---
Changes in v2:
- Merged the two pre-existing bounds-check fixes into this series ahead of
  the default-intensity patch as requested during review.
- Link to v1 (default-intensity): https://lore.kernel.org/r/20261109-b4-leds-lp50xx-default-intensity-v1-1-0a04a3533df6@axis.com
- Link to v1 (bounds-fixes): https://lore.kernel.org/r/20261127-leds-lp50xx-bounds-fixes-v1-0-b9f0399d747e@axis.com

---
Tobias Johansson (3):
      leds: lp50xx: Use an unsigned component index
      leds: lp50xx: Reject excessive component counts
      leds: lp50xx: Read default intensity from devicetree

 drivers/leds/leds-lp50xx.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
---
base-commit: 05b4738b0078f7d6f154f68068a11c8a0635e9df
change-id: 20260914-b4-leds-lp50xx-default-intensity-345d4cc702b4

Best regards,
-- 
Tobias Johansson <tobias.johansson@axis.com>


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v2 1/3] leds: lp50xx: Use an unsigned component index
  2026-12-02 13:50 [PATCH v2 0/3] leds: lp50xx: Fix component bounds checks and read default-intensity Tobias Johansson
@ 2026-12-02 13:50 ` Tobias Johansson
  2026-12-02 13:50 ` [PATCH v2 2/3] leds: lp50xx: Reject excessive component counts Tobias Johansson
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Tobias Johansson @ 2026-12-02 13:50 UTC (permalink / raw)
  To: Lee Jones, Pavel Machek, Jacek Anaszewski, Johan Adolfsson,
	Dan Murphy
  Cc: linux-leds, linux-kernel, Pavel Machek, kernel, Tobias Johansson

The component reg property is read from a firmware node as a u32, but
multi_index is an int. A malformed firmware description with the high
bit set is interpreted as negative and passes the upper-bound check
against LP50XX_LEDS_PER_MODULE. Using such an index then writes out of
bounds at a negative offset from mc_led_info during probe.

Declare multi_index as u32 to match the property reader and ensure that
the existing bounds check rejects all values outside the allocation.
Update the diagnostic format specifier accordingly.

Reported-by: Lee Jones <lee@kernel.org>
Link: https://lore.kernel.org/all/179442102947.44545.9103121805533352120@kernel.org/
Fixes: 2e84a5e53742 ("leds: leds-lp50xx: Handle reg to get correct multi_index")
Signed-off-by: Tobias Johansson <tobias.johansson@axis.com>
---
 drivers/leds/leds-lp50xx.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/leds/leds-lp50xx.c b/drivers/leds/leds-lp50xx.c
index 20bfb315bda1..4d4ad0db96af 100644
--- a/drivers/leds/leds-lp50xx.c
+++ b/drivers/leds/leds-lp50xx.c
@@ -506,7 +506,7 @@ static int lp50xx_probe_dt(struct lp50xx *priv)
 			return -ENOMEM;
 
 		fwnode_for_each_child_node(child, led_node) {
-			int multi_index;
+			u32 multi_index;
 			ret = fwnode_property_read_u32(led_node, "color",
 						       &color_id);
 			if (ret) {
@@ -519,7 +519,7 @@ static int lp50xx_probe_dt(struct lp50xx *priv)
 				dev_err(priv->dev, "reg must be set\n");
 				return -EINVAL;
 			} else if (multi_index >= LP50XX_LEDS_PER_MODULE) {
-				dev_err(priv->dev, "reg %i out of range\n", multi_index);
+				dev_err(priv->dev, "reg %u out of range\n", multi_index);
 				return -EINVAL;
 			}
 

-- 
2.43.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v2 2/3] leds: lp50xx: Reject excessive component counts
  2026-12-02 13:50 [PATCH v2 0/3] leds: lp50xx: Fix component bounds checks and read default-intensity Tobias Johansson
  2026-12-02 13:50 ` [PATCH v2 1/3] leds: lp50xx: Use an unsigned component index Tobias Johansson
@ 2026-12-02 13:50 ` Tobias Johansson
  2026-12-02 13:50 ` [PATCH v2 3/3] leds: lp50xx: Read default intensity from devicetree Tobias Johansson
  2026-12-02 13:59 ` [PATCH v2 0/3] leds: lp50xx: Fix component bounds checks and read default-intensity sashiko-bot
  3 siblings, 0 replies; 5+ messages in thread
From: Tobias Johansson @ 2026-12-02 13:50 UTC (permalink / raw)
  To: Lee Jones, Pavel Machek, Jacek Anaszewski, Johan Adolfsson,
	Dan Murphy
  Cc: linux-leds, linux-kernel, Pavel Machek, kernel, Sashiko,
	Tobias Johansson

Each multicolor LED has storage for LP50XX_LEDS_PER_MODULE components,
but num_colors is incremented for every component child node. More than
three children with repeated valid reg values therefore produce a count
larger than the subled_info allocation.

The brightness and multicolor sysfs paths trust this count, resulting in
out-of-bounds reads and writes.

Reject firmware nodes containing more components than the allocation can
hold before parsing them. This bounds num_colors without changing the
handling of configurations with up to three components.

Reported-by: Sashiko <sashiko-bot@kernel.org>
Link: https://lore.kernel.org/all/sashiko-outbox-204991@kernel.org/
Fixes: 242b81170fb8 ("leds: lp50xx: Add the LP50XX family of the RGB LED driver")
Signed-off-by: Tobias Johansson <tobias.johansson@axis.com>
---
 drivers/leds/leds-lp50xx.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/leds/leds-lp50xx.c b/drivers/leds/leds-lp50xx.c
index 4d4ad0db96af..4da78e6ad0aa 100644
--- a/drivers/leds/leds-lp50xx.c
+++ b/drivers/leds/leds-lp50xx.c
@@ -496,6 +496,11 @@ static int lp50xx_probe_dt(struct lp50xx *priv)
 		init_data.fwnode = child;
 		num_colors = 0;
 
+		if (fwnode_get_child_node_count(child) > LP50XX_LEDS_PER_MODULE) {
+			dev_err(priv->dev, "Too many sub-LEDs\n");
+			return -EINVAL;
+		}
+
 		/*
 		 * There are only 3 LEDs per module otherwise they should be
 		 * banked which also is presented as 3 LEDs.

-- 
2.43.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v2 3/3] leds: lp50xx: Read default intensity from devicetree
  2026-12-02 13:50 [PATCH v2 0/3] leds: lp50xx: Fix component bounds checks and read default-intensity Tobias Johansson
  2026-12-02 13:50 ` [PATCH v2 1/3] leds: lp50xx: Use an unsigned component index Tobias Johansson
  2026-12-02 13:50 ` [PATCH v2 2/3] leds: lp50xx: Reject excessive component counts Tobias Johansson
@ 2026-12-02 13:50 ` Tobias Johansson
  2026-12-02 13:59 ` [PATCH v2 0/3] leds: lp50xx: Fix component bounds checks and read default-intensity sashiko-bot
  3 siblings, 0 replies; 5+ messages in thread
From: Tobias Johansson @ 2026-12-02 13:50 UTC (permalink / raw)
  To: Lee Jones, Pavel Machek, Jacek Anaszewski, Johan Adolfsson,
	Dan Murphy
  Cc: linux-leds, linux-kernel, Pavel Machek, kernel, Tobias Johansson

Read the default-intensity property for each LP50xx multicolor
component so that the configured color intensities are available
when brightness is applied. This allows LEDs to use the intended
RGB values without first writing multi_intensity from userspace.

Leave the intensity at zero when the property is absent.

Signed-off-by: Tobias Johansson <tobias.johansson@axis.com>
---
 drivers/leds/leds-lp50xx.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/leds/leds-lp50xx.c b/drivers/leds/leds-lp50xx.c
index 4da78e6ad0aa..0261127c776b 100644
--- a/drivers/leds/leds-lp50xx.c
+++ b/drivers/leds/leds-lp50xx.c
@@ -527,6 +527,8 @@ static int lp50xx_probe_dt(struct lp50xx *priv)
 				dev_err(priv->dev, "reg %u out of range\n", multi_index);
 				return -EINVAL;
 			}
+			fwnode_property_read_u32(led_node, "default-intensity",
+						 &mc_led_info[multi_index].intensity);
 
 			mc_led_info[multi_index].color_index = color_id;
 			mc_led_info[multi_index].max_intensity = 255;

-- 
2.43.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v2 0/3] leds: lp50xx: Fix component bounds checks and read default-intensity
  2026-12-02 13:50 [PATCH v2 0/3] leds: lp50xx: Fix component bounds checks and read default-intensity Tobias Johansson
                   ` (2 preceding siblings ...)
  2026-12-02 13:50 ` [PATCH v2 3/3] leds: lp50xx: Read default intensity from devicetree Tobias Johansson
@ 2026-12-02 13:59 ` sashiko-bot
  3 siblings, 0 replies; 5+ messages in thread
From: sashiko-bot @ 2026-12-02 13:59 UTC (permalink / raw)
  To: Tobias Johansson; +Cc: linux-leds, lee

Sashiko has reviewed this 3-patch series and found no issues.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261202-b4-leds-lp50xx-default-intensity-v2-0-786f9b0e39e8@axis.com

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-12-02 13:59 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-02 13:50 [PATCH v2 0/3] leds: lp50xx: Fix component bounds checks and read default-intensity Tobias Johansson
2026-12-02 13:50 ` [PATCH v2 1/3] leds: lp50xx: Use an unsigned component index Tobias Johansson
2026-12-02 13:50 ` [PATCH v2 2/3] leds: lp50xx: Reject excessive component counts Tobias Johansson
2026-12-02 13:50 ` [PATCH v2 3/3] leds: lp50xx: Read default intensity from devicetree Tobias Johansson
2026-12-02 13:59 ` [PATCH v2 0/3] leds: lp50xx: Fix component bounds checks and read default-intensity sashiko-bot

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.