From: David Laight <[email protected]>

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 <[email protected]>
---
 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


Reply via email to