Skip to content

Commit 55fbae0

Browse files
Martin KaFai LauAlexei Starovoitov
authored andcommitted
bpf: Check IS_ERR for the bpf_map_get() return value
This patch fixes a mistake in checking NULL instead of checking IS_ERR for the bpf_map_get() return value. It also fixes the return value in link_update_map() from -EINVAL to PTR_ERR(*_map). Reported-by: [email protected] Fixes: 68b0486 ("bpf: Create links for BPF struct_ops maps.") Fixes: aef56f2 ("bpf: Update the struct_ops of a bpf_link.") Signed-off-by: Martin KaFai Lau <[email protected]> Acked-by: Kui-Feng Lee <[email protected]> Acked-by: Stanislav Fomichev <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexei Starovoitov <[email protected]>
1 parent 226bc6a commit 55fbae0

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

kernel/bpf/bpf_struct_ops.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -871,8 +871,8 @@ int bpf_struct_ops_link_create(union bpf_attr *attr)
871871
int err;
872872

873873
map = bpf_map_get(attr->link_create.map_fd);
874-
if (!map)
875-
return -EINVAL;
874+
if (IS_ERR(map))
875+
return PTR_ERR(map);
876876

877877
st_map = (struct bpf_struct_ops_map *)map;
878878

kernel/bpf/syscall.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4689,12 +4689,12 @@ static int link_update_map(struct bpf_link *link, union bpf_attr *attr)
46894689

46904690
new_map = bpf_map_get(attr->link_update.new_map_fd);
46914691
if (IS_ERR(new_map))
4692-
return -EINVAL;
4692+
return PTR_ERR(new_map);
46934693

46944694
if (attr->link_update.flags & BPF_F_REPLACE) {
46954695
old_map = bpf_map_get(attr->link_update.old_map_fd);
46964696
if (IS_ERR(old_map)) {
4697-
ret = -EINVAL;
4697+
ret = PTR_ERR(old_map);
46984698
goto out_put;
46994699
}
47004700
} else if (attr->link_update.old_map_fd) {

0 commit comments

Comments
 (0)