diff options
author | Heiko Schocher <hs@denx.de> | 2025-02-26 10:18:58 +0100 |
---|---|---|
committer | Tom Rini <trini@konsulko.com> | 2025-03-04 12:07:23 -0600 |
commit | 409d37e869e91453d94319792e17d1d882259b49 (patch) | |
tree | db272d11811b098bdb01495ffaa2b3ab633022a6 | |
parent | b6f8da1c2e1a91fbf3059bbd68e3355d76c88b42 (diff) |
led: Fix next Coverity scan error
The following was reported by Coverity scan:
*** CID 542488: Control flow issues (NO_EFFECT)
/drivers/led/led-uclass.c: 277 in led_get_function_name()
271 return uc_plat->label;
272
273 /* Now try to detect function label name */
274 func = dev_read_string(dev, "function");
275 cp = dev_read_u32(dev, "color", &color);
276 // prevent coverity scan error CID 541279: (TAINTED_SCALAR)
>>> CID 542488: Control flow issues (NO_EFFECT)
>>> This less-than-zero comparison of an unsigned value is never true. "color < 0U".
277 if (color < LED_COLOR_ID_WHITE || color >= LED_COLOR_ID_MAX)
278 cp = -EINVAL;
279
Fix it.
Addresses-Coverity-ID: 542488
Link: https://lists.denx.de/pipermail/u-boot/2025-February/581567.html
Signed-off-by: Heiko Schocher <hs@denx.de>
Reviewed-by: Quentin Schulz <quentin.schulz@cherry.de>
-rw-r--r-- | drivers/led/led-uclass.c | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/drivers/led/led-uclass.c b/drivers/led/led-uclass.c index 22f61d12d38..edcdeee1e9a 100644 --- a/drivers/led/led-uclass.c +++ b/drivers/led/led-uclass.c @@ -273,8 +273,12 @@ 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) + /* + * prevent coverity scan error CID 541279: (TAINTED_SCALAR) + * only check the upper bound. No need to check the lower bound + * as color is from type u32 and never can be lower than 0. + */ + if (color >= LED_COLOR_ID_MAX) cp = -EINVAL; if (cp == 0 || func) { |