Skip to content

Commit

Permalink
perf/core: Remove optional 'size' arguments from strscpy() calls
Browse files Browse the repository at this point in the history
The 'size' parameter is optional and strscpy() automatically determines
the length of the destination buffer using sizeof() if the argument is
omitted. This makes the explicit sizeof() calls unnecessary.

Furthermore, KSYM_NAME_LEN is equal to sizeof(name) and can also be
removed. Remove them to shorten and simplify the code.

Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Link: https://lore.kernel.org/r/20250310192336.442994-1-thorsten.blum@linux.dev
  • Loading branch information
Thorsten Blum authored and Ingo Molnar committed Mar 10, 2025
1 parent 7a310c6 commit fd3f5d3
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions kernel/events/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -8665,7 +8665,7 @@ static void perf_event_comm_event(struct perf_comm_event *comm_event)
unsigned int size;

memset(comm, 0, sizeof(comm));
strscpy(comm, comm_event->task->comm, sizeof(comm));
strscpy(comm, comm_event->task->comm);
size = ALIGN(strlen(comm)+1, sizeof(u64));

comm_event->comm = comm;
Expand Down Expand Up @@ -9109,7 +9109,7 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
}

cpy_name:
strscpy(tmp, name, sizeof(tmp));
strscpy(tmp, name);
name = tmp;
got_name:
/*
Expand Down Expand Up @@ -9533,7 +9533,7 @@ void perf_event_ksymbol(u16 ksym_type, u64 addr, u32 len, bool unregister,
ksym_type == PERF_RECORD_KSYMBOL_TYPE_UNKNOWN)
goto err;

strscpy(name, sym, KSYM_NAME_LEN);
strscpy(name, sym);
name_len = strlen(name) + 1;
while (!IS_ALIGNED(name_len, sizeof(u64)))
name[name_len++] = '\0';
Expand Down

0 comments on commit fd3f5d3

Please sign in to comment.