Skip to contentSkip to conversation

tools/sched_ext: fix strtoul() misuse in scx_hotplug_seq()

PATCH In review David Carlier 2 participants 2 messages Feb 27 Scheduler - sched_ext

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tools/sched_ext: fix strtoul() misuse in scx_hotplug_seq()

scx_hotplug_seq() uses strtoul() to parse the hotplug sequence number but checks the result with val < 0. Since strtoul() returns an unsigned long, it never produces a negative value, making the validation dead code.

Switch to strtol() so the negative check is meaningful and fix the format specifier from %lu to %ld to match the long type of val.

---
 tools/sched_ext/include/scx/compat.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tools/sched_ext/include/scx/compat.h +2 -2
index 8b4897fc8b99..1518d05d3e21 100644
@@ -137,8 +137,8 @@ static inline long scx_hotplug_seq(void)
 	buf[len] = 0;
 	close(fd);
 
-	val = strtoul(buf, NULL, 10);
-	SCX_BUG_ON(val < 0, "invalid num hotplug events: %lu", val);
+	val = strtol(buf, NULL, 10);
+	SCX_BUG_ON(val < 0, "invalid num hotplug events: %ld", val);
 
 	return val;
 }
Signature · 1 line
2.51.0
reviewer
#1 lore raw

tools/sched_ext/include/scx/compat.h static inline long scx_hotplug_seq(void) · line 141

Quoted 2 lines · David Carlier
tools/sched_ext/include/scx/compat.h +2 -0
+	val = strtol(buf, NULL, 10);
+	SCX_BUG_ON(val < 0, "invalid num hotplug events: %ld", val);

This isn't a proper way to detect conversion errors either, right? Wouldn't it be better to keep strtoul() and test whether endptr reaches \0?

Thanks.

Signature · 1 line
tejun