tools/sched_ext: fix strtoul() misuse in scx_hotplug_seq()
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.
Signed-off-by David Carlier <[email protected]>
--- tools/sched_ext/include/scx/compat.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
tools/sched_ext/include/scx/compat.h +2 -2
@@ -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
Tejun Heo
reviewertools/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