Signed-off-by: Philippe Mathieu-Daudé <f4...@amsat.org> --- scripts/coccinelle/use_osdep.cocci | 60 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 scripts/coccinelle/use_osdep.cocci
diff --git a/scripts/coccinelle/use_osdep.cocci b/scripts/coccinelle/use_osdep.cocci new file mode 100644 index 0000000000..356b36e358 --- /dev/null +++ b/scripts/coccinelle/use_osdep.cocci @@ -0,0 +1,60 @@ +// Use macros from qemu/osdep.h +// +// Copyright: (C) 2017 Philippe Mathieu-Daudé. GPLv2+. +// Confidence: High +// Options: --macro-file scripts/cocci-macro-file.h +// +// docker run --rm -v `pwd`:`pwd` -w `pwd` philmd/coccinelle \ +// --macro-file scripts/cocci-macro-file.h \ +// --sp-file scripts/coccinelle/add_osdep.cocci \ +// --keep-comments --in-place \ +// --use-gitgrep --dir . + +// Use QEMU_IS_ALIGNED() +@@ +typedef uintptr_t; +uintptr_t ptr; +expression n, m; +@@ +( +-ptr % m == 0 ++QEMU_PTR_IS_ALIGNED(ptr, m) +| +-n % m == 0 ++QEMU_IS_ALIGNED(n, m) +) + +// Use QEMU_ALIGN_DOWN() +@@ +expression n, m; +@@ +-n / m * m ++QEMU_ALIGN_DOWN(n, m) + +// Use ARRAY_SIZE() +@@ +expression x; +@@ +-sizeof(x) / sizeof((x)[0]) ++ARRAY_SIZE(x) + +// Drop superfluous parenthesis +@@ +expression n, m; +@@ +( +-(QEMU_IS_ALIGNED(n, m)) ++QEMU_IS_ALIGNED(n, m) +| +-QEMU_IS_ALIGNED((n), m) ++QEMU_IS_ALIGNED(n, m) +| +-(QEMU_PTR_IS_ALIGNED(n, m)) ++QEMU_PTR_IS_ALIGNED(n, m) +| +-QEMU_ALIGN_DOWN((n), m) ++QEMU_ALIGN_DOWN(n, m) +| +-(ARRAY_SIZE(n)) ++ARRAY_SIZE(n) +) -- 2.13.2