linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH bpf] tools: bpftool: Add missing close before bpftool net attach exit
@ 2020-11-09  7:04 Wang Hai
  2020-11-09 10:07 ` Quentin Monnet
  2020-11-09 10:51 ` Michal Rostecki
  0 siblings, 2 replies; 5+ messages in thread
From: Wang Hai @ 2020-11-09  7:04 UTC (permalink / raw)
  To: ast, daniel, kafai, songliubraving, yhs, andrii, john.fastabend,
	kpsingh, toke, quentin, danieltimlee
  Cc: bpf, netdev, linux-kernel

progfd is created by prog_parse_fd(), before 'bpftool net attach' exit,
it should be closed.

Fixes: 04949ccc273e ("tools: bpftool: add net attach command to attach XDP on interface")
Signed-off-by: Wang Hai <wanghai38@huawei.com>
---
 tools/bpf/bpftool/net.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/tools/bpf/bpftool/net.c b/tools/bpf/bpftool/net.c
index 910e7bac6e9e..3e9b40e64fb0 100644
--- a/tools/bpf/bpftool/net.c
+++ b/tools/bpf/bpftool/net.c
@@ -600,12 +600,14 @@ static int do_attach(int argc, char **argv)
 	if (err < 0) {
 		p_err("interface %s attach failed: %s",
 		      attach_type_strings[attach_type], strerror(-err));
+		close(progfd);
 		return err;
 	}
 
 	if (json_output)
 		jsonw_null(json_wtr);
 
+	close(progfd);
 	return 0;
 }
 
-- 
2.17.1


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

* Re: [PATCH bpf] tools: bpftool: Add missing close before bpftool net attach exit
  2020-11-09  7:04 [PATCH bpf] tools: bpftool: Add missing close before bpftool net attach exit Wang Hai
@ 2020-11-09 10:07 ` Quentin Monnet
  2020-11-09 10:51 ` Michal Rostecki
  1 sibling, 0 replies; 5+ messages in thread
From: Quentin Monnet @ 2020-11-09 10:07 UTC (permalink / raw)
  To: Wang Hai, ast, daniel, kafai, songliubraving, yhs, andrii,
	john.fastabend, kpsingh, toke, danieltimlee
  Cc: bpf, netdev, linux-kernel

On 09/11/2020 07:04, Wang Hai wrote:
> progfd is created by prog_parse_fd(), before 'bpftool net attach' exit,
> it should be closed.
> 
> Fixes: 04949ccc273e ("tools: bpftool: add net attach command to attach XDP on interface")
> Signed-off-by: Wang Hai <wanghai38@huawei.com>

Reviewed-by: Quentin Monnet <quentin@isovalent.com>

Thanks!
Quentin

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

* Re: [PATCH bpf] tools: bpftool: Add missing close before bpftool net attach exit
  2020-11-09  7:04 [PATCH bpf] tools: bpftool: Add missing close before bpftool net attach exit Wang Hai
  2020-11-09 10:07 ` Quentin Monnet
@ 2020-11-09 10:51 ` Michal Rostecki
  2020-11-09 21:37   ` John Fastabend
  2020-11-10  1:57   ` wanghai (M)
  1 sibling, 2 replies; 5+ messages in thread
From: Michal Rostecki @ 2020-11-09 10:51 UTC (permalink / raw)
  To: Wang Hai, ast, daniel, kafai, songliubraving, yhs, andrii,
	john.fastabend, kpsingh, toke, quentin, danieltimlee
  Cc: bpf, netdev, linux-kernel

On 11/9/20 8:04 AM, Wang Hai wrote:
> progfd is created by prog_parse_fd(), before 'bpftool net attach' exit,
> it should be closed.
> 
> Fixes: 04949ccc273e ("tools: bpftool: add net attach command to attach XDP on interface")
> Signed-off-by: Wang Hai <wanghai38@huawei.com>
> ---
>   tools/bpf/bpftool/net.c | 2 ++
>   1 file changed, 2 insertions(+)
> 
> diff --git a/tools/bpf/bpftool/net.c b/tools/bpf/bpftool/net.c
> index 910e7bac6e9e..3e9b40e64fb0 100644
> --- a/tools/bpf/bpftool/net.c
> +++ b/tools/bpf/bpftool/net.c
> @@ -600,12 +600,14 @@ static int do_attach(int argc, char **argv)
>   	if (err < 0) {
>   		p_err("interface %s attach failed: %s",
>   		      attach_type_strings[attach_type], strerror(-err));
> +		close(progfd);
>   		return err;
>   	}
>   
>   	if (json_output)
>   		jsonw_null(json_wtr);
>   
> +	close(progfd);
>   	return 0;
>   }
>   

