BPF List
 help / color / mirror / Atom feed
* [PATCH bpf-next] libbpf: Close fd in bpf_object__reuse_map
@ 2022-03-17  2:03 Hengqi Chen
  2022-03-18 14:55 ` Daniel Borkmann
  0 siblings, 1 reply; 2+ messages in thread
From: Hengqi Chen @ 2022-03-17  2:03 UTC (permalink / raw)
  To: bpf; +Cc: hengqi.chen

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(+)

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);
 
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH bpf-next] libbpf: Close fd in bpf_object__reuse_map
  2022-03-17  2:03 [PATCH bpf-next] libbpf: Close fd in bpf_object__reuse_map Hengqi Chen
@ 2022-03-18 14:55 ` Daniel Borkmann
  0 siblings, 0 replies; 2+ messages in thread
From: Daniel Borkmann @ 2022-03-18 14:55 UTC (permalink / raw)
  To: Hengqi Chen, bpf; +Cc: toke

[ 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);
>   
> 


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-03-18 14:55 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-03-17  2:03 [PATCH bpf-next] libbpf: Close fd in bpf_object__reuse_map Hengqi Chen
2022-03-18 14:55 ` Daniel Borkmann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox