[1/5] cocci: add script to use RTE_DIM

Message ID 20240416152124.69590-2-stephen@networkplumber.org (mailing list archive)
State New
Delegated to: Thomas Monjalon
Headers
Series use RTE_DIM where possible |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Stephen Hemminger April 16, 2024, 3:19 p.m. UTC
  New script to find RTE_DIM should be used.

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

Patch

diff --git a/devtools/cocci/rte-dim.cocci b/devtools/cocci/rte-dim.cocci
new file mode 100644
index 0000000000..e7fcadec98
--- /dev/null
+++ b/devtools/cocci/rte-dim.cocci
@@ -0,0 +1,23 @@ 
+// SPDX-License-Identifier: BSD-3-Clause
+// Use RTE_DIM macro instead of dividing sizeof array with sizeof an elmemnt
+//
+// Based of Linux kernela array_size.cocci
+//
+@@
+type T;
+T[] E;
+@@
+(
+|
+- (sizeof(E)/sizeof(E[...]))
++ RTE_DIM(E)
+|
+- (sizeof(E)/sizeof(*E))
++ RTE_DIM(E)
+|
+- (sizeof(E)/sizeof(T))
++ RTE_DIM(E)
+|
+- RTE_DIM((E))
++ RTE_DIM(E)
+)