[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20251119224140.8616-35-david.laight.linux@gmail.com>
Date: Wed, 19 Nov 2025 22:41:30 +0000
From: david.laight.linux@...il.com
To: linux-kernel@...r.kernel.org,
bpf@...r.kernel.org
Cc: Alexei Starovoitov <ast@...nel.org>,
Andrii Nakryiko <andrii@...nel.org>,
Daniel Borkmann <daniel@...earbox.net>,
David Laight <david.laight.linux@...il.com>
Subject: [PATCH 34/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/bpf/core.c | 4 ++--
kernel/bpf/log.c | 2 +-
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c
index d595fe512498..4f9808ea51fb 100644
--- a/kernel/bpf/core.c
+++ b/kernel/bpf/core.c
@@ -1081,7 +1081,7 @@ bpf_jit_binary_alloc(unsigned int proglen, u8 **image_ptr,
bpf_fill_ill_insns(hdr, size);
hdr->size = size;
- hole = min_t(unsigned int, size - (proglen + sizeof(*hdr)),
+ hole = min(size - (proglen + sizeof(*hdr)),
PAGE_SIZE - sizeof(*hdr));
start = get_random_u32_below(hole) & ~(alignment - 1);
@@ -1142,7 +1142,7 @@ bpf_jit_binary_pack_alloc(unsigned int proglen, u8 **image_ptr,
bpf_fill_ill_insns(*rw_header, size);
(*rw_header)->size = size;
- hole = min_t(unsigned int, size - (proglen + sizeof(*ro_header)),
+ hole = min(size - (proglen + sizeof(*ro_header)),
BPF_PROG_CHUNK_SIZE - sizeof(*ro_header));
start = get_random_u32_below(hole) & ~(alignment - 1);
diff --git a/kernel/bpf/log.c b/kernel/bpf/log.c
index f50533169cc3..01dc13aaa785 100644
--- a/kernel/bpf/log.c
+++ b/kernel/bpf/log.c
@@ -79,7 +79,7 @@ void bpf_verifier_vlog(struct bpf_verifier_log *log, const char *fmt,
/* check if we have at least something to put into user buf */
new_n = 0;
if (log->end_pos < log->len_total) {
- new_n = min_t(u32, log->len_total - log->end_pos, n);
+ new_n = min(log->len_total - log->end_pos, n);
log->kbuf[new_n - 1] = '\0';
}
--
2.39.5
Powered by blists - more mailing lists