Re: [PATCH 1/2] tracing: Clean up find_event_field() assignment-in-if and type truncation
From: Steven Rostedt
Date: Fri Dec 04 2026 - 13:16:00 EST
On Fri, 4 Dec 2026 23:36:29 +0700
EisenWalds <aerovynqueque@xxxxxxxxx> wrote:
> find_event_field() assigns str_has_prefix() to an int and uses the
> assignment as an if condition. The int type truncates the size_t
> returned by str_has_prefix(), and checkpatch warns about the
> assignment-in-if pattern.
Checkpatch should never be used on code in the kernel.
>
> Separate the assignment from the condition and use size_t for len.
> Also drop the redundant initializer of p, which is immediately
> overwritten by the loop.
>
> No functional change.
>
> Signed-off-by: EisenWalds <aerovynqueque@xxxxxxxxx>
> ---
> kernel/trace/trace_events.c | 8 +++++---
> 1 file changed, 5 insertions(+), 3 deletions(-)
>
> diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
> index 394d7cde1..b5cbdd31c 100644
> --- a/kernel/trace/trace_events.c
> +++ b/kernel/trace/trace_events.c
> @@ -263,12 +263,14 @@ static struct trace_event_fields *find_event_field(const char *fmt,
> struct trace_event_call *call)
> {
> struct trace_event_fields *field = call->class->fields_array;
> - const char *p = fmt;
> - int len;
> + const char *p;
> + size_t len;
>
> - if (!(len = str_has_prefix(fmt, "REC->")))
NACK!!!
This is exactly the use case I created str_has_prefix() for. It returns 0
or strlen("REC->") so there is no chance of size_t being truncated when
compared to int.
-- Steve
> + len = str_has_prefix(fmt, "REC->");
> + if (!len)
> return NULL;
> fmt += len;
> +
> for (p = fmt; *p; p++) {
> if (!isalnum(*p) && *p != '_')
> break;