public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] tracing: branch: Fix inverted check on stat tracer registration
@ 2026-04-20 13:25 Breno Leitao
  2026-04-20 23:57 ` Masami Hiramatsu
  0 siblings, 1 reply; 2+ messages in thread
From: Breno Leitao @ 2026-04-20 13:25 UTC (permalink / raw)
  To: Steven Rostedt, Masami Hiramatsu, Mathieu Desnoyers, Ingo Molnar,
	Frederic Weisbecker
  Cc: Steven Rostedt, linux-kernel, linux-trace-kernel, paulmck,
	kernel-team, Breno Leitao

init_annotated_branch_stats() and all_annotated_branch_stats() check the
return value of register_stat_tracer() with "if (!ret)", but
register_stat_tracer() returns 0 on success and a negative errno on
failure. The inverted check causes the warning to be printed on every
successful registration, e.g.:

  Warning: could not register annotated branches stats

while leaving real failures silent. The initcall also returned a
hard-coded 1 instead of the actual error.

Invert the check and propagate ret so that the warning fires on real
errors and the initcall reports the correct status.

Fixes: 002bb86d8d42 ("tracing/ftrace: separate events tracing and stats tracing engine")
Signed-off-by: Breno Leitao <leitao@debian.org>
---
 kernel/trace/trace_branch.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/kernel/trace/trace_branch.c b/kernel/trace/trace_branch.c
index 6809b370e991d..d1564db95a8f5 100644
--- a/kernel/trace/trace_branch.c
+++ b/kernel/trace/trace_branch.c
@@ -373,10 +373,10 @@ __init static int init_annotated_branch_stats(void)
 	int ret;
 
 	ret = register_stat_tracer(&annotated_branch_stats);
-	if (!ret) {
+	if (ret) {
 		printk(KERN_WARNING "Warning: could not register "
 				    "annotated branches stats\n");
-		return 1;
+		return ret;
 	}
 	return 0;
 }
@@ -438,10 +438,10 @@ __init static int all_annotated_branch_stats(void)
 	int ret;
 
 	ret = register_stat_tracer(&all_branch_stats);
-	if (!ret) {
+	if (ret) {
 		printk(KERN_WARNING "Warning: could not register "
 				    "all branches stats\n");
-		return 1;
+		return ret;
 	}
 	return 0;
 }

---
base-commit: c7275b05bc428c7373d97aa2da02d3a7fa6b9f66
change-id: 20260420-tracing-3f1367ee4b93

Best regards,
--  
Breno Leitao <leitao@debian.org>


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

* Re: [PATCH] tracing: branch: Fix inverted check on stat tracer registration
  2026-04-20 13:25 [PATCH] tracing: branch: Fix inverted check on stat tracer registration Breno Leitao
@ 2026-04-20 23:57 ` Masami Hiramatsu
  0 siblings, 0 replies; 2+ messages in thread
From: Masami Hiramatsu @ 2026-04-20 23:57 UTC (permalink / raw)
  To: Breno Leitao
  Cc: Steven Rostedt, Mathieu Desnoyers, Ingo Molnar,
	Frederic Weisbecker, Steven Rostedt, linux-kernel,
	linux-trace-kernel, paulmck, kernel-team

On Mon, 20 Apr 2026 06:25:09 -0700
Breno Leitao <leitao@debian.org> wrote:

> init_annotated_branch_stats() and all_annotated_branch_stats() check the
> return value of register_stat_tracer() with "if (!ret)", but
> register_stat_tracer() returns 0 on success and a negative errno on
> failure. The inverted check causes the warning to be printed on every
> successful registration, e.g.:
> 
>   Warning: could not register annotated branches stats
> 
> while leaving real failures silent. The initcall also returned a
> hard-coded 1 instead of the actual error.
> 
> Invert the check and propagate ret so that the warning fires on real
> errors and the initcall reports the correct status.
> 

Good catch!

Acked-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>

Thanks,

> Fixes: 002bb86d8d42 ("tracing/ftrace: separate events tracing and stats tracing engine")
> Signed-off-by: Breno Leitao <leitao@debian.org>
> ---
>  kernel/trace/trace_branch.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/kernel/trace/trace_branch.c b/kernel/trace/trace_branch.c
> index 6809b370e991d..d1564db95a8f5 100644
> --- a/kernel/trace/trace_branch.c
> +++ b/kernel/trace/trace_branch.c
> @@ -373,10 +373,10 @@ __init static int init_annotated_branch_stats(void)
>  	int ret;
>  
>  	ret = register_stat_tracer(&annotated_branch_stats);
> -	if (!ret) {
> +	if (ret) {
>  		printk(KERN_WARNING "Warning: could not register "
>  				    "annotated branches stats\n");
> -		return 1;
> +		return ret;
>  	}
>  	return 0;
>  }
> @@ -438,10 +438,10 @@ __init static int all_annotated_branch_stats(void)
>  	int ret;
>  
>  	ret = register_stat_tracer(&all_branch_stats);
> -	if (!ret) {
> +	if (ret) {
>  		printk(KERN_WARNING "Warning: could not register "
>  				    "all branches stats\n");
> -		return 1;
> +		return ret;
>  	}
>  	return 0;
>  }
> 
> ---
> base-commit: c7275b05bc428c7373d97aa2da02d3a7fa6b9f66
> change-id: 20260420-tracing-3f1367ee4b93
> 
> Best regards,
> --  
> Breno Leitao <leitao@debian.org>
> 


-- 
Masami Hiramatsu (Google) <mhiramat@kernel.org>

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

end of thread, other threads:[~2026-04-20 23:57 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-20 13:25 [PATCH] tracing: branch: Fix inverted check on stat tracer registration Breno Leitao
2026-04-20 23:57 ` Masami Hiramatsu

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