[PATCH v2 01/68] devtools/cocci: add script to replace fixed size rte_memcpy

Stephen Hemminger <[email protected]>
Newsgroups org.dpdk.dev
Message-ID <[email protected]>
Rte_memcpy need not be used for the simple case of copying
a fix sized because it is not faster and will hide problems
from code analysis tools. Static and dynamic analyzers
special case memcpy() and can find issues that rte_memcpy()
will hide.

Note: many platforms use memcpy instead of rte_memcpy already.
The only reason rte_memcpy() was added in original DPDK was that
the older Gcc was doing slower on x86 than the special rte_memcpy()
when handling larger size copies.

Signed-off-by: Stephen Hemminger <[email protected]>
---
 devtools/cocci/rte_memcpy_fixed.cocci | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
 create mode 100644 devtools/cocci/rte_memcpy_fixed.cocci

diff --git a/devtools/cocci/rte_memcpy_fixed.cocci b/devtools/cocci/rte_memcpy_fixed.cocci
new file mode 100644
index 0000000000..1f264711eb
--- /dev/null
+++ b/devtools/cocci/rte_memcpy_fixed.cocci
@@ -0,0 +1,15 @@
+//
+// rte_memcpy should not be used for simple fixed size structure
+// because compiler's are smart enough to inline these.
+//
+@@
+expression src, dst, E;
+constant size;
+@@
+(
+- rte_memcpy(dst, src, sizeof(E))
++ memcpy(dst, src, sizeof(E))
+|
+- rte_memcpy(dst, src, size)
++ memcpy(dst, src, size)
+)
-- 
2.53.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.