Nit - wouldn't it be better to create a `cleanup`/`out` section before 
return and use goto, to avoid copying the `close` call?

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

* Re: [PATCH bpf] tools: bpftool: Add missing close before bpftool net attach exit
  2020-11-09 10:51 ` Michal Rostecki
@ 2020-11-09 21:37   ` John Fastabend
  2020-11-10  1:57   ` wanghai (M)
  1 sibling, 0 replies; 5+ messages in thread
From: John Fastabend @ 2020-11-09 21:37 UTC (permalink / raw)
  To: Michal Rostecki, Wang Hai, ast, daniel, kafai, songliubraving,
	yhs, andrii, john.fastabend, kpsingh, toke, quentin,
	danieltimlee
  Cc: bpf, netdev, linux-kernel

Michal Rostecki wrote:
> On 11/9/20 8:04 AM, Wang Hai wrote:
> > progfd is created by prog_parse_fd(), before 'bpftool net attach' exit,
> > it should be closed.
> > 
> > Fixes: 04949ccc273e ("tools: bpftool: add net attach command to attach XDP on interface")
> > Signed-off-by: Wang Hai <wanghai38@huawei.com>
> > ---
> >   tools/bpf/bpftool/net.c | 2 ++
> >   1 file changed, 2 insertions(+)
> > 
> > diff --git a/tools/bpf/bpftool/net.c b/tools/bpf/bpftool/net.c
> > index 910e7bac6e9e..3e9b40e64fb0 100644
> > --- a/tools/bpf/bpftool/net.c
> > +++ b/tools/bpf/bpftool/net.c
> > @@ -600,12 +600,14 @@ static int do_attach(int argc, char **argv)
> >   	if (err < 0) {
> >   		p_err("interface %s attach failed: %s",
> >   		      attach_type_strings[attach_type], strerror(-err));
> > +		close(progfd);
> >   		return err;
> >   	}
> >   
> >   	if (json_output)
> >   		jsonw_null(json_wtr);
> >   
> > +	close(progfd);
> >   	return 0;
> >   }
> >   
> 
> Nit - wouldn't it be better to create a `cleanup`/`out` section before 
> return and use goto, to avoid copying the `close` call?

I agree would be nicer.

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

* Re: [PATCH bpf] tools: bpftool: Add missing close before bpftool net attach exit
  2020-11-09 10:51 ` Michal Rostecki
  2020-11-09 21:37   ` John Fastabend
@ 2020-11-10  1:57   ` wanghai (M)
  1 sibling, 0 replies; 5+ messages in thread
From: wanghai (M) @ 2020-11-10  1:57 UTC (permalink / raw)
  To: Michal Rostecki
  Cc: ast, daniel, kafai, songliubraving, yhs, andrii, john.fastabend,
	kpsingh, toke, quentin, danieltimlee, bpf, netdev, linux-kernel


在 2020/11/9 18:51, Michal Rostecki 写道:
> On 11/9/20 8:04 AM, Wang Hai wrote:
>> progfd is created by prog_parse_fd(), before 'bpftool net attach' exit,
>> it should be closed.
>>
>> Fixes: 04949ccc273e ("tools: bpftool: add net attach command to 
>> attach XDP on interface")
>> Signed-off-by: Wang Hai <wanghai38@huawei.com>
>> ---
>>   tools/bpf/bpftool/net.c | 2 ++
>>   1 file changed, 2 insertions(+)
>>
>> diff --git a/tools/bpf/bpftool/net.c b/tools/bpf/bpftool/net.c
>> index 910e7bac6e9e..3e9b40e64fb0 100644
>> --- a/tools/bpf/bpftool/net.c
>> +++ b/tools/bpf/bpftool/net.c
>> @@ -600,12 +600,14 @@ static int do_attach(int argc, char **argv)
>>       if (err < 0) {
>>           p_err("interface %s attach failed: %s",
>>                 attach_type_strings[attach_type], strerror(-err));
>> +        close(progfd);
>>           return err;
>>       }
>>         if (json_output)
>>           jsonw_null(json_wtr);
>>   +    close(progfd);
>>       return 0;
>>   }
>
> Nit - wouldn't it be better to create a `cleanup`/`out` section before 
> return and use goto, to avoid copying the `close` call?
> .
>
Thanks for review. I just sent v2 patch

"[PATCH v2 bpf] tools: bpftool: Add missing close before bpftool net 
attach exit"


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

end of thread, other threads:[~2020-11-10  1:57 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-09  7:04 [PATCH bpf] tools: bpftool: Add missing close before bpftool net attach exit Wang Hai
2020-11-09 10:07 ` Quentin Monnet
2020-11-09 10:51 ` Michal Rostecki
2020-11-09 21:37   ` John Fastabend
2020-11-10  1:57   ` wanghai (M)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).