[PATCH bpf-next] bpf: Use max() instead of max_t()

Thorsten Blum posted 1 patch 1 year, 7 months ago
kernel/bpf/bpf_local_storage.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH bpf-next] bpf: Use max() instead of max_t()
Posted by Thorsten Blum 1 year, 7 months ago
Use max() instead of max_t(). The types are already compatible and don't
need to be cast to u32 using max_t().

Compile-tested only.

Signed-off-by: Thorsten Blum <thorsten.blum@toblux.com>
---
 kernel/bpf/bpf_local_storage.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/bpf/bpf_local_storage.c b/kernel/bpf/bpf_local_storage.c
index 976cb258a0ed..f0a4f5c06b10 100644
--- a/kernel/bpf/bpf_local_storage.c
+++ b/kernel/bpf/bpf_local_storage.c
@@ -779,7 +779,7 @@ bpf_local_storage_map_alloc(union bpf_attr *attr,
 
 	nbuckets = roundup_pow_of_two(num_possible_cpus());
 	/* Use at least 2 buckets, select_bucket() is undefined behavior with 1 bucket */
-	nbuckets = max_t(u32, 2, nbuckets);
+	nbuckets = max(2, nbuckets);
 	smap->bucket_log = ilog2(nbuckets);
 
 	smap->buckets = bpf_map_kvcalloc(&smap->map, sizeof(*smap->buckets),
-- 
2.45.2
Re: [PATCH bpf-next] bpf: Use max() instead of max_t()
Posted by Alexei Starovoitov 1 year, 7 months ago
On Fri, Jul 5, 2024 at 10:14 PM Thorsten Blum <thorsten.blum@toblux.com> wrote:
>
> Use max() instead of max_t(). The types are already compatible and don't
> need to be cast to u32 using max_t().
>
> Compile-tested only.
>
> Signed-off-by: Thorsten Blum <thorsten.blum@toblux.com>
> ---
>  kernel/bpf/bpf_local_storage.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/kernel/bpf/bpf_local_storage.c b/kernel/bpf/bpf_local_storage.c
> index 976cb258a0ed..f0a4f5c06b10 100644
> --- a/kernel/bpf/bpf_local_storage.c
> +++ b/kernel/bpf/bpf_local_storage.c
> @@ -779,7 +779,7 @@ bpf_local_storage_map_alloc(union bpf_attr *attr,
>
>         nbuckets = roundup_pow_of_two(num_possible_cpus());
>         /* Use at least 2 buckets, select_bucket() is undefined behavior with 1 bucket */
> -       nbuckets = max_t(u32, 2, nbuckets);
> +       nbuckets = max(2, nbuckets);

max_t is cleaner imo and u32 serves as documentation.
pw-bot: cr