kernel-janitors.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] sparc: time: Use pointer from memcpy() call for assignment in setup_sparc64_timer()
@ 2025-10-31  7:46 Markus Elfring
  2025-10-31  8:01 ` Geert Uytterhoeven
  0 siblings, 1 reply; 6+ messages in thread
From: Markus Elfring @ 2025-10-31  7:46 UTC (permalink / raw)
  To: sparclinux, Alexandre Belloni, Andreas Larsson, Christoph Lameter,
	David S. Miller, Finn Thain, Geert Uytterhoeven, Tejun Heo
  Cc: LKML, kernel-janitors, Miaoqian Lin

From: Markus Elfring <elfring@users.sourceforge.net>
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.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 arch/sparc/kernel/time_64.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/arch/sparc/kernel/time_64.c b/arch/sparc/kernel/time_64.c
index b32f27f929d1..e9c29574cd59 100644
--- a/arch/sparc/kernel/time_64.c
+++ b/arch/sparc/kernel/time_64.c
@@ -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);
-- 
2.51.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] sparc: time: Use pointer from memcpy() call for assignment in setup_sparc64_timer()
  2025-10-31  7:46 [PATCH] sparc: time: Use pointer from memcpy() call for assignment in setup_sparc64_timer() Markus Elfring
@ 2025-10-31  8:01 ` Geert Uytterhoeven
  2025-10-31  8:46   ` Markus Elfring
  0 siblings, 1 reply; 6+ messages in thread
From: Geert Uytterhoeven @ 2025-10-31  8:01 UTC (permalink / raw)
  To: Markus Elfring
  Cc: sparclinux, Alexandre Belloni, Andreas Larsson, Christoph Lameter,
	David S. Miller, Finn Thain, Tejun Heo, LKML, kernel-janitors,
	Miaoqian Lin

Hi Markus,

On Fri, 31 Oct 2025 at 08:46, Markus Elfring <Markus.Elfring@web.de> wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> 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.
>
> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>

Thanks for your patch!

> --- a/arch/sparc/kernel/time_64.c
> +++ b/arch/sparc/kernel/time_64.c
> @@ -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.

>         sevt->cpumask = cpumask_of(smp_processor_id());
>
>         clockevents_register_device(sevt);

Gr{oetje,eeting}s,

                        Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] sparc: time: Use pointer from memcpy() call for assignment in setup_sparc64_timer()
  2025-10-31  8:01 ` Geert Uytterhoeven
@ 2025-10-31  8:46   ` Markus Elfring
  2025-10-31  9:51     ` David Laight
  2025-10-31 10:08     ` Geert Uytterhoeven
  0 siblings, 2 replies; 6+ messages in thread
From: Markus Elfring @ 2025-10-31  8:46 UTC (permalink / raw)
  To: Geert Uytterhoeven, sparclinux
  Cc: Alexandre Belloni, Andreas Larsson, Christoph Lameter,
	David S. Miller, Finn Thain, Tejun Heo, LKML, kernel-janitors,
	Miaoqian Lin

…>> +++ b/arch/sparc/kernel/time_64.c
>> @@ -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,

I obviously propose to refactor this implementation detail.


>   - 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


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] sparc: time: Use pointer from memcpy() call for assignment in setup_sparc64_timer()
  2025-10-31  8:46   ` Markus Elfring
@ 2025-10-31  9:51     ` David Laight
  2025-10-31 10:08     ` Geert Uytterhoeven
  1 sibling, 0 replies; 6+ messages in thread
From: David Laight @ 2025-10-31  9:51 UTC (permalink / raw)
  To: Markus Elfring
  Cc: Geert Uytterhoeven, sparclinux, Alexandre Belloni,
	Andreas Larsson, Christoph Lameter, David S. Miller, Finn Thain,
	Tejun Heo, LKML, kernel-janitors, Miaoqian Lin

On Fri, 31 Oct 2025 09:46:25 +0100
Markus Elfring <Markus.Elfring@web.de> wrote:

> …>> +++ b/arch/sparc/kernel/time_64.c
> >> @@ -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,  
> 
> 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



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] sparc: time: Use pointer from memcpy() call for assignment in setup_sparc64_timer()
  2025-10-31  8:46   ` Markus Elfring
  2025-10-31  9:51     ` David Laight
@ 2025-10-31 10:08     ` Geert Uytterhoeven
  2025-10-31 11:27       ` Dan Carpenter
  1 sibling, 1 reply; 6+ messages in thread
From: Geert Uytterhoeven @ 2025-10-31 10:08 UTC (permalink / raw)
  To: Markus Elfring
  Cc: sparclinux, Alexandre Belloni, Andreas Larsson, Christoph Lameter,
	David S. Miller, Finn Thain, Tejun Heo, LKML, kernel-janitors,
	Miaoqian Lin

Hi Markus,

On Fri, 31 Oct 2025 at 09:46, Markus Elfring <Markus.Elfring@web.de> wrote:
> …>> +++ b/arch/sparc/kernel/time_64.c
> >> @@ -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,

It is also less clear the passed size matches the destination pointer.

> 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 -- geert@linux-m68k.org

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] sparc: time: Use pointer from memcpy() call for assignment in setup_sparc64_timer()
  2025-10-31 10:08     ` Geert Uytterhoeven
@ 2025-10-31 11:27       ` Dan Carpenter
  0 siblings, 0 replies; 6+ messages in thread
From: Dan Carpenter @ 2025-10-31 11:27 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: Markus Elfring, sparclinux, Alexandre Belloni, Andreas Larsson,
	Christoph Lameter, David S. Miller, Finn Thain, Tejun Heo, LKML,
	kernel-janitors, Miaoqian Lin

On Fri, Oct 31, 2025 at 11:08:39AM +0100, Geert Uytterhoeven wrote:
> 
> 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


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2025-10-31 11:27 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-31  7:46 [PATCH] sparc: time: Use pointer from memcpy() call for assignment in setup_sparc64_timer() Markus Elfring
2025-10-31  8:01 ` Geert Uytterhoeven
2025-10-31  8:46   ` Markus Elfring
2025-10-31  9:51     ` David Laight
2025-10-31 10:08     ` Geert Uytterhoeven
2025-10-31 11:27       ` Dan Carpenter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).