[v4,01/30] cocci/rte_memcpy: add script to eliminate fixed size rte_memcpy

Message ID 20240405165518.367503-2-stephen@networkplumber.org (mailing list archive)
State Superseded
Delegated to: Thomas Monjalon
Headers
Series replace use of rte_memcpy with fixed sizes |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Stephen Hemminger April 5, 2024, 4:53 p.m. UTC
  Rte_memcpy should not be used for the simple case of copying
a fix size structure because it is slower and will hide problems
from code analysis tools. Coverity, fortify and other analyzers
special case memcpy().

Gcc (and Clang) are smart enough to inline copies which
will be faster.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 devtools/cocci/rte_memcpy.cocci | 11 +++++++++++
 1 file changed, 11 insertions(+)
 create mode 100644 devtools/cocci/rte_memcpy.cocci
  

Comments

Morten Brørup April 6, 2024, 9:01 a.m. UTC | #1
> From: Stephen Hemminger [mailto:stephen@networkplumber.org]
> Sent: Friday, 5 April 2024 18.53
> 
> Rte_memcpy should not be used for the simple case of copying
> a fix size structure because it is slower and will hide problems

"it is slower"... not always true.
Perhaps: "it is not faster than memcpy".

> from code analysis tools. Coverity, fortify and other analyzers
> special case memcpy().
> 
> Gcc (and Clang) are smart enough to inline copies which
> will be faster.

"faster" -> "just as fast".

> 
> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
> ---

With the updated description,

For the series,
Acked-by: Morten Brørup <mb@smartsharesystems.com>
  

Patch

diff --git a/devtools/cocci/rte_memcpy.cocci b/devtools/cocci/rte_memcpy.cocci
new file mode 100644
index 0000000000..fa1038fc06
--- /dev/null
+++ b/devtools/cocci/rte_memcpy.cocci
@@ -0,0 +1,11 @@ 
+//
+// rte_memcpy should not be used for simple fixed size structure
+// because compiler's are smart enough to inline these.
+//
+@@
+expression src, dst; constant size;
+@@
+(
+- rte_memcpy(dst, src, size)
++ memcpy(dst, src, size)
+)