diff mbox series

[bpf-next] libbpf: Close fd in bpf_object__reuse_map

Message ID 20220317020301.2680432-1-hengqi.chen@gmail.com (mailing list archive)
State Superseded
Delegated to: BPF
Headers show
Series [bpf-next] libbpf: Close fd in bpf_object__reuse_map | expand

Checks

Context Check Description
netdev/tree_selection success Clearly marked for bpf-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix success Link
netdev/cover_letter success Single patches do not need cover letters
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers fail 3 blamed authors not CCed: ast@kernel.org toke@redhat.com andrii@kernel.org; 10 maintainers not CCed: daniel@iogearbox.net ast@kernel.org toke@redhat.com netdev@vger.kernel.org songliubraving@fb.com andrii@kernel.org yhs@fb.com john.fastabend@gmail.com kafai@fb.com kpsingh@kernel.org
netdev/build_clang success Errors and warnings before: 0 this patch: 0
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 7 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
bpf/vmtest-bpf-next success VM_Test
bpf/vmtest-bpf-next-PR fail PR summary

Commit Message

Hengqi Chen March 17, 2022, 2:03 a.m. UTC
pin_fd is dup-ed and assigned in bpf_map__reuse_fd. Close it
after reuse successfully.

Fixes: 57a00f41644f ("libbpf: Add auto-pinning of maps when loading BPF objects")
Signed-off-by: Hengqi Chen <hengqi.chen@gmail.com>
---
 tools/lib/bpf/libbpf.c | 1 +
 1 file changed, 1 insertion(+)

Comments

Daniel Borkmann March 18, 2022, 2:55 p.m. UTC | #1
[ Cc +Toke ]

On 3/17/22 3:03 AM, Hengqi Chen wrote:
> pin_fd is dup-ed and assigned in bpf_map__reuse_fd. Close it
> after reuse successfully.
> 
> Fixes: 57a00f416toke@redhat.com44f ("libbpf: Add auto-pinning of maps when loading BPF objects")
> Signed-off-by: Hengqi Chen <hengqi.chen@gmail.com>
> ---
>   tools/lib/bpf/libbpf.c | 1 +
>   1 file changed, 1 insertion(+)
> 
> diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
> index 43161fdd44bb..10ad500f1d6e 100644
> --- a/tools/lib/bpf/libbpf.c
> +++ b/tools/lib/bpf/libbpf.c
> @@ -4804,6 +4804,7 @@ bpf_object__reuse_map(struct bpf_map *map)
>   		close(pin_fd);
>   		return err;
>   	}
> +	close(pin_fd);

Lgtm, but in that case, pls just do ...

         err = bpf_map__reuse_fd(map, pin_fd);
         close(pin_fd);
         if (err)
                 return err;
         [...]

... given we close it in both branches.

>   	map->pinned = true;
>   	pr_debug("reused pinned map at '%s'\n", map->pin_path);
>   
>
diff mbox series

Patch

diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index 43161fdd44bb..10ad500f1d6e 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -4804,6 +4804,7 @@  bpf_object__reuse_map(struct bpf_map *map)
 		close(pin_fd);
 		return err;
 	}
+	close(pin_fd);
 	map->pinned = true;
 	pr_debug("reused pinned map at '%s'\n", map->pin_path);