[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH-for-5.1 v3 13/23] scripts/coccinelle: Add script to catch missing
From: |
Philippe Mathieu-Daudé |
Subject: |
[PATCH-for-5.1 v3 13/23] scripts/coccinelle: Add script to catch missing error_propagate() calls |
Date: |
Mon, 13 Apr 2020 00:41:34 +0200 |
In some places in we put an error into a local Error*, but forget
to check for failure and pass it back to the caller.
Add a Coccinelle patch to catch and automatically add the missing
code.
Inspired-by: Peter Maydell <address@hidden>
Signed-off-by: Philippe Mathieu-Daudé <address@hidden>
---
v3: Fixed typo 'provides', let prototype return 'void' (eblake)
---
.../add-missing-error_propagate.cocci | 30 +++++++++++++++++++
MAINTAINERS | 1 +
2 files changed, 31 insertions(+)
create mode 100644 scripts/coccinelle/add-missing-error_propagate.cocci
diff --git a/scripts/coccinelle/add-missing-error_propagate.cocci
b/scripts/coccinelle/add-missing-error_propagate.cocci
new file mode 100644
index 0000000000..4b82e40418
--- /dev/null
+++ b/scripts/coccinelle/add-missing-error_propagate.cocci
@@ -0,0 +1,30 @@
+// Add missing error-propagation code where caller provides a Error* argument
+//
+// Copyright: (C) 2020 Philippe Mathieu-Daudé
+// This work is licensed under the terms of the GNU GPLv2 or later.
+//
+// spatch \
+// --macro-file scripts/cocci-macro-file.h --include-headers \
+// --sp-file scripts/coccinelle/add-missing-error_propagate.cocci \
+// --keep-comments --in-place
+//
+// Inspired by https://www.mail-archive.com/address@hidden/msg691638.html
+
+
+@ add_missing_error_propagate @
+typedef Error;
+Error *local_err;
+identifier func, errp, errfunc1, errfunc2;
+@@
+void func(..., Error **errp)
+{
+ <...
+ errfunc1(..., &local_err);
++ if (local_err) {
++ error_propagate(errp, local_err);
++ return;
++ }
+ ... when != local_err
+ errfunc2(..., &local_err);
+ ...>
+}
diff --git a/MAINTAINERS b/MAINTAINERS
index 54e05ecbdf..f996e72780 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -2054,6 +2054,7 @@ F: include/qemu/error-report.h
F: qapi/error.json
F: util/error.c
F: util/qemu-error.c
+F: scripts/coccinelle/add-missing-error_propagate.cocci
F: scripts/coccinelle/err-bad-newline.cocci
F: scripts/coccinelle/error-use-after-free.cocci
F: scripts/coccinelle/error_propagate_null.cocci
--
2.21.1
- [PATCH-for-5.1 v3 07/23] hw/riscv/sifive: Add missing error-propagation code, (continued)
- [PATCH-for-5.1 v3 07/23] hw/riscv/sifive: Add missing error-propagation code, Philippe Mathieu-Daudé, 2020/04/12
- [PATCH-for-5.1 v3 08/23] hw/arm/armv7m: Add missing error-propagation code, Philippe Mathieu-Daudé, 2020/04/12
- [PATCH-for-5.1 v3 09/23] hw/intc/arm_gicv3_its_kvm: Add missing error-propagation code, Philippe Mathieu-Daudé, 2020/04/12
- [PATCH-for-5.1 v3 11/23] hw/pci-host/pnv_phb3: Add missing error-propagation code, Philippe Mathieu-Daudé, 2020/04/12
- [PATCH-for-5.1 v3 10/23] hw/microblaze/xlnx-zynqmp-pmu: Add missing error-propagation code, Philippe Mathieu-Daudé, 2020/04/12
- [PATCH-for-5.1 v3 12/23] hw/block/onenand: Add missing error-propagation code, Philippe Mathieu-Daudé, 2020/04/12
- [PATCH-for-5.1 v3 13/23] scripts/coccinelle: Add script to catch missing error_propagate() calls,
Philippe Mathieu-Daudé <=
- [PATCH-for-5.1 v3 14/23] hw/arm/bcm2835_peripherals: Add missing error-propagation code, Philippe Mathieu-Daudé, 2020/04/12
- [PATCH-for-5.1 v3 15/23] hw/arm/fsl-imx: Add missing error-propagation code, Philippe Mathieu-Daudé, 2020/04/12
- [PATCH-for-5.1 v3 16/23] hw/arm/stm32fx05_soc: Add missing error-propagation code, Philippe Mathieu-Daudé, 2020/04/12
- [PATCH-for-5.1 v3 17/23] hw/dma/xilinx_axidma: Add missing error-propagation code, Philippe Mathieu-Daudé, 2020/04/12
- [PATCH-for-5.1 v3 18/23] hw/i386/x86: Add missing error-propagation code, Philippe Mathieu-Daudé, 2020/04/12
- [PATCH-for-5.1 v3 19/23] hw/mips/cps: Add missing error-propagation code, Philippe Mathieu-Daudé, 2020/04/12
- [PATCH-for-5.1 v3 20/23] hw/misc/macio/macio: Add missing error-propagation code, Philippe Mathieu-Daudé, 2020/04/12
- [PATCH-for-5.1 v3 21/23] hw/net/xilinx_axienet: Add missing error-propagation code, Philippe Mathieu-Daudé, 2020/04/12
- [PATCH-for-5.1 v3 22/23] hw/riscv/sifive_u: Add missing error-propagation code, Philippe Mathieu-Daudé, 2020/04/12
- [PATCH-for-5.1 v3 23/23] hw/sd/milkymist-memcard: Add missing error-propagation code, Philippe Mathieu-Daudé, 2020/04/12