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

David Carlier posted 1 patch 1 month, 2 weeks ago
There is a newer version of this series
tools/sched_ext/include/scx/compat.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
[PATCH] tools/sched_ext: fix strtoul() misuse in scx_hotplug_seq()
Posted by David Carlier 1 month, 2 weeks ago
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 <devnexen@gmail.com>
---
 tools/sched_ext/include/scx/compat.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/sched_ext/include/scx/compat.h b/tools/sched_ext/include/scx/compat.h
index 8b4897fc8b99..1518d05d3e21 100644
--- a/tools/sched_ext/include/scx/compat.h
+++ b/tools/sched_ext/include/scx/compat.h
@@ -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;
 }
-- 
2.51.0
Re: [PATCH] tools/sched_ext: fix strtoul() misuse in scx_hotplug_seq()
Posted by Tejun Heo 1 month, 2 weeks ago
On Fri, Feb 27, 2026 at 06:14:39PM +0000, David Carlier wrote:
> +	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.

-- 
tejun