Skip to contentSkip to conversation

sys_leds01: Fix max_brightness range check on 32-bit

PATCH In review Wake Liu via ltp 3 participants 3 messages Nov 13 – Nov 16

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 sys_leds01: Fix max_brightness range check on 32-bit

The kernel stores max_brightness in struct led_classdev as unsigned int and led-class.c exports it with "%u", so any value up to UINT_MAX is valid.

The test checks it against LONG_MAX, which is only 2147483647 on 32-bit userspace. An LED that reports a larger max_brightness, e.g. 4294967295, makes the test fail on 32-bit while the same value passes on 64-bit.

Use TST_SYSFS_ASSERT_RANGEUU() with UINT_MAX as the upper bound. This matches the kernel type on all architectures and follows the tst_sysfs_assert.h guidance to use the unsigned variant for attributes the kernel exports as an unsigned type.

Fixes e996b5a6c2d9 ("testcases: sysfs: sys_leds01")
---
 testcases/kernel/sysfs/class/leds/sys_leds01.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
testcases/kernel/sysfs/class/leds/sys_leds01.c +1 -1
index 68e7f2094..50376d219 100644
@@ -30,7 +30,7 @@ static void check_led(const char *name)
 
 	tst_res(TINFO, "Checking led '%s'", name);
 
-	TST_SYSFS_ASSERT_RANGELL(1, LONG_MAX, PATH_CLASS_LEDS "/%s/max_brightness", name);
+	TST_SYSFS_ASSERT_RANGEUU(1, UINT_MAX, PATH_CLASS_LEDS "/%s/max_brightness", name);
 
 	TST_SYSFS_ASSERT_RANGELF(0, "brightness", "max_brightness",
 				  PATH_CLASS_LEDS "/%s/", name);
Signature · 5 lines
2.56.0.611.g1030f0b940-goog


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#1 lore raw

Hi Wake,

Quoted 1 line · Wake Liu

sys_leds01: Fix max_brightness range check on 32-bit

Verdict - Reviewed

---
Note:

The agent can sometimes produce false positives although often its findings are genuine. If you find issues with the review, please comment this email or ignore the suggestions.

Regards,
LTP AI Reviewer

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp