Skip to content

Commit c45eac5

Browse files
joannekoonganakryiko
authored andcommitted
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: 66e3a13 ("bpf: Add bpf_dynptr_slice and bpf_dynptr_slice_rdwr") Reported-by: kernel test robot <[email protected]> Signed-off-by: Joanne Koong <[email protected]> Signed-off-by: Andrii Nakryiko <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent b1d462b commit c45eac5

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

kernel/bpf/helpers.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2227,11 +2227,11 @@ __bpf_kfunc void *bpf_dynptr_slice(const struct bpf_dynptr_kern *ptr, u32 offset
22272227
int err;
22282228

22292229
if (!ptr->data)
2230-
return 0;
2230+
return NULL;
22312231

22322232
err = bpf_dynptr_check_off_len(ptr, offset, len);
22332233
if (err)
2234-
return 0;
2234+
return NULL;
22352235

22362236
type = bpf_dynptr_get_type(ptr);
22372237

@@ -2252,7 +2252,7 @@ __bpf_kfunc void *bpf_dynptr_slice(const struct bpf_dynptr_kern *ptr, u32 offset
22522252
}
22532253
default:
22542254
WARN_ONCE(true, "unknown dynptr type %d\n", type);
2255-
return 0;
2255+
return NULL;
22562256
}
22572257
}
22582258

@@ -2300,7 +2300,7 @@ __bpf_kfunc void *bpf_dynptr_slice_rdwr(const struct bpf_dynptr_kern *ptr, u32 o
23002300
void *buffer, u32 buffer__szk)
23012301
{
23022302
if (!ptr->data || bpf_dynptr_is_rdonly(ptr))
2303-
return 0;
2303+
return NULL;
23042304

23052305
/* bpf_dynptr_slice_rdwr is the same logic as bpf_dynptr_slice.
23062306
*

0 commit comments

Comments
 (0)