Sched_ext development
 help / color / mirror / Atom feed
* [PATCH] tools/sched_ext: fix getopt() option variable signedness
@ 2026-06-26  9:59 luoliang
  2026-06-29 16:43 ` Tejun Heo
  0 siblings, 1 reply; 2+ messages in thread
From: luoliang @ 2026-06-26  9:59 UTC (permalink / raw)
  To: Tejun Heo
  Cc: David Vernet, Andrea Righi, Changwoo Min, sched-ext, linux-kernel,
	Liang Luo

From: Liang Luo <luoliang@kylinos.cn>

Four example schedulers (scx_simple, scx_cpu0, scx_sdt, scx_userland)
declare the variable that holds getopt()'s return value as __u32.
getopt() returns int and uses -1 to mark end-of-options; storing that
sentinel in an unsigned variable turns it into 0xffffffff, and the
subsequent 'opt != -1' test only happens to keep working because both
operands of != are promoted to the same 0xffffffff.

Declare the variable as __s32 instead, matching getopt()'s actual
contract and the style already used in scx_qmap.c (int opt) and
scx_pair/central/flatcg.c (__s32 opt). This also silences the
-Wsign-compare warnings emitted for the affected files.

Signed-off-by: Liang Luo <luoliang@kylinos.cn>
---
 tools/sched_ext/scx_cpu0.c     | 2 +-
 tools/sched_ext/scx_sdt.c      | 2 +-
 tools/sched_ext/scx_simple.c   | 2 +-
 tools/sched_ext/scx_userland.c | 2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/tools/sched_ext/scx_cpu0.c b/tools/sched_ext/scx_cpu0.c
index a6fba9978b9c..af863b7d434a 100644
--- a/tools/sched_ext/scx_cpu0.c
+++ b/tools/sched_ext/scx_cpu0.c
@@ -62,7 +62,7 @@ int main(int argc, char **argv)
 {
 	struct scx_cpu0 *skel;
 	struct bpf_link *link;
-	__u32 opt;
+	__s32 opt;
 	__u64 ecode;

 	libbpf_set_print(libbpf_print_fn);
diff --git a/tools/sched_ext/scx_sdt.c b/tools/sched_ext/scx_sdt.c
index bf664b2d3785..ef197b266a36 100644
--- a/tools/sched_ext/scx_sdt.c
+++ b/tools/sched_ext/scx_sdt.c
@@ -44,7 +44,7 @@ int main(int argc, char **argv)
 {
 	struct scx_sdt *skel;
 	struct bpf_link *link;
-	__u32 opt;
+	__s32 opt;
 	__u64 ecode;

 	libbpf_set_print(libbpf_print_fn);
diff --git a/tools/sched_ext/scx_simple.c b/tools/sched_ext/scx_simple.c
index c3b48611712b..34f9785335b7 100644
--- a/tools/sched_ext/scx_simple.c
+++ b/tools/sched_ext/scx_simple.c
@@ -64,7 +64,7 @@ int main(int argc, char **argv)
 {
 	struct scx_simple *skel;
 	struct bpf_link *link;
-	__u32 opt;
+	__s32 opt;
 	__u64 ecode;

 	libbpf_set_print(libbpf_print_fn);
diff --git a/tools/sched_ext/scx_userland.c b/tools/sched_ext/scx_userland.c
index 616043c165e6..192b79c7e4aa 100644
--- a/tools/sched_ext/scx_userland.c
+++ b/tools/sched_ext/scx_userland.c
@@ -326,7 +326,7 @@ static int spawn_stats_thread(void)
 static void pre_bootstrap(int argc, char **argv)
 {
 	int err;
-	__u32 opt;
+	__s32 opt;
 	struct sched_param sched_param = {
 		.sched_priority = sched_get_priority_max(SCHED_EXT),
 	};
--
2.39.5


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] tools/sched_ext: fix getopt() option variable signedness
  2026-06-26  9:59 [PATCH] tools/sched_ext: fix getopt() option variable signedness luoliang
@ 2026-06-29 16:43 ` Tejun Heo
  0 siblings, 0 replies; 2+ messages in thread
From: Tejun Heo @ 2026-06-29 16:43 UTC (permalink / raw)
  To: Liang Luo
  Cc: David Vernet, Andrea Righi, Changwoo Min, sched-ext, linux-kernel,
	Emil Tsalapatis

On Fri, Jun 26, 2026 at 05:59:28PM +0800, Liang Luo wrote:
> Four example schedulers (scx_simple, scx_cpu0, scx_sdt, scx_userland)
> declare the variable that holds getopt()'s return value as __u32.
> getopt() returns int and uses -1 to mark end-of-options; storing that
> sentinel in an unsigned variable turns it into 0xffffffff, and the
> subsequent 'opt != -1' test only happens to keep working because both
> operands of != are promoted to the same 0xffffffff.
>
> Declare the variable as __s32 instead, matching getopt()'s actual
> contract and the style already used in scx_qmap.c (int opt) and
> scx_pair/central/flatcg.c (__s32 opt). This also silences the
> -Wsign-compare warnings emitted for the affected files.
>
> Signed-off-by: Liang Luo <luoliang@kylinos.cn>

Applied to sched_ext/for-7.3.

Thanks.

--
tejun

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-06-29 16:43 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-26  9:59 [PATCH] tools/sched_ext: fix getopt() option variable signedness luoliang
2026-06-29 16:43 ` Tejun Heo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox