Skip to contentSkip to conversation

led: fix coverity scan error

PATCH In review Heiko Schocher 2 participants 2 messages Feb 12, 2025 – Feb 18, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 led: fix coverity scan error

Tom reported the following covervity scan error:

*** CID 541279: (TAINTED_SCALAR)
/drivers/led/led-uclass.c: 284 in led_get_function_name()
278 if (!ret) {
279 snprintf(uc_plat->name, LED_MAX_NAME_SIZE,

280                                      "%s:%s-%d",
281                                      cp ? "" : led_colors[color],
282                                      func ? func : "", enumerator);

283 } else {

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

CID 541279: (TAINTED_SCALAR)
Using tainted variable "color" as an index into an array

"led_colors".

see:
https://lists.denx.de/pipermail/u-boot/2025-February/580250.html

Fix it.

---
Azure build:
https://dev.azure.com/hs0298/hs/_build/results?buildId=170&view=results

 drivers/led/led-uclass.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/led/led-uclass.c +4 -0
index 27ef890ed0a..22f61d12d38 100644
@@ -273,6 +273,10 @@ static const char *led_get_function_name(struct udevice *dev)
 	/* Now try to detect function label name */
 	func = dev_read_string(dev, "function");
 	cp = dev_read_u32(dev, "color", &color);
+	// prevent coverity scan error CID 541279: (TAINTED_SCALAR)
+	if (color < LED_COLOR_ID_WHITE || color >= LED_COLOR_ID_MAX)
+		cp = -EINVAL;
+
 	if (cp == 0 || func) {
 		ret = dev_read_u32(dev, "function-enumerator", &enumerator);
 		if (!ret) {
Signature · 1 line
2.20.1
#1 lore raw
Quoted 9 lines · Heiko Schocher

Tom reported the following covervity scan error:

*** CID 541279: (TAINTED_SCALAR)
/drivers/led/led-uclass.c: 284 in led_get_function_name()
278 if (!ret) {
279 snprintf(uc_plat->name, LED_MAX_NAME_SIZE,

280                                      "%s:%s-%d",
281                                      cp ? "" : led_colors[color],
282                                      func ? func : "", enumerator);
Quoted 6 lines

283 } else {

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

CID 541279: (TAINTED_SCALAR)
Using tainted variable "color" as an index into an array

"led_colors".

[...]

Applied to u-boot/master, thanks!

Signature · 1 line
Tom