2023-01-28 16:24:22

by Pietro Borrello

[permalink] [raw]
Subject: [PATCH] tracing/probe: trace_probe_primary_from_call(): checked list_first_entry

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 <[email protected]>
---
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 <[email protected]>


2023-01-30 15:20:16

by Steven Rostedt

[permalink] [raw]
Subject: Re: [PATCH] tracing/probe: trace_probe_primary_from_call(): checked list_first_entry

On Sat, 28 Jan 2023 16:23:41 +0000
Pietro Borrello <[email protected]> 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 <[email protected]>
> ---
> 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) <[email protected]>

-- Steve

>
> ---
> base-commit: 2241ab53cbb5cdb08a6b2d4688feb13971058f65
> change-id: 20230128-list-entry-null-check-37778efda18c
>
> Best regards,


2023-02-17 01:30:31

by Masami Hiramatsu

[permalink] [raw]
Subject: Re: [PATCH] tracing/probe: trace_probe_primary_from_call(): checked list_first_entry

On Sat, 28 Jan 2023 16:23:41 +0000
Pietro Borrello <[email protected]> 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 <[email protected]>

Looks good to me.

Acked-by: Masami Hiramatsu (Google) <[email protected]>

And

Fixes: 60d53e2c3b75 ("tracing/probe: Split trace_event related data from trace_probe")
Cc: [email protected]

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 <[email protected]>


--
Masami Hiramatsu (Google) <[email protected]>

2023-02-17 13:44:04

by Mukesh Ojha

[permalink] [raw]
Subject: Re: [PATCH] tracing/probe: trace_probe_primary_from_call(): checked list_first_entry

>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 <[email protected]>
>---
> 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 <[email protected]>

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