summaryrefslogtreecommitdiffstats
path: root/src/spdk/dpdk/devtools/cocci
diff options
context:
space:
mode:
Diffstat (limited to '')
-rwxr-xr-xsrc/spdk/dpdk/devtools/cocci.sh36
-rw-r--r--src/spdk/dpdk/devtools/cocci/mtod-offset.cocci76
-rw-r--r--src/spdk/dpdk/devtools/cocci/strlcpy-with-header.cocci12
-rw-r--r--src/spdk/dpdk/devtools/cocci/strlcpy.cocci7
4 files changed, 131 insertions, 0 deletions
diff --git a/src/spdk/dpdk/devtools/cocci.sh b/src/spdk/dpdk/devtools/cocci.sh
new file mode 100755
index 000000000..ab9a6efe9
--- /dev/null
+++ b/src/spdk/dpdk/devtools/cocci.sh
@@ -0,0 +1,36 @@
+#! /bin/sh
+# SPDX-License-Identifier: BSD-3-Clause
+# Copyright 2015-2020 Mellanox Technologies, Ltd
+
+# Apply coccinelle transforms.
+
+SRCTREE=$(readlink -f $(dirname $0)/..)
+COCCI=$SRCTREE/devtools/cocci
+[ -n "$SPATCH" ] || SPATCH=$(which spatch)
+
+PATCH_LIST="$@"
+[ -n "$PATCH_LIST" ] || PATCH_LIST=$(echo $COCCI/*.cocci)
+
+[ -x "$SPATCH" ] || (
+ echo "Coccinelle tools not installed."
+ exit 1
+)
+
+tmp=$(mktemp -t dpdk.cocci.XXX)
+
+for c in $PATCH_LIST; do
+ while true; do
+ echo -n "Applying $c..."
+ $SPATCH --sp-file $c -c --linux-spacing --very-quiet \
+ --include-headers --preprocess \
+ --in-place --dir $SRCTREE > $tmp
+ if [ -s $tmp ]; then
+ echo " changes applied, retrying."
+ else
+ echo " no change."
+ break;
+ fi
+ done
+done
+
+rm -f $tmp
diff --git a/src/spdk/dpdk/devtools/cocci/mtod-offset.cocci b/src/spdk/dpdk/devtools/cocci/mtod-offset.cocci
new file mode 100644
index 000000000..3f83f3223
--- /dev/null
+++ b/src/spdk/dpdk/devtools/cocci/mtod-offset.cocci
@@ -0,0 +1,76 @@
+//
+// Replace explicit packet offset computations with rte_pktmbuf_mtod_offset().
+//
+@disable paren@
+typedef uint8_t;
+expression M, O;
+@@
+(
+- rte_pktmbuf_mtod(M, char *) + O
++ rte_pktmbuf_mtod_offset(M, char *, O)
+|
+- rte_pktmbuf_mtod(M, char *) - O
++ rte_pktmbuf_mtod_offset(M, char *, -O)
+|
+- rte_pktmbuf_mtod(M, unsigned char *) + O
++ rte_pktmbuf_mtod_offset(M, unsigned char *, O)
+|
+- rte_pktmbuf_mtod(M, unsigned char *) - O
++ rte_pktmbuf_mtod_offset(M, unsigned char *, -O)
+|
+- rte_pktmbuf_mtod(M, uint8_t *) + O
++ rte_pktmbuf_mtod_offset(M, uint8_t *, O)
+|
+- rte_pktmbuf_mtod(M, uint8_t *) - O
++ rte_pktmbuf_mtod_offset(M, uint8_t *, -O)
+)
+
+
+//
+// Fold subsequent offset terms into pre-existing offset used in
+// rte_pktmbuf_mtod_offset().
+//
+@disable paren@
+expression M, O1, O2;
+@@
+(
+- rte_pktmbuf_mtod_offset(M, char *, O1) + O2
++ rte_pktmbuf_mtod_offset(M, char *, O1 + O2)
+|
+- rte_pktmbuf_mtod_offset(M, char *, O1) - O2
++ rte_pktmbuf_mtod_offset(M, char *, O1 - O2)
+|
+- rte_pktmbuf_mtod_offset(M, unsigned char *, O1) + O2
++ rte_pktmbuf_mtod_offset(M, unsigned char *, O1 + O2)
+|
+- rte_pktmbuf_mtod_offset(M, unsigned char *, O1) - O2
++ rte_pktmbuf_mtod_offset(M, unsigned char *, O1 - O2)
+|
+- rte_pktmbuf_mtod_offset(M, uint8_t *, O1) + O2
++ rte_pktmbuf_mtod_offset(M, uint8_t *, O1 + O2)
+|
+- rte_pktmbuf_mtod_offset(M, uint8_t *, O1) - O2
++ rte_pktmbuf_mtod_offset(M, uint8_t *, O1 - O2)
+)
+
+
+//
+// Cleanup rules. Fold in double casts, remove unnecessary parenthesis, etc.
+//
+@disable paren@
+expression M, O;
+type C, T;
+@@
+(
+- (C)rte_pktmbuf_mtod_offset(M, T, O)
++ rte_pktmbuf_mtod_offset(M, C, O)
+|
+- (rte_pktmbuf_mtod_offset(M, T, O))
++ rte_pktmbuf_mtod_offset(M, T, O)
+|
+- (C)rte_pktmbuf_mtod(M, T)
++ rte_pktmbuf_mtod(M, C)
+|
+- (rte_pktmbuf_mtod(M, T))
++ rte_pktmbuf_mtod(M, T)
+)
diff --git a/src/spdk/dpdk/devtools/cocci/strlcpy-with-header.cocci b/src/spdk/dpdk/devtools/cocci/strlcpy-with-header.cocci
new file mode 100644
index 000000000..046cdbdad
--- /dev/null
+++ b/src/spdk/dpdk/devtools/cocci/strlcpy-with-header.cocci
@@ -0,0 +1,12 @@
+@include@
+@@
+
+#include <rte_string_fns.h>
+
+@use_strlcpy depends on include@
+expression src, dst, size;
+@@
+(
+- snprintf(dst, size, "%s", src)
++ strlcpy(dst, src, size)
+)
diff --git a/src/spdk/dpdk/devtools/cocci/strlcpy.cocci b/src/spdk/dpdk/devtools/cocci/strlcpy.cocci
new file mode 100644
index 000000000..6f6beb697
--- /dev/null
+++ b/src/spdk/dpdk/devtools/cocci/strlcpy.cocci
@@ -0,0 +1,7 @@
+@use_strlcpy@
+expression src, dst, size;
+@@
+(
+- snprintf(dst, size, "%s", src)
++ strlcpy(dst, src, size)
+)