[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20251119224140.8616-36-david.laight.linux@gmail.com>
Date: Wed, 19 Nov 2025 22:41:31 +0000
From: david.laight.linux@...il.com
To: linux-kernel@...r.kernel.org,
bpf@...r.kernel.org,
linux-trace-kernel@...r.kernel.org
Cc: Alexei Starovoitov <ast@...nel.org>,
Andrii Nakryiko <andrii@...nel.org>,
Daniel Borkmann <daniel@...earbox.net>,
KP Singh <kpsingh@...nel.org>,
Masami Hiramatsu <mhiramat@...nel.org>,
Matt Bobrowski <mattbobrowski@...gle.com>,
Song Liu <song@...nel.org>,
Steven Rostedt <rostedt@...dmis.org>,
David Laight <david.laight.linux@...il.com>
Subject: [PATCH 35/44] bpf: use min() instead of min_t()
From: David Laight <david.laight.linux@...il.com>
min_t(unsigned int, a, b) casts an 'unsigned long' to 'unsigned int'.
Use min(a, b) instead as it promotes any 'unsigned int' to 'unsigned long'
and so cannot discard significant bits.
In this case the 'unsigned long' value is small enough that the result
is ok.
Detected by an extra check added to min_t().
Signed-off-by: David Laight <david.laight.linux@...il.com>
---
kernel/trace/bpf_trace.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
index 4f87c16d915a..ee3152df767c 100644
--- a/kernel/trace/bpf_trace.c
+++ b/kernel/trace/bpf_trace.c
@@ -1515,7 +1515,7 @@ BPF_CALL_4(bpf_read_branch_records, struct bpf_perf_event_data_kern *, ctx,
if (!buf || (size % br_entry_size != 0))
return -EINVAL;
- to_copy = min_t(u32, br_stack->nr * br_entry_size, size);
+ to_copy = min(br_stack->nr * br_entry_size, size);
memcpy(buf, br_stack->entries, to_copy);
return to_copy;
--
2.39.5
Powered by blists - more mailing lists