[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH-for-5.1 v2 25/54] scripts/coccinelle: Catch missing error_propaga
From: |
Philippe Mathieu-Daudé |
Subject: |
[PATCH-for-5.1 v2 25/54] scripts/coccinelle: Catch missing error_propagate() calls in realize() |
Date: |
Mon, 6 Apr 2020 19:47:14 +0200 |
In some DeviceClass::realize() while we can propagate errors
to the caller, we forgot to do so. Add a Coccinelle patch to
automatically add the missing code.
Inspired-by: Peter Maydell <address@hidden>
Signed-off-by: Philippe Mathieu-Daudé <address@hidden>
---
.../use-error_propagate-in-realize.cocci | 54 +++++++++++++++++++
MAINTAINERS | 1 +
2 files changed, 55 insertions(+)
create mode 100644 scripts/coccinelle/use-error_propagate-in-realize.cocci
diff --git a/scripts/coccinelle/use-error_propagate-in-realize.cocci
b/scripts/coccinelle/use-error_propagate-in-realize.cocci
new file mode 100644
index 0000000000..7b59277a50
--- /dev/null
+++ b/scripts/coccinelle/use-error_propagate-in-realize.cocci
@@ -0,0 +1,54 @@
+// Add missing error-propagation code in DeviceClass::realize()
+//
+// 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/use-error_abort-in-instance_init.cocci \
+// --keep-comments --timeout 60 --in-place
+//
+// Inspired by https://www.mail-archive.com/address@hidden/msg691638.html
+
+
+@ match_class_init @
+TypeInfo info;
+identifier class_initfn;
+@@
+ info.class_init = class_initfn;
+
+
+@ match_realize @
+identifier match_class_init.class_initfn;
+DeviceClass *dc;
+identifier realizefn;
+@@
+void class_initfn(...)
+{
+ ...
+ dc->realize = realizefn;
+ ...
+}
+
+
+@ propagate_in_realize @
+identifier match_realize.realizefn;
+identifier err;
+identifier errp;
+identifier func_with_errp;
+symbol error_abort, error_fatal;
+@@
+void realizefn(..., Error **errp)
+{
+ ...
+ Error *err = NULL;
+ <+...
+ func_with_errp(...,
+- \(&error_abort\|&error_fatal\));
++ &err);
++ if (err) {
++ error_propagate(errp, err);
++ return;
++ }
+ ...+>
+}
diff --git a/MAINTAINERS b/MAINTAINERS
index d06ffeddd5..7b58f02efb 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -2059,6 +2059,7 @@ F: scripts/coccinelle/error_propagate_null.cocci
F: scripts/coccinelle/remove_local_err.cocci
F: scripts/coccinelle/simplify-init-realize-error_propagate.cocci
F: scripts/coccinelle/use-error_fatal.cocci
+F: scripts/coccinelle/use-error_propagate-in-realize.cocci
GDB stub
M: Alex Bennée <address@hidden>
--
2.21.1
- [PATCH-for-5.1 v2 15/54] hw/arm/xlnx-zynqmp: Split xlnx_zynqmp_create_rpu() as init + realize, (continued)
- [PATCH-for-5.1 v2 15/54] hw/arm/xlnx-zynqmp: Split xlnx_zynqmp_create_rpu() as init + realize, Philippe Mathieu-Daudé, 2020/04/06
- [PATCH-for-5.1 v2 14/54] hw/arm/xlnx-zynqmp: Use single propagate_error() call, Philippe Mathieu-Daudé, 2020/04/06
- [PATCH-for-5.1 v2 18/54] hw/pci-host/pnv_phb3: Move some code from realize() to init(), Philippe Mathieu-Daudé, 2020/04/06
- [PATCH-for-5.1 v2 19/54] hw/riscv/sifive_e: Move some code from realize() to init(), Philippe Mathieu-Daudé, 2020/04/06
- [PATCH-for-5.1 v2 20/54] hw/riscv/sifive_u: Use single type_init(), Philippe Mathieu-Daudé, 2020/04/06
- [PATCH-for-5.1 v2 16/54] hw/arm/xlnx-zynqmp: Move some code from realize() to init(), Philippe Mathieu-Daudé, 2020/04/06
- [PATCH-for-5.1 v2 17/54] hw/microblaze/xlnx-zynqmp-pmu: Move some code from realize() to init(), Philippe Mathieu-Daudé, 2020/04/06
- [PATCH-for-5.1 v2 12/54] hw/arm/stm32f205_soc: Store MemoryRegion in STM32F205State, Philippe Mathieu-Daudé, 2020/04/06
- [PATCH-for-5.1 v2 21/54] hw/riscv/sifive_u: Move some code from realize() to init(), Philippe Mathieu-Daudé, 2020/04/06
- [PATCH-for-5.1 v2 22/54] hw/riscv/sifive_u: Store MemoryRegion in SiFiveUSoCState, Philippe Mathieu-Daudé, 2020/04/06
- [PATCH-for-5.1 v2 25/54] scripts/coccinelle: Catch missing error_propagate() calls in realize(),
Philippe Mathieu-Daudé <=
- [PATCH-for-5.1 v2 23/54] hw/riscv/sifive_u: Move some code from realize() to init(), Philippe Mathieu-Daudé, 2020/04/06
- [PATCH-for-5.1 v2 24/54] hw/riscv/sifive_u: Rename MachineClass::init(), Philippe Mathieu-Daudé, 2020/04/06
- [PATCH-for-5.1 v2 27/54] hw/arm/stm32f*05_soc: Add missing error-propagation code, Philippe Mathieu-Daudé, 2020/04/06
- [PATCH-for-5.1 v2 28/54] hw/arm/aspeed: Add missing error-propagation code, Philippe Mathieu-Daudé, 2020/04/06
- [PATCH-for-5.1 v2 26/54] hw/arm/fsl-imx: Add missing error-propagation code, Philippe Mathieu-Daudé, 2020/04/06
- [PATCH-for-5.1 v2 29/54] hw/arm/allwinner-a10: Add missing error-propagation code, Philippe Mathieu-Daudé, 2020/04/06
- [PATCH-for-5.1 v2 30/54] hw/arm/msf2-soc: Add missing error-propagation code, Philippe Mathieu-Daudé, 2020/04/06
- [PATCH-for-5.1 v2 32/54] hw/arm/armv7m: Add missing error-propagation code, Philippe Mathieu-Daudé, 2020/04/06
- [PATCH-for-5.1 v2 34/54] hw/microblaze/xlnx-zynqmp-pmu: Add missing error-propagation code, Philippe Mathieu-Daudé, 2020/04/06