Better to use ret_calloc() than directly multiply up the
sizes of objects.

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

diff --git a/devtools/cocci/prefer-calloc.cocci 
b/devtools/cocci/prefer-calloc.cocci
new file mode 100644
index 0000000000..77defed9f6
--- /dev/null
+++ b/devtools/cocci/prefer-calloc.cocci
@@ -0,0 +1,19 @@
+//
+// Prefer use of calloc over zmalloc when allocating multiple objects
+//
+@@
+expression name, T, num, socket, align;
+@@
+(
+- rte_zmalloc(name, num * sizeof(T), align)
++ rte_calloc(name, num, sizeof(T), align)
+|
+- rte_zmalloc(name, sizeof(T) * num, align)
++ rte_calloc(name, num, sizeof(T), align)
+|
+- rte_zmalloc_socket(name, num * sizeof(T), align, socket)
++ rte_calloc_socket(name, num, sizeof(T), align, socket)
+|
+- rte_zmalloc_socket(name, sizeof(T) * num, align, socket)
++ rte_calloc_socket(name, num, sizeof(T), align, socket)
+)
-- 
2.43.0

Reply via email to