Commit c45eac53 authored by Joanne Koong's avatar Joanne Koong Committed by Andrii Nakryiko

bpf: Fix bpf_dynptr_slice{_rdwr} to return NULL instead of 0

Change bpf_dynptr_slice and bpf_dynptr_slice_rdwr to return NULL instead
of 0, in accordance with the codebase guidelines.

Fixes: 66e3a13e ("bpf: Add bpf_dynptr_slice and bpf_dynptr_slice_rdwr")
Reported-by: default avatarkernel test robot <lkp@intel.com>
Signed-off-by: default avatarJoanne Koong <joannelkoong@gmail.com>
Signed-off-by: default avatarAndrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20230302053014.1726219-1-joannelkoong@gmail.com
parent b1d462bc
...@@ -2227,11 +2227,11 @@ __bpf_kfunc void *bpf_dynptr_slice(const struct bpf_dynptr_kern *ptr, u32 offset ...@@ -2227,11 +2227,11 @@ __bpf_kfunc void *bpf_dynptr_slice(const struct bpf_dynptr_kern *ptr, u32 offset
int err; int err;
if (!ptr->data) if (!ptr->data)
return 0; return NULL;
err = bpf_dynptr_check_off_len(ptr, offset, len); err = bpf_dynptr_check_off_len(ptr, offset, len);
if (err) if (err)
return 0; return NULL;
type = bpf_dynptr_get_type(ptr); type = bpf_dynptr_get_type(ptr);
...@@ -2252,7 +2252,7 @@ __bpf_kfunc void *bpf_dynptr_slice(const struct bpf_dynptr_kern *ptr, u32 offset ...@@ -2252,7 +2252,7 @@ __bpf_kfunc void *bpf_dynptr_slice(const struct bpf_dynptr_kern *ptr, u32 offset
} }
default: default:
WARN_ONCE(true, "unknown dynptr type %d\n", type); WARN_ONCE(true, "unknown dynptr type %d\n", type);
return 0; return NULL;
} }
} }
...@@ -2300,7 +2300,7 @@ __bpf_kfunc void *bpf_dynptr_slice_rdwr(const struct bpf_dynptr_kern *ptr, u32 o ...@@ -2300,7 +2300,7 @@ __bpf_kfunc void *bpf_dynptr_slice_rdwr(const struct bpf_dynptr_kern *ptr, u32 o
void *buffer, u32 buffer__szk) void *buffer, u32 buffer__szk)
{ {
if (!ptr->data || bpf_dynptr_is_rdonly(ptr)) if (!ptr->data || bpf_dynptr_is_rdonly(ptr))
return 0; return NULL;
/* bpf_dynptr_slice_rdwr is the same logic as bpf_dynptr_slice. /* bpf_dynptr_slice_rdwr is the same logic as bpf_dynptr_slice.
* *
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment