diff options
Diffstat (limited to 'src/spdk/dpdk/devtools/cocci')
-rw-r--r-- | src/spdk/dpdk/devtools/cocci/mtod-offset.cocci | 76 | ||||
-rw-r--r-- | src/spdk/dpdk/devtools/cocci/strlcpy-with-header.cocci | 12 | ||||
-rw-r--r-- | src/spdk/dpdk/devtools/cocci/strlcpy.cocci | 7 |
3 files changed, 95 insertions, 0 deletions
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) +) |