]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
bpf: fix BPF_MAP_LOOKUP_ELEM command return code
authorAlexei Starovoitov <ast@plumgrid.com>
Fri, 14 Nov 2014 01:36:47 +0000 (17:36 -0800)
committerDavid S. Miller <davem@davemloft.net>
Tue, 18 Nov 2014 18:43:59 +0000 (13:43 -0500)
fix errno of BPF_MAP_LOOKUP_ELEM command as bpf manpage
described it in commit b4fc1a460f30("Merge branch 'bpf-next'"):
-----
BPF_MAP_LOOKUP_ELEM
    int bpf_lookup_elem(int fd, void *key, void *value)
    {
        union bpf_attr attr = {
            .map_fd = fd,
            .key = ptr_to_u64(key),
            .value = ptr_to_u64(value),
        };

        return bpf(BPF_MAP_LOOKUP_ELEM, &attr, sizeof(attr));
    }
    bpf() syscall looks up an element with given key in  a  map  fd.
    If  element  is found it returns zero and stores element's value
    into value.  If element is not found  it  returns  -1  and  sets
    errno to ENOENT.

and further down in manpage:

   ENOENT For BPF_MAP_LOOKUP_ELEM or BPF_MAP_DELETE_ELEM,  indicates  that
          element with given key was not found.
-----

In general all BPF commands return ENOENT when map element is not found
(including BPF_MAP_GET_NEXT_KEY and BPF_MAP_UPDATE_ELEM with
 flags == BPF_MAP_UPDATE_ONLY)

Subsequent patch adds a testsuite to check return values for all of
these combinations.

Signed-off-by: Alexei Starovoitov <ast@plumgrid.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
kernel/bpf/syscall.c

index c0d03bf317a2b526560f5aa3aa59f7bbdfeb4c26..088ac0b1b106ff772e9122529866eb5406effd14 100644 (file)
@@ -169,7 +169,7 @@ static int map_lookup_elem(union bpf_attr *attr)
        if (copy_from_user(key, ukey, map->key_size) != 0)
                goto free_key;
 
-       err = -ESRCH;
+       err = -ENOENT;
        rcu_read_lock();
        value = map->ops->map_lookup_elem(map, key);
        if (!value)