bpf: Replace fput with sockfd_put in sock map
authorZheng Yongjun <zhengyongjun3@huawei.com>
Tue, 29 Dec 2020 13:48:34 +0000 (21:48 +0800)
committerAlexei Starovoitov <ast@kernel.org>
Fri, 8 Jan 2021 21:39:24 +0000 (13:39 -0800)
The function sockfd_lookup uses fget on the value that is stored in
the file field of the returned structure, so fput should ultimately
be applied to this value. This can be done directly, but it seems
better to use the specific macro sockfd_put, which does the same
thing.

The cleanup was done using the following semantic patch:
    (http://www.emn.fr/x-info/coccinelle/)

    // <smpl>
    @@
    expression s;
    @@

       s = sockfd_lookup(...)
       ...
    +  sockfd_put(s);
    ?- fput(s->file);
    // </smpl>

Signed-off-by: Zheng Yongjun <zhengyongjun3@huawei.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Link: https://lore.kernel.org/bpf/20201229134834.22962-1-zhengyongjun3@huawei.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
net/core/sock_map.c

index 64b5ec14ff50c99393acf344235f7f2c16b364a2..d758fb83c8841d35737c25c6a42f338468b95a6f 100644 (file)
@@ -602,7 +602,7 @@ int sock_map_update_elem_sys(struct bpf_map *map, void *key, void *value,
                ret = sock_hash_update_common(map, key, sk, flags);
        sock_map_sk_release(sk);
 out:
-       fput(sock->file);
+       sockfd_put(sock);
        return ret;
 }