qemu-e2k/hw/intc
Markus Armbruster 668f62ec62 error: Eliminate error_propagate() with Coccinelle, part 1
When all we do with an Error we receive into a local variable is
propagating to somewhere else, we can just as well receive it there
right away.  Convert

    if (!foo(..., &err)) {
        ...
        error_propagate(errp, err);
        ...
        return ...
    }

to

    if (!foo(..., errp)) {
        ...
        ...
        return ...
    }

where nothing else needs @err.  Coccinelle script:

    @rule1 forall@
    identifier fun, err, errp, lbl;
    expression list args, args2;
    binary operator op;
    constant c1, c2;
    symbol false;
    @@
         if (
    (
    -        fun(args, &err, args2)
    +        fun(args, errp, args2)
    |
    -        !fun(args, &err, args2)
    +        !fun(args, errp, args2)
    |
    -        fun(args, &err, args2) op c1
    +        fun(args, errp, args2) op c1
    )
            )
         {
             ... when != err
                 when != lbl:
                 when strict
    -        error_propagate(errp, err);
             ... when != err
    (
             return;
    |
             return c2;
    |
             return false;
    )
         }

    @rule2 forall@
    identifier fun, err, errp, lbl;
    expression list args, args2;
    expression var;
    binary operator op;
    constant c1, c2;
    symbol false;
    @@
    -    var = fun(args, &err, args2);
    +    var = fun(args, errp, args2);
         ... when != err
         if (
    (
             var
    |
             !var
    |
             var op c1
    )
            )
         {
             ... when != err
                 when != lbl:
                 when strict
    -        error_propagate(errp, err);
             ... when != err
    (
             return;
    |
             return c2;
    |
             return false;
    |
             return var;
    )
         }

    @depends on rule1 || rule2@
    identifier err;
    @@
    -    Error *err = NULL;
         ... when != err

Not exactly elegant, I'm afraid.

The "when != lbl:" is necessary to avoid transforming

         if (fun(args, &err)) {
             goto out
         }
         ...
     out:
         error_propagate(errp, err);

even though other paths to label out still need the error_propagate().
For an actual example, see sclp_realize().

Without the "when strict", Coccinelle transforms vfio_msix_setup(),
incorrectly.  I don't know what exactly "when strict" does, only that
it helps here.

The match of return is narrower than what I want, but I can't figure
out how to express "return where the operand doesn't use @err".  For
an example where it's too narrow, see vfio_intx_enable().

Silently fails to convert hw/arm/armsse.c, because Coccinelle gets
confused by ARMSSE being used both as typedef and function-like macro
there.  Converted manually.

