[1/5] cocci: add script to use RTE_DIM
Checks
Commit Message
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
new file mode 100644
@@ -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)
+)