diff mbox series

tracing/probe: trace_probe_primary_from_call(): checked list_first_entry

Message ID 20230128-list-entry-null-check-v1-1-8bde6a3da2ef@diag.uniroma1.it (mailing list archive)
State Accepted
Commit 81d0fa4cb4fc0e1a49c2b22f92c43d9fe972ebcf
Delegated to: Masami Hiramatsu
Headers show
Series tracing/probe: trace_probe_primary_from_call(): checked list_first_entry | expand

Commit Message

Pietro Borrello Jan. 28, 2023, 4:23 p.m. UTC
All callers of trace_probe_primary_from_call() check the return
value to be non NULL. However, the function returns
list_first_entry(&tpe->probes, ...) which can never be NULL.
Additionally, it does not check for the list being possibly empty,
possibly causing a type confusion on empty lists.
Use list_first_entry_or_null() which solves both problems.

Fixes: 60d53e2c3b75 ("tracing/probe: Split trace_event related data from trace_probe")
Signed-off-by: Pietro Borrello <borrello@diag.uniroma1.it>
---
 kernel/trace/trace_probe.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)


---
base-commit: 2241ab53cbb5cdb08a6b2d4688feb13971058f65
change-id: 20230128-list-entry-null-check-37778efda18c

Best regards,

Comments

Steven Rostedt Jan. 30, 2023, 3:19 p.m. UTC | #1
On Sat, 28 Jan 2023 16:23:41 +0000
Pietro Borrello <borrello@diag.uniroma1.it> wrote:

> All callers of trace_probe_primary_from_call() check the return
> value to be non NULL. However, the function returns
> list_first_entry(&tpe->probes, ...) which can never be NULL.
> Additionally, it does not check for the list being possibly empty,
> possibly causing a type confusion on empty lists.
> Use list_first_entry_or_null() which solves both problems.
> 
> Fixes: 60d53e2c3b75 ("tracing/probe: Split trace_event related data from trace_probe")
> Signed-off-by: Pietro Borrello <borrello@diag.uniroma1.it>
> ---
>  kernel/trace/trace_probe.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/kernel/trace/trace_probe.h b/kernel/trace/trace_probe.h
> index 23acfd1c3812..f6b565dced56 100644
> --- a/kernel/trace/trace_probe.h
> +++ b/kernel/trace/trace_probe.h
> @@ -307,7 +307,7 @@ trace_probe_primary_from_call(struct trace_event_call *call)
>  {
>  	struct trace_probe_event *tpe = trace_probe_event_from_call(call);
>  
> -	return list_first_entry(&tpe->probes, struct trace_probe, list);
> +	return list_first_entry_or_null(&tpe->probes, struct trace_probe, list);
>  }
>  
>  static inline struct list_head *trace_probe_probe_list(struct trace_probe *tp)

Reviewed-by: Steven Rostedt (Google) <rostedt@goodmis.org>

-- Steve

> 
> ---
> base-commit: 2241ab53cbb5cdb08a6b2d4688feb13971058f65
> change-id: 20230128-list-entry-null-check-37778efda18c
> 
> Best regards,
Masami Hiramatsu (Google) Feb. 17, 2023, 1:30 a.m. UTC | #2
On Sat, 28 Jan 2023 16:23:41 +0000
Pietro Borrello <borrello@diag.uniroma1.it> wrote:

> All callers of trace_probe_primary_from_call() check the return
> value to be non NULL. However, the function returns
> list_first_entry(&tpe->probes, ...) which can never be NULL.
> Additionally, it does not check for the list being possibly empty,
> possibly causing a type confusion on empty lists.
> Use list_first_entry_or_null() which solves both problems.
> 
> Fixes: 60d53e2c3b75 ("tracing/probe: Split trace_event related data from trace_probe")
> Signed-off-by: Pietro Borrello <borrello@diag.uniroma1.it>

Looks good to me.

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

And

Fixes: 60d53e2c3b75 ("tracing/probe: Split trace_event related data from trace_probe")
Cc: stable@vger.kernel.org

Thank you!

> ---
>  kernel/trace/trace_probe.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/kernel/trace/trace_probe.h b/kernel/trace/trace_probe.h
> index 23acfd1c3812..f6b565dced56 100644
> --- a/kernel/trace/trace_probe.h
> +++ b/kernel/trace/trace_probe.h
> @@ -307,7 +307,7 @@ trace_probe_primary_from_call(struct trace_event_call *call)
>  {
>  	struct trace_probe_event *tpe = trace_probe_event_from_call(call);
>  
> -	return list_first_entry(&tpe->probes, struct trace_probe, list);
> +	return list_first_entry_or_null(&tpe->probes, struct trace_probe, list);
>  }
>  
>  static inline struct list_head *trace_probe_probe_list(struct trace_probe *tp)
> 
> ---
> base-commit: 2241ab53cbb5cdb08a6b2d4688feb13971058f65
> change-id: 20230128-list-entry-null-check-37778efda18c
> 
> Best regards,
> -- 
> Pietro Borrello <borrello@diag.uniroma1.it>
Mukesh Ojha Feb. 17, 2023, 1:42 p.m. UTC | #3
>All callers of trace_probe_primary_from_call() check the return
>value to be non NULL. However, the function returns
>list_first_entry(&tpe->probes, ...) which can never be NULL.
>Additionally, it does not check for the list being possibly empty,
>possibly causing a type confusion on empty lists.
>Use list_first_entry_or_null() which solves both problems.
>
>Fixes: 60d53e2c3b75 ("tracing/probe: Split trace_event related data from trace_probe")
>Signed-off-by: Pietro Borrello <borrello@diag.uniroma1.it>
>---
> kernel/trace/trace_probe.h | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
>diff --git a/kernel/trace/trace_probe.h b/kernel/trace/trace_probe.h
>index 23acfd1c3812..f6b565dced56 100644
>--- a/kernel/trace/trace_probe.h
>+++ b/kernel/trace/trace_probe.h
>@@ -307,7 +307,7 @@ trace_probe_primary_from_call(struct trace_event_call *call)
> {
> 	struct trace_probe_event *tpe = trace_probe_event_from_call(call);
> 
>-	return list_first_entry(&tpe->probes, struct trace_probe, list);
>+	return list_first_entry_or_null(&tpe->probes, struct trace_probe, list);
> }

Nice catch !!

Acked-by: Mukesh Ojha <quic_mojha@quicinc.com>

-Mukesh
> 
> static inline struct list_head *trace_probe_probe_list(struct trace_probe *tp)
diff mbox series

Patch

diff --git a/kernel/trace/trace_probe.h b/kernel/trace/trace_probe.h
index 23acfd1c3812..f6b565dced56 100644
--- a/kernel/trace/trace_probe.h
+++ b/kernel/trace/trace_probe.h
@@ -307,7 +307,7 @@  trace_probe_primary_from_call(struct trace_event_call *call)
 {
 	struct trace_probe_event *tpe = trace_probe_event_from_call(call);
 
-	return list_first_entry(&tpe->probes, struct trace_probe, list);
+	return list_first_entry_or_null(&tpe->probes, struct trace_probe, list);
 }
 
 static inline struct list_head *trace_probe_probe_list(struct trace_probe *tp)