linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] perf llvm: Fix error return code in llvm__compile_bpf()
@ 2021-06-09 11:59 Zhihao Cheng
  2021-07-01 17:20 ` Arnaldo Carvalho de Melo
  0 siblings, 1 reply; 3+ messages in thread
From: Zhihao Cheng @ 2021-06-09 11:59 UTC (permalink / raw)
  To: peterz, mingo, acme, jolsa, ast, daniel, andrii, nathan, ndesaulniers
  Cc: linux-perf-users, linux-kernel, netdev, bpf, clang-built-linux,
	chengzhihao1, yukuai3

Fix to return a negative error code from the error handling
case instead of 0, as done elsewhere in this function.

Fixes: cb76371441d098 ("perf llvm: Allow passing options to llc ...")
Fixes: 5eab5a7ee032ac ("perf llvm: Display eBPF compiling command ...")
Reported-by: Hulk Robot <hulkci@huawei.com>
Signed-off-by: Zhihao Cheng <chengzhihao1@huawei.com>
---
 tools/perf/util/llvm-utils.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/tools/perf/util/llvm-utils.c b/tools/perf/util/llvm-utils.c
index 3ceaf7ef3301..2de02639fb67 100644
--- a/tools/perf/util/llvm-utils.c
+++ b/tools/perf/util/llvm-utils.c
@@ -504,8 +504,9 @@ int llvm__compile_bpf(const char *path, void **p_obj_buf,
 			goto errout;
 		}
 
-		if (asprintf(&pipe_template, "%s -emit-llvm | %s -march=bpf %s -filetype=obj -o -",
-			      template, llc_path, opts) < 0) {
+		err = asprintf(&pipe_template, "%s -emit-llvm | %s -march=bpf %s -filetype=obj -o -",
+			       template, llc_path, opts);
+		if (err < 0) {
 			pr_err("ERROR:\tnot enough memory to setup command line\n");
 			goto errout;
 		}
@@ -524,7 +525,8 @@ int llvm__compile_bpf(const char *path, void **p_obj_buf,
 
 	pr_debug("llvm compiling command template: %s\n", template);
 
-	if (asprintf(&command_echo, "echo -n \"%s\"", template) < 0)
+	err = asprintf(&command_echo, "echo -n \"%s\"", template);
+	if (err < 0)
 		goto errout;
 
 	err = read_from_pipe(command_echo, (void **) &command_out, NULL);
-- 
2.31.1


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

* Re: [PATCH] perf llvm: Fix error return code in llvm__compile_bpf()
  2021-06-09 11:59 [PATCH] perf llvm: Fix error return code in llvm__compile_bpf() Zhihao Cheng
@ 2021-07-01 17:20 ` Arnaldo Carvalho de Melo
  2021-07-02  3:01   ` Zhihao Cheng
  0 siblings, 1 reply; 3+ messages in thread
From: Arnaldo Carvalho de Melo @ 2021-07-01 17:20 UTC (permalink / raw)
  To: Zhihao Cheng
  Cc: peterz, mingo, jolsa, ast, daniel, andrii, nathan, ndesaulniers,
	linux-perf-users, linux-kernel, netdev, bpf, clang-built-linux,
	yukuai3

Em Wed, Jun 09, 2021 at 07:59:45PM +0800, Zhihao Cheng escreveu:
> Fix to return a negative error code from the error handling
> case instead of 0, as done elsewhere in this function.

I checked and llvm__compile_bpf() returns -errno, so I'll change this to
instead set err to -ENOMEM just before the if (asprintf)(), ok?

- Arnaldo
 
> Fixes: cb76371441d098 ("perf llvm: Allow passing options to llc ...")
> Fixes: 5eab5a7ee032ac ("perf llvm: Display eBPF compiling command ...")
> Reported-by: Hulk Robot <hulkci@huawei.com>
> Signed-off-by: Zhihao Cheng <chengzhihao1@huawei.com>
> ---
>  tools/perf/util/llvm-utils.c | 8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/tools/perf/util/llvm-utils.c b/tools/perf/util/llvm-utils.c
> index 3ceaf7ef3301..2de02639fb67 100644
> --- a/tools/perf/util/llvm-utils.c
> +++ b/tools/perf/util/llvm-utils.c
> @@ -504,8 +504,9 @@ int llvm__compile_bpf(const char *path, void **p_obj_buf,
>  			goto errout;
>  		}
>  
> -		if (asprintf(&pipe_template, "%s -emit-llvm | %s -march=bpf %s -filetype=obj -o -",
> -			      template, llc_path, opts) < 0) {
> +		err = asprintf(&pipe_template, "%s -emit-llvm | %s -march=bpf %s -filetype=obj -o -",
> +			       template, llc_path, opts);
> +		if (err < 0) {
>  			pr_err("ERROR:\tnot enough memory to setup command line\n");
>  			goto errout;
>  		}
> @@ -524,7 +525,8 @@ int llvm__compile_bpf(const char *path, void **p_obj_buf,
>  
>  	pr_debug("llvm compiling command template: %s\n", template);
>  
> -	if (asprintf(&command_echo, "echo -n \"%s\"", template) < 0)
> +	err = asprintf(&command_echo, "echo -n \"%s\"", template);
> +	if (err < 0)
>  		goto errout;
>  
>  	err = read_from_pipe(command_echo, (void **) &command_out, NULL);
> -- 
> 2.31.1
> 

-- 

- Arnaldo

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

* Re: [PATCH] perf llvm: Fix error return code in llvm__compile_bpf()
  2021-07-01 17:20 ` Arnaldo Carvalho de Melo
@ 2021-07-02  3:01   ` Zhihao Cheng
  0 siblings, 0 replies; 3+ messages in thread
From: Zhihao Cheng @ 2021-07-02  3:01 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: peterz, mingo, jolsa, ast, daniel, andrii, nathan, ndesaulniers,
	linux-perf-users, linux-kernel, netdev, bpf, clang-built-linux,
	yukuai3

在 2021/7/2 1:20, Arnaldo Carvalho de Melo 写道:
> Em Wed, Jun 09, 2021 at 07:59:45PM +0800, Zhihao Cheng escreveu:
>> Fix to return a negative error code from the error handling
>> case instead of 0, as done elsewhere in this function.
> 
> I checked and llvm__compile_bpf() returns -errno, so I'll change this to
> instead set err to -ENOMEM just before the if (asprintf)(), ok?
> 
> - Arnaldo
>   
Glad to accept this change.
>> Fixes: cb76371441d098 ("perf llvm: Allow passing options to llc ...")
>> Fixes: 5eab5a7ee032ac ("perf llvm: Display eBPF compiling command ...")
>> Reported-by: Hulk Robot <hulkci@huawei.com>
>> Signed-off-by: Zhihao Cheng <chengzhihao1@huawei.com>



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

end of thread, other threads:[~2021-07-02  3:01 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-09 11:59 [PATCH] perf llvm: Fix error return code in llvm__compile_bpf() Zhihao Cheng
2021-07-01 17:20 ` Arnaldo Carvalho de Melo
2021-07-02  3:01   ` Zhihao Cheng

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).