Line breaks tidied up manually.  One nested declaration of @local_err
deleted manually.  Preexisting unwanted blank line dropped in
hw/riscv/sifive_e.c.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-Id: <20200707160613.848843-35-armbru@redhat.com>
2020-07-10 15:18:08 +02:00
..
Kconfig hw/intc: Add Loongson LIOINTC support 2020-06-27 19:42:22 +02:00
Makefile.objs hw/intc: Add Loongson LIOINTC support 2020-06-27 19:42:22 +02:00
allwinner-a10-pic.c Clean up inclusion of sysemu/sysemu.h 2019-08-16 13:31:53 +02:00
apic.c qdev: Unrealize must not fail 2020-05-15 07:08:14 +02:00
apic_common.c error: Eliminate error_propagate() with Coccinelle, part 1 2020-07-10 15:18:08 +02:00
arm_gic.c arm_gic: Mask the un-supported priority bits 2020-02-28 16:14:57 +00:00
arm_gic_common.c arm_gic: Mask the un-supported priority bits 2020-02-28 16:14:57 +00:00
arm_gic_kvm.c hw/intc/arm_gic_kvm: Don't assume kernel can provide a GICv2 2020-02-28 16:14:57 +00:00
arm_gicv2m.c qdev: set properties with device_class_set_props() 2020-01-24 20:59:15 +01:00
arm_gicv3.c Include qemu/module.h where needed, drop it from qemu-common.h 2019-06-12 13:18:33 +02:00
arm_gicv3_common.c qdev: set properties with device_class_set_props() 2020-01-24 20:59:15 +01:00
arm_gicv3_cpuif.c arm/gicv3: update virtual irq state after IAR register read 2020-01-17 14:27:16 +00:00
arm_gicv3_dist.c hw/intc/arm_gicv3: GICD_TYPER.SecurityExtn is RAZ if GICD_CTLR.DS == 1 2019-06-17 15:13:19 +01:00
arm_gicv3_its_common.c Include migration/vmstate.h less 2019-08-16 13:31:52 +02:00
arm_gicv3_its_kvm.c qdev: set properties with device_class_set_props() 2020-01-24 20:59:15 +01:00
arm_gicv3_kvm.c bugfix: Use gicr_typer in arm_gicv3_icc_reset 2020-04-30 11:52:27 +01:00
arm_gicv3_redist.c hw/intc/arm_gicv3: Fix decoding of ID register range 2019-06-17 15:13:19 +01:00
armv7m_nvic.c error: Eliminate error_propagate() with Coccinelle, part 1 2020-07-10 15:18:08 +02:00
aspeed_vic.c Include migration/vmstate.h less 2019-08-16 13:31:52 +02:00
bcm2835_ic.c hw/arm/bcm283x: Correct the license text 2020-03-23 17:22:30 +00:00
bcm2836_control.c hw/arm/bcm283x: Correct the license text 2020-03-23 17:22:30 +00:00
etraxfs_pic.c cris: improve passing PIC interrupt vector to the CPU 2020-01-07 17:24:29 +04:00
exynos4210_combiner.c qdev: set properties with device_class_set_props() 2020-01-24 20:59:15 +01:00
exynos4210_gic.c sysbus: Convert to sysbus_realize() etc. with Coccinelle 2020-06-15 22:05:28 +02:00
gic_internal.h hw/intc/arm_gic: Drop GIC_BASE_IRQ macro 2018-09-25 15:13:24 +01:00
gicv3_internal.h target-arm: Add GICv3CPUState in CPUARMState struct 2017-02-28 17:10:00 +00:00
grlib_irqmp.c leon3: use qemu_irq framework instead of callback as property 2020-01-07 17:24:29 +04:00
heathrow_pic.c Include hw/hw.h exactly where needed 2019-08-16 13:31:52 +02:00
i8259.c hw: replace hw/i386/pc.h with a header just for the i8259 2019-12-17 19:33:49 +01:00
i8259_common.c isa: Convert uses of isa_create() with Coccinelle 2020-06-15 22:05:28 +02:00
ibex_plic.c hw/intc: Initial commit of lowRISC Ibex PLIC 2020-06-19 08:24:07 -07:00
imx_avic.c Include migration/vmstate.h less 2019-08-16 13:31:52 +02:00
imx_gpcv2.c Include migration/vmstate.h less 2019-08-16 13:31:52 +02:00
intc.c intc: add an interface to gather statistics/informations on interrupt controllers 2016-10-04 10:00:25 +02:00
ioapic.c KVM: Kick resamplefd for split kernel irqchip 2020-06-10 12:10:33 -04:00
ioapic_common.c Include migration/vmstate.h less 2019-08-16 13:31:52 +02:00
lm32_pic.c Include hw/hw.h exactly where needed 2019-08-16 13:31:52 +02:00
loongson_liointc.c hw/intc: Add Loongson LIOINTC support 2020-06-27 19:42:22 +02:00
mips_gic.c qdev: set properties with device_class_set_props() 2020-01-24 20:59:15 +01:00
nios2_iic.c qom: Don't handle impossible object_property_get_link() failure 2020-07-10 15:18:08 +02:00
omap_intc.c qdev: set properties with device_class_set_props() 2020-01-24 20:59:15 +01:00
ompic.c qdev: set properties with device_class_set_props() 2020-01-24 20:59:15 +01:00
openpic.c qdev: set properties with device_class_set_props() 2020-01-24 20:59:15 +01:00
openpic_kvm.c qdev: set properties with device_class_set_props() 2020-01-24 20:59:15 +01:00
pl190.c Include migration/vmstate.h less 2019-08-16 13:31:52 +02:00
pnv_xive.c error: Eliminate error_propagate() with Coccinelle, part 1 2020-07-10 15:18:08 +02:00
pnv_xive_regs.h ppc/pnv: add a XIVE interrupt controller model for POWER9 2019-03-12 14:33:04 +11:00
puv3_intc.c hw/unicore32/puv3: Use qemu_log_mask(ERROR) instead of debug printf() 2020-06-09 19:01:56 +02:00
realview_gic.c error: Eliminate error_propagate() with Coccinelle, part 1 2020-07-10 15:18:08 +02:00
rx_icu.c hw/intc: RX62N interrupt controller (ICUa) 2020-06-22 18:37:12 +02:00
s390_flic.c sysbus: Convert to sysbus_realize() etc. with Coccinelle 2020-06-15 22:05:28 +02:00
s390_flic_kvm.c s390x: adapter routes error handling 2020-01-27 12:13:09 +01:00
sh_intc.c Include hw/hw.h exactly where needed 2019-08-16 13:31:52 +02:00
slavio_intctl.c Include migration/vmstate.h less 2019-08-16 13:31:52 +02:00
spapr_xive.c error: Eliminate error_propagate() with Coccinelle, part 1 2020-07-10 15:18:08 +02:00
spapr_xive_kvm.c spapr/xive: Deduce the SpaprXive pointer from XiveTCTX::xptr 2020-01-08 11:01:59 +11:00
trace-events xics: Rename misleading ics_simple_*() functions 2019-10-04 19:08:22 +10:00
vgic_common.h intc/gic: Extract some reusable vGIC code 2015-09-24 01:29:36 +01:00
xics.c qom: Put name parameter before value / visitor parameter 2020-07-10 15:18:08 +02:00
xics_kvm.c error: Eliminate error_propagate() with Coccinelle, part 1 2020-07-10 15:18:08 +02:00
xics_pnv.c Clean up inclusion of sysemu/sysemu.h 2019-08-16 13:31:53 +02:00
xics_spapr.c spapr: Pass the maximum number of vCPUs to the KVM interrupt controller 2019-12-17 10:39:48 +11:00
xilinx_intc.c qdev: set properties with device_class_set_props() 2020-01-24 20:59:15 +01:00
xive.c qom: Put name parameter before value / visitor parameter 2020-07-10 15:18:08 +02:00
xlnx-pmu-iomod-intc.c qdev: set properties with device_class_set_props() 2020-01-24 20:59:15 +01:00
xlnx-zynqmp-ipi.c Include migration/vmstate.h less 2019-08-16 13:31:52 +02:00