The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH] tools/sched_ext: use btf_vlen() helper in compat.h
@ 2026-06-30  3:12 luoliang
  2026-06-30  5:13 ` Andrea Righi
  2026-06-30  8:17 ` [PATCH v2] " luoliang
  0 siblings, 2 replies; 6+ messages in thread
From: luoliang @ 2026-06-30  3:12 UTC (permalink / raw)
  To: Tejun Heo
  Cc: David Vernet, Andrea Righi, Changwoo Min, sched-ext, linux-kernel,
	bpf, Liang Luo

From: luoliang <luoliang@kylinos.cn>

__COMPAT_read_enum() and __COMPAT_struct_has_field() open-code the
vlen lookup via the raw BTF_INFO_VLEN(t->info) UAPI macro, whose
result type is __u32 (t->info is __u32 and 0xffff is promoted to
unsigned). Comparing it against the int loop counter triggers
-Wsign-compare in every example scheduler that includes compat.h.

libbpf already exposes btf_vlen() for exactly this purpose; it
returns __u16, the natural width of the vlen field, and the usual
integer promotions turn the 'int < __u16' comparison into a plain
'int < int' so the warning goes away without any cast. This matches
the pattern already used in-kernel (e.g. kernel/bpf/inode.c) and in
tools/bpf/bpftool. Replace the three open-coded lookups with
btf_vlen(t). No functional change.

Signed-off-by: Liang Luo <luoliang@kylinos.cn>
---
 tools/sched_ext/include/scx/compat.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/tools/sched_ext/include/scx/compat.h b/tools/sched_ext/include/scx/compat.h
index 039854c490d5..df5ca1ce20f6 100644
--- a/tools/sched_ext/include/scx/compat.h
+++ b/tools/sched_ext/include/scx/compat.h
@@ -42,7 +42,7 @@ static inline bool __COMPAT_read_enum(const char *type, const char *name, u64 *v
 	if (btf_is_enum(t)) {
 		struct btf_enum *e = btf_enum(t);
 
-		for (i = 0; i < BTF_INFO_VLEN(t->info); i++) {
+		for (i = 0; i < btf_vlen(t); i++) {
 			n = btf__name_by_offset(__COMPAT_vmlinux_btf, e[i].name_off);
 			SCX_BUG_ON(!n, "btf__name_by_offset()");
 			if (!strcmp(n, name)) {
@@ -53,7 +53,7 @@ static inline bool __COMPAT_read_enum(const char *type, const char *name, u64 *v
 	} else if (btf_is_enum64(t)) {
 		struct btf_enum64 *e = btf_enum64(t);
 
-		for (i = 0; i < BTF_INFO_VLEN(t->info); i++) {
+		for (i = 0; i < btf_vlen(t); i++) {
 			n = btf__name_by_offset(__COMPAT_vmlinux_btf, e[i].name_off);
 			SCX_BUG_ON(!n, "btf__name_by_offset()");
 			if (!strcmp(n, name)) {
@@ -97,7 +97,7 @@ static inline bool __COMPAT_struct_has_field(const char *type, const char *field
 
 	m = btf_members(t);
 
-	for (i = 0; i < BTF_INFO_VLEN(t->info); i++) {
+	for (i = 0; i < btf_vlen(t); i++) {
 		n = btf__name_by_offset(__COMPAT_vmlinux_btf, m[i].name_off);
 		SCX_BUG_ON(!n, "btf__name_by_offset()");
 			if (!strcmp(n, field))
-- 
2.43.0


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

end of thread, other threads:[~2026-06-30 14:24 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-30  3:12 [PATCH] tools/sched_ext: use btf_vlen() helper in compat.h luoliang
2026-06-30  5:13 ` Andrea Righi
2026-06-30  8:15   ` luoliang
2026-06-30  8:17 ` [PATCH v2] " luoliang
2026-06-30  8:27   ` Andrea Righi
2026-06-30 14:24   ` Tejun Heo

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