Re: [cocci] [RFC] Increasing usage of direct pointer assignments from memcpy() calls with SmPL?

From: Markus Elfring

Date: Thu Oct 30 2025 - 05:33:21 EST


>> It can be determined then from the generated diff file that mentioned
>> implementation details can be transformed in 304 source files at the moment.
>> Thus I became curious if it would be supported to adjust any places there
>> according to (Linux) coding style preferences.
>
> If you have a concern, you have to say what it is.

I expressed something for further development considerations.
The source code analysis result can be interpreted in some directions.


> It doesn't seem it is
> about the running time,

Not directly in this case.


> so why do you include that information?

Further software users can compare such a measurement with other observations.


> I should not have to repeat your experiment to figure out what you are
> asking about.

You can recognise recurring development challenges, can't you?

* Change resistance

* Varying coding style preferences

* Code improvement possibilities

* Development resources

* Pretty-printing issues


Another test result representation for your convenience:
https://elixir.bootlin.com/linux/v6.18-rc3/source/arch/arm64/kvm/arm.c#L2554-L2726

Markus_Elfring@Sonne:…/Projekte/Linux/next-analyses> time /usr/bin/spatch --max-width 100 --no-loops …/Projekte/Coccinelle/janitor/use_memcpy_assignment.cocci arch/arm64/kvm/arm.c

@@ -2600,8 +2600,8 @@ static int __init init_hyp_mode(void)
goto out_err;
}

- page_addr = page_address(page);
- memcpy(page_addr, CHOOSE_NVHE_SYM(__per_cpu_start), nvhe_percpu_size());
+ page_addr =
+ memcpy(page_address(page), CHOOSE_NVHE_SYM(__per_cpu_start), nvhe_percpu_size());
kvm_nvhe_sym(kvm_arm_hyp_percpu_base)[cpu] = (unsigned long)page_addr;
}


real 0m0,606s
user 0m0,576s
sys 0m0,030s



Another SmPL script example might become helpful.

@replacement2@
expression object, size, source, target;
@@
target =
- object; memcpy(target, source, size)
+ memcpy(object, source, size)
;


Markus_Elfring@Sonne:…/Projekte/Linux/next-analyses> time /usr/bin/spatch --max-width 100 --no-loops …/Projekte/Coccinelle/janitor/use_memcpy_assignment2.cocci arch/arm64/kvm/arm.c

@@ -2600,8 +2600,8 @@ static int __init init_hyp_mode(void)
goto out_err;
}

- page_addr = page_address(page);
- memcpy(page_addr, CHOOSE_NVHE_SYM(__per_cpu_start), nvhe_percpu_size());
+ page_addr =memcpy(page_address(page), CHOOSE_NVHE_SYM(__per_cpu_start),
+ nvhe_percpu_size());
kvm_nvhe_sym(kvm_arm_hyp_percpu_base)[cpu] = (unsigned long)page_addr;
}


real 0m0,626s
user 0m0,588s
sys 0m0,037s


Regards,
Markus