sparc: time: Use pointer from memcpy() call for assignment in setup_sparc64_timer()
Subsystems (2)
PATCH 1/1 sparc: time: Use pointer from memcpy() call for assignment in setup_sparc64_timer()
From: Markus Elfring <[email protected]>
Date: Fri, 31 Oct 2025 08:36:13 +0100
A pointer was assigned to a variable. The same pointer was used for the destination parameter of a memcpy() call.
This function is documented in the way that the same value is returned. Thus convert two separate statements into a direct variable assignment for the return value from a memory copy action.
The source code was transformed by using the Coccinelle software.
--- arch/sparc/kernel/time_64.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
arch/sparc/kernel/time_64.c +1 -3
@@ -760,9 +760,7 @@ void setup_sparc64_timer(void) : /* no outputs */ : "r" (pstate)); - sevt =this_cpu_ptr (&sparc64_events); - -memcpy (sevt, &sparc64_clockevent,sizeof (*sevt)); + sevt =memcpy (this_cpu_ptr (&sparc64_events), &sparc64_clockevent,sizeof (*sevt)); sevt->cpumask =cpumask_of (smp_processor_id ());clockevents_register_device (sevt);
Signature · 1 line
2.51.1
Hi Markus,
Quoted 9 lines · Markus Elfring
From: Markus Elfring <[email protected]>
Date: Fri, 31 Oct 2025 08:36:13 +0100A pointer was assigned to a variable. The same pointer was used for the destination parameter of a
memcpy()call.
This function is documented in the way that the same value is returned. Thus convert two separate statements into a direct variable assignment for the return value from a memory copy action.
Quoted 3 lines
The source code was transformed by using the Coccinelle software.
Signed-off-by Markus Elfring <[email protected]>
Thanks for your patch!
arch/sparc/kernel/time_64.c void setup_sparc64_timer(void) · line 763
Quoted 10 lines
arch/sparc/kernel/time_64.c +1
-3@@ -760,9 +760,7 @@ void setup_sparc64_timer(void) : /* no outputs */ : "r" (pstate)); - sevt =this_cpu_ptr (&sparc64_events); - -memcpy (sevt, &sparc64_clockevent,sizeof (*sevt)); + sevt =memcpy (this_cpu_ptr (&sparc64_events), &sparc64_clockevent,sizeof (*sevt));
IMHO this makes the code harder to read:
- Only 0.15% of the memcpy() calls in the kernel use the memcpy() chaining feature,
- The line is now longer than the 80-character limit, which is still customary for this file.
arch/sparc/kernel/time_64.c void setup_sparc64_timer(void) · line 766
Quoted 3 lines
arch/sparc/kernel/time_64.c +0
-0sevt->cpumask =cpumask_of (smp_processor_id ());clockevents_register_device (sevt);
Gr{oetje,eeting}s,
Geert
Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected] In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds
…>> +++ b/arch/sparc/kernel/time_64.c
Quoted 4 lines
Quoted 4 lines
arch/sparc/kernel/time_64.c +0
-0@@ -760,9 +760,7 @@ void setup_sparc64_timer(void) : /* no outputs */ : "r" (pstate));
Quoted 8 lines
arch/sparc/kernel/time_64.c void setup_sparc64_timer(void) · line 763
Quoted 4 lines
arch/sparc/kernel/time_64.c +1
-3- sevt =this_cpu_ptr (&sparc64_events); - -memcpy (sevt, &sparc64_clockevent,sizeof (*sevt)); + sevt =memcpy (this_cpu_ptr (&sparc64_events), &sparc64_clockevent,sizeof (*sevt));IMHO this makes the code harder to read:
- Only 0.15% of thememcpy()calls in the kernel use thememcpy()chaining feature,
I obviously propose to refactor this implementation detail.
Quoted 2 lines
- The line is now longer than the 80-character limit, which is still customary for this file.
Would you like to get a subsequent patch variant?
Regards,
Markus
Quoted 14 lines · On Fri, 31 Oct 2025 09:46:25 +0100 Markus Elfring <[email protected]> wrote:
…>> +++
b/arch/sparc/kernel/time_64.cQuoted 4 lines
Quoted 4 lines
arch/sparc/kernel/time_64.c +0
-0@@ -760,9 +760,7 @@ void setup_sparc64_timer(void) : /* no outputs */ : "r" (pstate));Quoted 8 lines
arch/sparc/kernel/time_64.c void setup_sparc64_timer(void) · line 763
Quoted 4 lines
arch/sparc/kernel/time_64.c +1
-3- sevt =this_cpu_ptr (&sparc64_events); - -memcpy (sevt, &sparc64_clockevent,sizeof (*sevt)); + sevt =memcpy (this_cpu_ptr (&sparc64_events), &sparc64_clockevent,sizeof (*sevt));IMHO this makes the code harder to read:
- Only 0.15% of thememcpy()calls in the kernel use thememcpy()chaining feature,
Quoted 1 line
I obviously propose to refactor this implementation detail.
Reduce it to 0% and the kernel memcpy() can be made 'void'. :-) That will simplify the architecture specific implementations.
The same can be done for strcpy() and strcat() (etc). Where the 'useful' return value would be the address of the '\0'.
David
Hi Markus,
Quoted 13 lines · Markus Elfring
…>> +++
b/arch/sparc/kernel/time_64.cQuoted 12 lines
arch/sparc/kernel/time_64.c void setup_sparc64_timer(void) · line 763
Quoted 8 lines
arch/sparc/kernel/time_64.c +1
-3@@ -760,9 +760,7 @@ void setup_sparc64_timer(void) : /* no outputs */ : "r" (pstate)); - sevt =this_cpu_ptr (&sparc64_events); - -memcpy (sevt, &sparc64_clockevent,sizeof (*sevt)); + sevt =memcpy (this_cpu_ptr (&sparc64_events), &sparc64_clockevent,sizeof (*sevt));IMHO this makes the code harder to read:
- Only 0.15% of thememcpy()calls in the kernel use thememcpy()chaining feature,
It is also less clear the passed size matches the destination pointer.
Quoted 1 line
I obviously propose to refactor this implementation detail.
Oh no...
<other-bad-ideas>
The above function could be shortened by writing
(sevt = memcpy(this_cpu_ptr(&sparc64_events), &sparc64_clockevent,
sizeof(*sevt)))->cpumask = cpumask_of(smp_processor_id());
And after introducing a variant of clockevents_register_device() that takes the cpumask as a parameter:
clockevents_register_device_with_cpumask(memcpy(this_cpu_ptr(&sparc64_events),&sparc64_clockevent, sizeof(*sevt)), cpumask_of(smp_processor_id()));
</other-bad-ideas>
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]
In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
Quoted 5 lines · Geert Uytterhoeven
The above function could be shortened by writing
(sevt = memcpy(this_cpu_ptr(&sparc64_events), &sparc64_clockevent,sizeof(*sevt)))->cpumask = cpumask_of(smp_processor_id());
Heh.
regards,
dan carpenter