Skip to contentSkip to conversation

error: auto propagated local_err

RFC Superseded Vladimir Sementsov-Ogievskiy 14 participants 215 messages Oct 11, 2019 – Dec 6, 2019 Page 1 of 3

Subsystems (14)

v5 of 11 Superseded Latest is v11 →

lore
Share & tools
lore
#0 lore raw

v5 cover error: auto propagated local_err

Hi all!

At the request of Markus: full version of errp propagation. Let's look at it. Cover as much as possible, except inserting macro invocation where it's not necessary.

It's huge, and so it's an RFC.

In v5 I've added a lot more preparation cleanups:
01-23 are preparation cleanups
01: not changed, keep Eric's r-b
02: improve commit msg [Markus], keep Eric's r-b
03: changed, only error API here, drop r-b
24 is core macro
- improve cover letter, wording and macro code style
- keep Eric's r-b
25-26: automation scripts
- commit-per-subsystem changed a lot. it's a draft, don't bother too much with it
- coccinelle: add support of error_propagate_prepend

27-126: generated patches

====

Here is a proposal of auto propagation for local_err, to not call error_propagate on every exit point, when we deal with local_err.

There are also two issues with errp:

1. error_fatal & error_append_hint/error_prepend: user can't see this additional info, because exit() happens in error_setg earlier than info is added. [Reported by Greg Kurz]

2. error_abort & error_propagate: when we wrap
error_abort by local_err+error_propagate, resulting coredump will refer to error_propagate and not to the place where error happened. (the macro itself don't fix the issue, but it allows to [3.] drop all local_err+error_propagate pattern, which will definitely fix the issue) [Reported by Kevin Wolf]

====

Generated patches split:

misc
hw/misc/ivshmem.c
hw/misc/tmp105.c
hw/misc/tmp421.c
s390x
hw/intc/s390_flic_kvm.c
hw/s390x/3270-ccw.c
hw/s390x/css-bridge.c
hw/s390x/css.c
hw/s390x/s390-skeys.c
hw/s390x/s390-virtio-ccw.c
hw/s390x/sclp.c
hw/s390x/tod-kvm.c
hw/vfio/ccw.c
target/s390x/cpu.c
tcg
exec.c
hw/arm/armv7m.c
hw/arm/smmu-common.c
hw/arm/smmuv3.c
hw/cpu/a15mpcore.c
hw/cpu/a9mpcore.c
hw/cpu/arm11mpcore.c
hw/i386/pc.c
hw/intc/nios2_iic.c
hw/mips/cps.c
hw/riscv/riscv_hart.c
hw/riscv/sifive_e.c
hw/riscv/sifive_u.c
hw/sd/milkymist-memcard.c
target/alpha/cpu.c
target/arm/cpu.c
target/arm/cpu64.c
target/cris/cpu.c
target/hppa/cpu.c
target/i386/cpu.c
target/lm32/cpu.c
target/m68k/cpu.c
target/microblaze/cpu.c
target/mips/cpu.c
target/moxie/cpu.c
target/nios2/cpu.c
target/openrisc/cpu.c
target/ppc/compat.c
target/ppc/translate_init.inc.c
target/riscv/cpu.c
target/sh4/cpu.c
target/sparc/cpu.c
target/tricore/cpu.c
target/unicore32/cpu.c
target/xtensa/cpu.c
kvm
target/ppc/kvm.c
target/s390x/cpu_models.c
xen
hw/block/dataplane/xen-block.c
hw/block/xen-block.c
hw/xen/xen-backend.c
hw/xen/xen-bus.c
hw/xen/xen-host-pci-device.c
hw/xen/xen_pt.c
hw/xen/xen_pt_config_init.c
Hosts
qga/commands-win32.c
util/oslib-posix.c
ARM Machines
hw/arm/allwinner-a10.c
hw/arm/aspeed_soc.c
hw/arm/bcm2835_peripherals.c
hw/arm/bcm2836.c
hw/arm/digic.c
hw/arm/fsl-imx25.c
hw/arm/fsl-imx31.c
hw/arm/fsl-imx6.c
hw/arm/integratorcp.c
hw/arm/msf2-soc.c
hw/arm/nrf51_soc.c
hw/arm/stm32f205_soc.c
hw/arm/virt.c
hw/arm/xlnx-versal-virt.c
hw/arm/xlnx-zynqmp.c
hw/cpu/realview_mpcore.c
hw/display/bcm2835_fb.c
hw/dma/bcm2835_dma.c
hw/dma/xilinx_axidma.c
hw/gpio/aspeed_gpio.c
hw/gpio/bcm2835_gpio.c
hw/intc/arm_gic.c
hw/intc/arm_gic_kvm.c
hw/intc/arm_gicv3.c
hw/intc/arm_gicv3_its_kvm.c
hw/intc/arm_gicv3_kvm.c
hw/intc/armv7m_nvic.c
hw/intc/realview_gic.c
hw/microblaze/xlnx-zynqmp-pmu.c
hw/misc/bcm2835_mbox.c
hw/misc/bcm2835_property.c
hw/misc/msf2-sysreg.c
hw/net/xilinx_axienet.c
hw/nvram/nrf51_nvm.c
hw/timer/aspeed_timer.c
hw/watchdog/wdt_aspeed.c
MIPS Machines
hw/core/loader-fit.c
PowerPC Machines
hw/intc/pnv_xive.c
hw/intc/xics.c
hw/intc/xics_kvm.c
hw/intc/xics_pnv.c
hw/intc/xics_spapr.c
hw/isa/pc87312.c
hw/misc/macio/macio.c
hw/ppc/e500.c
hw/ppc/mac_newworld.c
hw/ppc/pnv.c
hw/ppc/pnv_core.c
hw/ppc/pnv_homer.c
hw/ppc/pnv_lpc.c
hw/ppc/pnv_occ.c
hw/ppc/pnv_psi.c
hw/ppc/spapr.c
hw/ppc/spapr_caps.c
hw/ppc/spapr_cpu_core.c
hw/ppc/spapr_drc.c
hw/ppc/spapr_irq.c
hw/ppc/spapr_pci.c
hw/ppc/spapr_vio.c
SPARC Machines
hw/sparc/sun4m.c
hw/sparc64/sun4u.c
S390 Machines
hw/s390x/ipl.c
hw/s390x/s390-pci-bus.c
X86 Machines
hw/acpi/ich9.c
hw/char/debugcon.c
hw/char/serial-pci-multi.c
hw/char/serial-pci.c
hw/core/machine.c
hw/core/numa.c
hw/intc/apic_common.c
hw/pci-host/piix.c
IDE
hw/ide/qdev.c
Floppy
hw/block/fdc.c
IPack
hw/ipack/ipack.c
PCI
hw/pci-bridge/gen_pcie_root_port.c
hw/pci-bridge/pci_bridge_dev.c
hw/pci-bridge/pci_expander_bridge.c
hw/pci-bridge/pcie_pci_bridge.c
hw/pci-bridge/pcie_root_port.c
hw/pci/pci.c
hw/pci/pcie.c
hw/pci/shpc.c
ACPI/SMBIOS
hw/acpi/core.c
hw/acpi/cpu_hotplug.c
hw/acpi/memory_hotplug.c
hw/mem/memory-device.c
hw/mem/pc-dimm.c
hw/smbios/smbios.c
Network devices
hw/net/dp8393x.c
hw/net/ne2000-isa.c
pflash
hw/block/pflash_cfi01.c
hw/block/pflash_cfi02.c
SCSI
hw/scsi/esp-pci.c
hw/scsi/mptsas.c
hw/scsi/scsi-bus.c
hw/scsi/scsi-disk.c
hw/scsi/scsi-generic.c
hw/scsi/virtio-scsi.c
SD (Secure Card)
hw/sd/sdhci-pci.c
hw/sd/sdhci.c
USB
hw/usb/bus.c
hw/usb/ccid-card-emulated.c
hw/usb/dev-smartcard-reader.c
hw/usb/dev-storage.c
hw/usb/hcd-ohci-pci.c
hw/usb/hcd-ohci.c
hw/usb/hcd-uhci.c
hw/usb/hcd-xhci.c
USB (serial adapter)
hw/usb/dev-serial.c
VFIO
hw/vfio/common.c
hw/vfio/pci-quirks.c
hw/vfio/pci.c
hw/vfio/platform.c
vfio-ccw
hw/s390x/s390-ccw.c
vhost
hw/block/vhost-user-blk.c
hw/scsi/vhost-scsi.c
hw/scsi/vhost-user-scsi.c
hw/virtio/vhost-vsock.c
virtio
hw/virtio/virtio-balloon.c
hw/virtio/virtio-bus.c
hw/virtio/virtio-pci.c
hw/virtio/virtio-rng-pci.c
hw/virtio/virtio.c
virtio-9p
hw/9pfs/9p-local.c
hw/9pfs/9p.c
virtio-blk
hw/block/dataplane/virtio-blk.c
hw/block/virtio-blk.c
virtio-ccw
hw/s390x/virtio-ccw-crypto.c
hw/s390x/virtio-ccw-rng.c
hw/s390x/virtio-ccw.c
virtio-input
hw/input/virtio-input.c
virtio-serial
hw/char/virtio-serial-bus.c
virtio-rng
backends/rng.c
hw/virtio/virtio-rng.c
megasas
hw/scsi/megasas.c
NVDIMM
hw/mem/nvdimm.c
eepro100
hw/net/eepro100.c
virtio-gpu
hw/display/virtio-gpu-base.c
hw/display/virtio-gpu-pci.c
hw/display/virtio-vga.c
fw_cfg
hw/nvram/fw_cfg.c
XIVE
hw/intc/spapr_xive.c
hw/intc/spapr_xive_kvm.c
hw/intc/xive.c
Audio
audio/audio.c
hw/audio/intel-hda.c
block
block.c
block/backup.c
block/block-backend.c
block/commit.c
block/crypto.c
block/dirty-bitmap.c
block/io.c
block/mirror.c
block/qapi.c
block/snapshot.c
block/throttle-groups.c
block/throttle.c
block/vxhs.c
blockdev.c
blockjob.c
hw/block/onenand.c
job.c
scsi
scsi/pr-manager-helper.c
chardev
chardev/char-socket.c
chardev/char.c
chardev/spice.c
cmdline
util/qemu-option.c
Dump
dump/dump.c
dump/win_dump.c
Memory API
memory.c
SPICE
hw/display/qxl.c
Graphics
ui/input-barrier.c
ui/input.c
ui/vnc.c
Main loop
util/main-loop.c
vl.c
Human Monitor (HMP)
monitor/misc.c
net
net/can/can_host.c
net/dump.c
net/filter-buffer.c
net/filter.c
net/net.c
net/netmap.c
net/tap.c
hostmem
backends/hostmem-file.c
backends/hostmem-memfd.c
backends/hostmem.c
cryptodev
backends/cryptodev-vhost-user.c
backends/cryptodev.c
QAPI
qapi/qapi-visit-core.c
qapi/qmp-dispatch.c
qapi/string-input-visitor.c
qga
qga/commands-posix.c
QOM
hw/core/qdev-properties-system.c
hw/core/qdev-properties.c
hw/core/qdev.c
qdev-monitor.c
qom/object.c
qom/object_interfaces.c
qom/qom-qobject.c
QMP
monitor/qmp-cmds.c
SLIRP
net/slirp.c
Tracing
trace/qmp.c
TPM
hw/tpm/tpm_util.c
tpm.c
Migration
migration/migration.c
migration/ram.c
migration/rdma.c
migration/savevm.c
migration/socket.c
Cryptography
crypto/block-luks.c
crypto/secret.c
crypto/tlssession.c
I/O Channels
io/dns-resolver.c
io/net-listener.c
Sockets
util/qemu-sockets.c
colo
migration/colo.c
Record/replay
block/blkreplay.c
VMDK
block/vmdk.c
RBD
block/rbd.c
Sheepdog
block/sheepdog.c
VHDX
block/vhdx-log.c
block/vhdx.c
VDI
block/vdi.c
iSCSI
block/iscsi.c
nbd
include/block/nbd.h
block/nbd.c
nbd/client.c
nbd/server.c
NFS
block/nfs.c
SSH
block/ssh.c
CURL
block/curl.c
GLUSTER
block/gluster.c
NVMe Block Driver
block/nvme.c
Bootdevice
bootdevice.c
Quorum
block/quorum.c
blklogwrites
block/blklogwrites.c
blkverify
block/blkverify.c
parallels
block/parallels.c
qed
block/qed.c
raw
block/file-posix.c
block/file-win32.c
block/raw-format.c
qcow2
block/qcow2-bitmap.c
block/qcow2.c
qcow
block/qcow.c
blkdebug
block/blkdebug.c
vpc
block/vpc.c
vvfat
block/vvfat.c
Replication
block/replication.c
replication.c
PVRDMA
hw/rdma/vmw/pvrdma_main.c
hw/core/bus.c
hw/core/bus.c
hw/cpu/core.c
hw/cpu/core.c
hw/sd/ssi-sd.c
hw/sd/ssi-sd.c
iothread.c
iothread.c
memory_mapping.c
memory_mapping.c
target/tilegx/cpu.c
target/tilegx/cpu.c
tests/test-image-locking.c
tests/test-image-locking.c
util/qemu-config.c
util/qemu-config.c

Vladimir Sementsov-Ogievskiy (126):
hw/core/loader-fit: fix freeing errp in fit_load_fdt net/net: Clean up variable shadowing in net_client_init()
error: rename errp to errp_in where it is IN-argument
hmp: drop Error pointer indirection in hmp_handle_error
vnc: drop Error pointer indirection in vnc_client_io_error
qdev-monitor: well form error hint helpers
nbd: well form nbd_iter_channel_error errp handler
ppc: well form kvmppc_hint_smt_possible error hint helper 9pfs: well form error hint helpers
hw/core/qdev: cleanup Error ** variables
block/snapshot: rename Error ** parameter to more common errp hw/i386/amd_iommu: rename Error ** parameter to more common errp
qga: rename Error ** parameter to more common errp monitor/qmp-cmds: rename Error ** parameter to more common errp hw/s390x: rename Error ** parameter to more common errp hw/sd: rename Error ** parameter to more common errp hw/tpm: rename Error ** parameter to more common errp hw/usb: rename Error ** parameter to more common errp include/block/snapshot.h: rename Error ** parameter to more common
errp
include/qom/object.h: rename Error ** parameter to more common errp qapi/error: add (Error **errp) cleaning APIs backends/cryptodev: drop local_err from cryptodev_backend_complete() hw/vfio/ap: drop local_err from vfio_ap_realize
error: auto propagated local_err
scripts: add coccinelle script to use auto propagated errp
python: add commit-per-subsystem.py
misc: introduce ERRP_AUTO_PROPAGATE
s390x: introduce ERRP_AUTO_PROPAGATE
tcg: introduce ERRP_AUTO_PROPAGATE
kvm: introduce ERRP_AUTO_PROPAGATE
xen: introduce ERRP_AUTO_PROPAGATE
Hosts: introduce ERRP_AUTO_PROPAGATE
ARM Machines: introduce ERRP_AUTO_PROPAGATE
MIPS Machines: introduce ERRP_AUTO_PROPAGATE
PowerPC Machines: introduce ERRP_AUTO_PROPAGATE
SPARC Machines: introduce ERRP_AUTO_PROPAGATE
S390 Machines: introduce ERRP_AUTO_PROPAGATE
X86 Machines: introduce ERRP_AUTO_PROPAGATE
IDE: introduce ERRP_AUTO_PROPAGATE
Floppy: introduce ERRP_AUTO_PROPAGATE
IPack: introduce ERRP_AUTO_PROPAGATE
PCI: introduce ERRP_AUTO_PROPAGATE
ACPI/SMBIOS: introduce ERRP_AUTO_PROPAGATE
Network devices: introduce ERRP_AUTO_PROPAGATE
pflash: introduce ERRP_AUTO_PROPAGATE
SCSI: introduce ERRP_AUTO_PROPAGATE
SD (Secure Card): introduce ERRP_AUTO_PROPAGATE
USB: introduce ERRP_AUTO_PROPAGATE
USB (serial adapter): introduce ERRP_AUTO_PROPAGATE
VFIO: introduce ERRP_AUTO_PROPAGATE
vfio-ccw: introduce ERRP_AUTO_PROPAGATE
vhost: introduce ERRP_AUTO_PROPAGATE
virtio: introduce ERRP_AUTO_PROPAGATE
virtio-9p: introduce ERRP_AUTO_PROPAGATE
virtio-blk: introduce ERRP_AUTO_PROPAGATE
virtio-ccw: introduce ERRP_AUTO_PROPAGATE
virtio-input: introduce ERRP_AUTO_PROPAGATE
virtio-serial: introduce ERRP_AUTO_PROPAGATE
virtio-rng: introduce ERRP_AUTO_PROPAGATE
megasas: introduce ERRP_AUTO_PROPAGATE
NVDIMM: introduce ERRP_AUTO_PROPAGATE
eepro100: introduce ERRP_AUTO_PROPAGATE
virtio-gpu: introduce ERRP_AUTO_PROPAGATE
fw_cfg: introduce ERRP_AUTO_PROPAGATE
XIVE: introduce ERRP_AUTO_PROPAGATE
Audio: introduce ERRP_AUTO_PROPAGATE
block: introduce ERRP_AUTO_PROPAGATE
scsi: introduce ERRP_AUTO_PROPAGATE
chardev: introduce ERRP_AUTO_PROPAGATE
cmdline: introduce ERRP_AUTO_PROPAGATE
Dump: introduce ERRP_AUTO_PROPAGATE
Memory API: introduce ERRP_AUTO_PROPAGATE
SPICE: introduce ERRP_AUTO_PROPAGATE
Graphics: introduce ERRP_AUTO_PROPAGATE
Main loop: introduce ERRP_AUTO_PROPAGATE
Human Monitor (HMP): introduce ERRP_AUTO_PROPAGATE
net: introduce ERRP_AUTO_PROPAGATE
hostmem: introduce ERRP_AUTO_PROPAGATE
cryptodev: introduce ERRP_AUTO_PROPAGATE
QAPI: introduce ERRP_AUTO_PROPAGATE
qga: introduce ERRP_AUTO_PROPAGATE
QOM: introduce ERRP_AUTO_PROPAGATE
QMP: introduce ERRP_AUTO_PROPAGATE
SLIRP: introduce ERRP_AUTO_PROPAGATE
Tracing: introduce ERRP_AUTO_PROPAGATE
TPM: introduce ERRP_AUTO_PROPAGATE
Migration: introduce ERRP_AUTO_PROPAGATE
Cryptography: introduce ERRP_AUTO_PROPAGATE
I/O Channels: introduce ERRP_AUTO_PROPAGATE
Sockets: introduce ERRP_AUTO_PROPAGATE
colo: introduce ERRP_AUTO_PROPAGATE
Record/replay: introduce ERRP_AUTO_PROPAGATE
VMDK: introduce ERRP_AUTO_PROPAGATE
RBD: introduce ERRP_AUTO_PROPAGATE
Sheepdog: introduce ERRP_AUTO_PROPAGATE
VHDX: introduce ERRP_AUTO_PROPAGATE
VDI: introduce ERRP_AUTO_PROPAGATE
iSCSI: introduce ERRP_AUTO_PROPAGATE
nbd: introduce ERRP_AUTO_PROPAGATE
NFS: introduce ERRP_AUTO_PROPAGATE
SSH: introduce ERRP_AUTO_PROPAGATE
CURL: introduce ERRP_AUTO_PROPAGATE
GLUSTER: introduce ERRP_AUTO_PROPAGATE
NVMe Block Driver: introduce ERRP_AUTO_PROPAGATE
Bootdevice: introduce ERRP_AUTO_PROPAGATE
Quorum: introduce ERRP_AUTO_PROPAGATE
blklogwrites: introduce ERRP_AUTO_PROPAGATE
blkverify: introduce ERRP_AUTO_PROPAGATE
parallels: introduce ERRP_AUTO_PROPAGATE
qed: introduce ERRP_AUTO_PROPAGATE

  raw: introduce ERRP_AUTO_PROPAGATE
  qcow2: introduce ERRP_AUTO_PROPAGATE
  qcow: introduce ERRP_AUTO_PROPAGATE
  blkdebug: introduce ERRP_AUTO_PROPAGATE
  vpc: introduce ERRP_AUTO_PROPAGATE
  vvfat: introduce ERRP_AUTO_PROPAGATE
  Replication: introduce ERRP_AUTO_PROPAGATE
  PVRDMA: introduce ERRP_AUTO_PROPAGATE
  hw/core/bus.c: introduce ERRP_AUTO_PROPAGATE
  hw/cpu/core.c: introduce ERRP_AUTO_PROPAGATE
  hw/sd/ssi-sd.c: introduce ERRP_AUTO_PROPAGATE
  iothread.c: introduce ERRP_AUTO_PROPAGATE
  memory_mapping.c: introduce ERRP_AUTO_PROPAGATE
  target/tilegx/cpu.c: introduce ERRP_AUTO_PROPAGATE
  tests/test-image-locking.c: introduce ERRP_AUTO_PROPAGATE
  util/qemu-config.c: introduce ERRP_AUTO_PROPAGATE
CC Gerd Hoffmann <[email protected]>
CC "Gonglei (Arei)" <[email protected]>
CC Eduardo Habkost <[email protected]>
CC Igor Mammedov <[email protected]>
CC Laurent Vivier <[email protected]>
CC Amit Shah <[email protected]>
CC Kevin Wolf <[email protected]>
CC Max Reitz <[email protected]>
CC John Snow <[email protected]>
CC Ari Sundholm <[email protected]>
CC Pavel Dovgalyuk <[email protected]>
CC Paolo Bonzini <[email protected]>
CC Stefan Hajnoczi <[email protected]>
CC Fam Zheng <[email protected]>
CC Stefan Weil <[email protected]>
CC Ronnie Sahlberg <[email protected]>
CC Peter Lieven <[email protected]>
CC Eric Blake <[email protected]>
CC "Denis V. Lunev" <[email protected]>
CC Markus Armbruster <[email protected]>
CC Alberto Garcia <[email protected]>
CC Jason Dillaman <[email protected]>
CC Wen Congyang <[email protected]>
CC Xie Changlong <[email protected]>
CC Liu Yuan <[email protected]>
CC "Richard W.M. Jones" <[email protected]>
CC Jeff Cody <[email protected]>
CC "Marc-André Lureau" <[email protected]>
CC "Daniel P. Berrangé" <[email protected]>
CC Richard Henderson <[email protected]>
CC Greg Kurz <[email protected]>
CC "Michael S. Tsirkin" <[email protected]>
CC Marcel Apfelbaum <[email protected]>
CC Beniamino Galvani <[email protected]>
CC Peter Maydell <[email protected]>
CC "Cédric Le Goater" <[email protected]>
CC Andrew Jeffery <[email protected]>
CC Joel Stanley <[email protected]>
CC Andrew Baumann <[email protected]>
CC "Philippe Mathieu-Daudé" <[email protected]>
CC Antony Pavlov <[email protected]>
CC Jean-Christophe Dubois <[email protected]>
CC Peter Chubb <[email protected]>
CC Subbaraya Sundeep <[email protected]>
CC Eric Auger <[email protected]>
CC Alistair Francis <[email protected]>
CC "Edgar E. Iglesias" <[email protected]>
CC Stefano Stabellini <[email protected]>
CC Anthony Perard <[email protected]>
CC Paul Durrant <[email protected]>
CC Paul Burton <[email protected]>
CC Aleksandar Rikalo <[email protected]>
CC Chris Wulff <[email protected]>
CC Marek Vasut <[email protected]>
CC David Gibson <[email protected]>
CC Cornelia Huck <[email protected]>
CC Halil Pasic <[email protected]>
CC Christian Borntraeger <[email protected]>
CC "Hervé Poussineau" <[email protected]>
CC Xiao Guangrong <[email protected]>
CC Aurelien Jarno <[email protected]>
CC Aleksandar Markovic <[email protected]>
CC Mark Cave-Ayland <[email protected]>
CC Jason Wang <[email protected]>
CC Laszlo Ersek <[email protected]>
CC Yuval Shaia <[email protected]>
CC Palmer Dabbelt <[email protected]>
CC Sagar Karandikar <[email protected]>
CC Bastian Koppelmann <[email protected]>
CC David Hildenbrand <[email protected]>
CC Thomas Huth <[email protected]>
CC Eric Farman <[email protected]>
CC Matthew Rosato <[email protected]>
CC Hannes Reinecke <[email protected]>
CC Michael Walle <[email protected]>
CC Artyom Tarasenko <[email protected]>
CC Stefan Berger <[email protected]>
CC Samuel Thibault <[email protected]>
CC Alex Williamson <[email protected]>
CC Tony Krowiak <[email protected]>
CC Pierre Morel <[email protected]>
CC Michael Roth <[email protected]>
CC Hailiang Zhang <[email protected]>
CC Juan Quintela <[email protected]>
CC "Dr. David Alan Gilbert" <[email protected]>
CC Luigi Rizzo <[email protected]>
CC Giuseppe Lettieri <[email protected]>
CC Vincenzo Maffione <[email protected]>
CC Jan Kiszka <[email protected]>
CC Anthony Green <[email protected]>
CC Stafford Horne <[email protected]>
CC Guan Xuetao <[email protected]>
CC Max Filippov <[email protected]>
 include/block/nbd.h                           |   1 +
 include/block/snapshot.h                      |   2 +-
 include/monitor/hmp.h                         |   2 +-
 include/qapi/error.h                          |  69 ++++-
 include/qom/object.h                          |   4 +-
 target/ppc/kvm_ppc.h                          |   4 +-
 ui/vnc.h                                      |   2 +-
 audio/audio.c                                 |  12 +-
 backends/cryptodev-vhost-user.c               |  10 +-
 backends/cryptodev.c                          |  25 +-
 backends/hostmem-file.c                       |  21 +-
 backends/hostmem-memfd.c                      |  18 +-
 backends/hostmem.c                            |  41 ++-
 backends/rng.c                                |   7 +-
 block.c                                       | 225 +++++++---------
 block/backup.c                                |   1 +
 block/blkdebug.c                              |  36 ++-
 block/blklogwrites.c                          |  22 +-
 block/blkreplay.c                             |   7 +-
 block/blkverify.c                             |  17 +-
 block/block-backend.c                         |  19 +-
 block/commit.c                                |   7 +-
 block/crypto.c                                |  14 +-
 block/curl.c                                  |   7 +-
 block/dirty-bitmap.c                          |   1 +
 block/file-posix.c                            |  79 +++---
 block/file-win32.c                            |  29 +-
 block/gluster.c                               |  69 +++--
 block/io.c                                    |  12 +-
 block/iscsi.c                                 |  36 ++-
 block/mirror.c                                |  19 +-
 block/nbd.c                                   |  59 ++--
 block/nfs.c                                   |   7 +-
 block/nvme.c                                  |  19 +-
 block/parallels.c                             |  30 +--
 block/qapi.c                                  |  26 +-
 block/qcow.c                                  |  17 +-
 block/qcow2-bitmap.c                          |   9 +-
 block/qcow2.c                                 |  98 +++----
 block/qed.c                                   |  18 +-
 block/quorum.c                                |  23 +-
 block/raw-format.c                            |   7 +-
 block/rbd.c                                   |  29 +-
 block/replication.c                           |  40 ++-
 block/sheepdog.c                              |  73 +++--
 block/snapshot.c                              |  20 +-
 block/ssh.c                                   |  12 +-
 block/throttle-groups.c                       |  24 +-
 block/throttle.c                              |   7 +-
 block/vdi.c                                   |  15 +-
 block/vhdx-log.c                              |   1 +
 block/vhdx.c                                  |  22 +-
 block/vmdk.c                                  |  41 ++-
 block/vpc.c                                   |  28 +-
 block/vvfat.c                                 |  12 +-
 block/vxhs.c                                  |  23 +-
 blockdev.c                                    | 252 ++++++++----------
 blockjob.c                                    |   8 +-
 bootdevice.c                                  |  31 +--
 chardev/char-socket.c                         |   7 +-
 chardev/char.c                                |  20 +-
 chardev/spice.c                               |   1 +
 crypto/block-luks.c                           |  56 ++--
 crypto/secret.c                               |  17 +-
 crypto/tlssession.c                           |   7 +-
 dump/dump-hmp-cmds.c                          |   4 +-
 dump/dump.c                                   | 151 +++++------
 dump/win_dump.c                               |  29 +-
 exec.c                                        |  21 +-
 hw/9pfs/9p-local.c                            |  12 +-
 hw/9pfs/9p-proxy.c                            |   5 +-
 hw/9pfs/9p.c                                  |   1 +
 hw/acpi/core.c                                |  18 +-
 hw/acpi/cpu_hotplug.c                         |   2 +-
 hw/acpi/ich9.c                                |  30 +--
 hw/acpi/memory_hotplug.c                      |   7 +-
 hw/arm/allwinner-a10.c                        |  27 +-
 hw/arm/armv7m.c                               |  52 ++--
 hw/arm/aspeed_soc.c                           |   1 +
 hw/arm/bcm2835_peripherals.c                  |  85 +++---
 hw/arm/bcm2836.c                              |  41 ++-
 hw/arm/digic.c                                |  22 +-
 hw/arm/fsl-imx25.c                            |  62 ++---
 hw/arm/fsl-imx31.c                            |  57 ++--
 hw/arm/fsl-imx6.c                             |  81 +++---
 hw/arm/integratorcp.c                         |   7 +-
 hw/arm/msf2-soc.c                             |  22 +-
 hw/arm/nrf51_soc.c                            |  47 ++--
 hw/arm/smmu-common.c                          |   7 +-
 hw/arm/smmuv3.c                               |   7 +-
 hw/arm/stm32f205_soc.c                        |  39 ++-
 hw/arm/virt.c                                 |   2 +
 hw/arm/xlnx-versal-virt.c                     |   7 +-
 hw/arm/xlnx-zynqmp.c                          |  86 +++---
 hw/audio/intel-hda.c                          |  13 +-
 hw/block/dataplane/virtio-blk.c               |   1 +
 hw/block/dataplane/xen-block.c                |  17 +-
 hw/block/fdc.c                                |  19 +-
 hw/block/onenand.c                            |   7 +-
 hw/block/pflash_cfi01.c                       |   7 +-
 hw/block/pflash_cfi02.c                       |   7 +-
 hw/block/vhost-user-blk.c                     |   6 +-
 hw/block/virtio-blk.c                         |   7 +-
 hw/block/xen-block.c                          | 119 ++++-----
 hw/char/debugcon.c                            |   7 +-
 hw/char/serial-pci-multi.c                    |   7 +-
 hw/char/serial-pci.c                          |   7 +-
 hw/char/virtio-serial-bus.c                   |   7 +-
 hw/core/bus.c                                 |  15 +-
 hw/core/loader-fit.c                          |   7 +-
 hw/core/machine-hmp-cmds.c                    |   6 +-
 hw/core/machine.c                             |  21 +-
 hw/core/numa.c                                |  51 ++--
 hw/core/qdev-properties-system.c              |  28 +-
 hw/core/qdev-properties.c                     |  89 +++----
 hw/core/qdev.c                                |  58 ++--
 hw/cpu/a15mpcore.c                            |   7 +-
 hw/cpu/a9mpcore.c                             |  27 +-
 hw/cpu/arm11mpcore.c                          |  22 +-
 hw/cpu/core.c                                 |  14 +-
 hw/cpu/realview_mpcore.c                      |  12 +-
 hw/display/bcm2835_fb.c                       |   6 +-
 hw/display/qxl.c                              |   7 +-
 hw/display/virtio-gpu-base.c                  |   7 +-
 hw/display/virtio-gpu-pci.c                   |   7 +-
 hw/display/virtio-vga.c                       |   7 +-
 hw/dma/bcm2835_dma.c                          |   6 +-
 hw/dma/xilinx_axidma.c                        |  22 +-
 hw/gpio/aspeed_gpio.c                         |   7 +-
 hw/gpio/bcm2835_gpio.c                        |  10 +-
 hw/i386/amd_iommu.c                           |  14 +-
 hw/i386/pc.c                                  | 120 ++++-----
 hw/ide/qdev.c                                 |  16 +-
 hw/input/virtio-input.c                       |  14 +-
 hw/intc/apic_common.c                         |   7 +-
 hw/intc/arm_gic.c                             |   7 +-
 hw/intc/arm_gic_kvm.c                         |  12 +-
 hw/intc/arm_gicv3.c                           |  12 +-
 hw/intc/arm_gicv3_its_kvm.c                   |   7 +-
 hw/intc/arm_gicv3_kvm.c                       |  17 +-
 hw/intc/armv7m_nvic.c                         |  12 +-
 hw/intc/nios2_iic.c                           |   6 +-
 hw/intc/pnv_xive.c                            |  15 +-
 hw/intc/realview_gic.c                        |   7 +-
 hw/intc/s390_flic_kvm.c                       |   9 +-
 hw/intc/spapr_xive.c                          |  12 +-
 hw/intc/spapr_xive_kvm.c                      |  55 ++--
 hw/intc/xics.c                                |  28 +-
 hw/intc/xics_kvm.c                            |  30 +--
 hw/intc/xics_pnv.c                            |   7 +-
 hw/intc/xics_spapr.c                          |   7 +-
 hw/intc/xive.c                                |  27 +-
 hw/ipack/ipack.c                              |   5 +-
 hw/isa/pc87312.c                              |   7 +-
 hw/mem/memory-device.c                        |  20 +-
 hw/mem/nvdimm.c                               |  25 +-
 hw/mem/pc-dimm.c                              |  23 +-
 hw/microblaze/xlnx-zynqmp-pmu.c               |  12 +-
 hw/mips/cps.c                                 |  46 ++--
 hw/misc/bcm2835_mbox.c                        |   6 +-
 hw/misc/bcm2835_property.c                    |  10 +-
 hw/misc/ivshmem.c                             |  37 ++-
 hw/misc/macio/macio.c                         |  68 ++---
 hw/misc/msf2-sysreg.c                         |   1 +
 hw/misc/tmp105.c                              |   7 +-
 hw/misc/tmp421.c                              |   7 +-
 hw/net/dp8393x.c                              |   7 +-
 hw/net/eepro100.c                             |   7 +-
 hw/net/ne2000-isa.c                           |  17 +-
 hw/net/xilinx_axienet.c                       |  22 +-
 hw/nvram/fw_cfg.c                             |  14 +-
 hw/nvram/nrf51_nvm.c                          |   7 +-
 hw/pci-bridge/gen_pcie_root_port.c            |   7 +-
 hw/pci-bridge/pci_bridge_dev.c                |  13 +-
 hw/pci-bridge/pci_expander_bridge.c           |   7 +-
 hw/pci-bridge/pcie_pci_bridge.c               |   8 +-
 hw/pci-bridge/pcie_root_port.c                |   1 +
 hw/pci-host/piix.c                            |   7 +-
 hw/pci/pci.c                                  |  19 +-
 hw/pci/pcie.c                                 |   7 +-
 hw/pci/shpc.c                                 |  14 +-
 hw/ppc/e500.c                                 |   7 +-
 hw/ppc/mac_newworld.c                         |   1 +
 hw/ppc/pnv.c                                  | 109 ++++----
 hw/ppc/pnv_core.c                             |  23 +-
 hw/ppc/pnv_homer.c                            |   5 +-
 hw/ppc/pnv_lpc.c                              |  26 +-
 hw/ppc/pnv_occ.c                              |   5 +-
 hw/ppc/pnv_psi.c                              |  23 +-
 hw/ppc/spapr.c                                | 133 ++++-----
 hw/ppc/spapr_caps.c                           |  57 ++--
 hw/ppc/spapr_cpu_core.c                       |  36 ++-
 hw/ppc/spapr_drc.c                            |  48 ++--
 hw/ppc/spapr_irq.c                            |  98 +++----
 hw/ppc/spapr_pci.c                            |  97 +++----
 hw/ppc/spapr_vio.c                            |  12 +-
 hw/rdma/vmw/pvrdma_main.c                     |   1 +
 hw/riscv/riscv_hart.c                         |   7 +-
 hw/riscv/sifive_e.c                           |   7 +-
 hw/riscv/sifive_u.c                           |  11 +-
 hw/s390x/3270-ccw.c                           |  13 +-
 hw/s390x/css-bridge.c                         |   7 +-
 hw/s390x/css.c                                |   7 +-
 hw/s390x/event-facility.c                     |   2 +-
 hw/s390x/ipl.c                                |  24 +-
 hw/s390x/s390-ccw.c                           |  19 +-
 hw/s390x/s390-pci-bus.c                       |  37 ++-
 hw/s390x/s390-skeys.c                         |   7 +-
 hw/s390x/s390-stattrib.c                      |   3 +-
 hw/s390x/s390-virtio-ccw.c                    |  11 +-
 hw/s390x/sclp.c                               |  15 +-
 hw/s390x/tod-kvm.c                            |  14 +-
 hw/s390x/virtio-ccw-crypto.c                  |   7 +-
 hw/s390x/virtio-ccw-rng.c                     |   7 +-
 hw/s390x/virtio-ccw.c                         |  13 +-
 hw/scsi/esp-pci.c                             |   7 +-
 hw/scsi/megasas.c                             |  11 +-
 hw/scsi/mptsas.c                              |  13 +-
 hw/scsi/scsi-bus.c                            |  24 +-
 hw/scsi/scsi-disk.c                           |   8 +-
 hw/scsi/scsi-generic.c                        |   1 +
 hw/scsi/vhost-scsi.c                          |  12 +-
 hw/scsi/vhost-user-scsi.c                     |   7 +-
 hw/scsi/virtio-scsi.c                         |   7 +-
 hw/sd/milkymist-memcard.c                     |  11 +-
 hw/sd/sdhci-pci.c                             |   7 +-
 hw/sd/sdhci.c                                 |  23 +-
 hw/sd/ssi-sd.c                                |  14 +-
 hw/smbios/smbios.c                            |  42 ++-
 hw/sparc/sun4m.c                              |  21 +-
 hw/sparc64/sun4u.c                            |   7 +-
 hw/timer/aspeed_timer.c                       |   6 +-
 hw/tpm/tpm_emulator.c                         |   8 +-
 hw/tpm/tpm_util.c                             |   7 +-
 hw/usb/bus.c                                  |  37 ++-
 hw/usb/ccid-card-emulated.c                   |   1 +
 hw/usb/dev-network.c                          |   2 +-
 hw/usb/dev-serial.c                           |   7 +-
 hw/usb/dev-smartcard-reader.c                 |  14 +-
 hw/usb/dev-storage.c                          |  17 +-
 hw/usb/hcd-ohci-pci.c                         |   7 +-
 hw/usb/hcd-ohci.c                             |  14 +-
 hw/usb/hcd-uhci.c                             |   7 +-
 hw/usb/hcd-xhci.c                             |  13 +-
 hw/vfio/ap.c                                  |  16 +-
 hw/vfio/ccw.c                                 |  24 +-
 hw/vfio/common.c                              |   3 +
 hw/vfio/pci-quirks.c                          |   8 +-
 hw/vfio/pci.c                                 |  42 ++-
 hw/vfio/platform.c                            |   1 +
 hw/virtio/vhost-vsock.c                       |   1 +
 hw/virtio/virtio-balloon.c                    |  35 ++-
 hw/virtio/virtio-bus.c                        |  17 +-
 hw/virtio/virtio-pci.c                        |   2 +
 hw/virtio/virtio-rng-pci.c                    |   7 +-
 hw/virtio/virtio-rng.c                        |   7 +-
 hw/virtio/virtio.c                            |  19 +-
 hw/watchdog/wdt_aspeed.c                      |   5 +-
 hw/xen/xen-backend.c                          |   7 +-
 hw/xen/xen-bus.c                              |  92 +++----
 hw/xen/xen-host-pci-device.c                  |  27 +-
 hw/xen/xen_pt.c                               |  25 +-
 hw/xen/xen_pt_config_init.c                   |  20 +-
 io/dns-resolver.c                             |   7 +-
 io/net-listener.c                             |   7 +-
 iothread.c                                    |  27 +-
 job.c                                         |   7 +-
 memory.c                                      |  63 ++---
 memory_mapping.c                              |   7 +-
 migration/colo.c                              |  38 ++-
 migration/migration.c                         |  39 ++-
 migration/ram.c                               |  13 +-
 migration/rdma.c                              |  13 +-
 migration/savevm.c                            |   2 +
 migration/socket.c                            |  18 +-
 monitor/hmp-cmds.c                            | 155 ++++++-----
 monitor/misc.c                                |   9 +-
 monitor/qmp-cmds.c                            |   9 +-
 nbd/client.c                                  |   5 +
 nbd/server.c                                  |   5 +
 net/can/can_host.c                            |   7 +-
 net/dump.c                                    |  15 +-
 net/filter-buffer.c                           |  15 +-
 net/filter.c                                  |   7 +-
 net/net.c                                     |  58 ++--
 net/netmap.c                                  |   7 +-
 net/slirp.c                                   |   7 +-
 net/tap.c                                     |  47 ++--
 qapi/qapi-visit-core.c                        |  56 ++--
 qapi/qmp-dispatch.c                           |   7 +-
 qapi/string-input-visitor.c                   |   7 +-
 qdev-monitor.c                                |  69 +++--
 qga/commands-posix.c                          | 222 +++++++--------
 qga/commands-win32.c                          | 141 +++++-----
 qga/commands.c                                |  12 +-
 qom/object.c                                  | 246 ++++++++---------
 qom/object_interfaces.c                       |  27 +-
 qom/qom-hmp-cmds.c                            |   4 +-
 qom/qom-qobject.c                             |   7 +-
 replication.c                                 |  28 +-
 scsi/pr-manager-helper.c                      |   7 +-
 target/alpha/cpu.c                            |   7 +-
 target/arm/cpu.c                              |   7 +-
 target/arm/cpu64.c                            |  11 +-
 target/cris/cpu.c                             |   7 +-
 target/hppa/cpu.c                             |   7 +-
 target/i386/cpu.c                             | 117 ++++----
 target/lm32/cpu.c                             |   7 +-
 target/m68k/cpu.c                             |   7 +-
 target/microblaze/cpu.c                       |   7 +-
 target/mips/cpu.c                             |   7 +-
 target/moxie/cpu.c                            |   7 +-
 target/nios2/cpu.c                            |   7 +-
 target/openrisc/cpu.c                         |   7 +-
 target/ppc/compat.c                           |  20 +-
 target/ppc/kvm.c                              |  14 +-
 target/ppc/translate_init.inc.c               |  26 +-
 target/riscv/cpu.c                            |   7 +-
 target/s390x/cpu.c                            |  26 +-
 target/s390x/cpu_models.c                     |   2 +
 target/sh4/cpu.c                              |   7 +-
 target/sparc/cpu.c                            |  14 +-
 target/tilegx/cpu.c                           |   7 +-
 target/tricore/cpu.c                          |   7 +-
 target/unicore32/cpu.c                        |   7 +-
 target/xtensa/cpu.c                           |   7 +-
 tests/test-image-locking.c                    |   7 +-
 tpm.c                                         |   7 +-
 trace/qmp.c                                   |  14 +-
 ui/input-barrier.c                            |   7 +-
 ui/input.c                                    |  14 +-
 ui/vnc.c                                      |  39 ++-
 util/error.c                                  |  30 +--
 util/main-loop.c                              |   5 +-
 util/oslib-posix.c                            |   6 +-
 util/qemu-config.c                            |  29 +-
 util/qemu-option.c                            |  59 ++--
 util/qemu-sockets.c                           |  31 +--
 vl.c                                          |  14 +-
 python/commit-per-subsystem.py                | 204 ++++++++++++++
 scripts/coccinelle/auto-propagated-errp.cocci | 118 ++++++++
 341 files changed, 3851 insertions(+), 4455 deletions(-)
 create mode 100755 python/commit-per-subsystem.py
 create mode 100644 scripts/coccinelle/auto-propagated-errp.cocci
Signature · 1 line
2.21.0
#1 lore raw

RFC v5 1/126 hw/core/loader-fit: fix freeing errp in fit_load_fdt

fit_load_fdt forget to check that errp is not NULL and to zero it after freeing. Fix it.

---
 hw/core/loader-fit.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
hw/core/loader-fit.c +4 -1
index 953b16bc82..3ee9fb2f2e 100644
@@ -200,7 +200,10 @@ static int fit_load_fdt(const struct fit_loader *ldr, const void *itb,
     err = fit_image_addr(itb, img_off, "load", &load_addr, errp);
     if (err == -ENOENT) {
         load_addr = ROUND_UP(kernel_end, 64 * KiB) + (10 * MiB);
-        error_free(*errp);
+        if (errp) {
+            error_free(*errp);
+            *errp = NULL;
+        }
     } else if (err) {
         error_prepend(errp, "unable to read FDT load address from FIT: ");
         ret = err;
Signature · 1 line
2.21.0
#2 lore raw

RFC v5 2/126 net/net: Clean up variable shadowing in net_client_init()

In reply to Vladimir Sementsov-Ogievskiy

Variable int err in inner scope shadows Error *err in outer scope.

---
 net/net.c | 17 +++++++----------
 1 file changed, 7 insertions(+), 10 deletions(-)
net/net.c +7 -10
index 84aa6d8d00..9e93c3f8a1 100644
@@ -1126,16 +1126,13 @@ static int net_client_init(QemuOpts *opts, bool is_netdev, Error **errp)
 
             prefix_addr = substrings[0];
 
-            if (substrings[1]) {
-                /* User-specified prefix length.  */
-                int err;
-
-                err = qemu_strtoul(substrings[1], NULL, 10, &prefix_len);
-                if (err) {
-                    error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
-                               "ipv6-prefixlen", "a number");
-                    goto out;
-                }
+            /* Handle user-specified prefix length. */
+            if (substrings[1] &&
+                qemu_strtoul(substrings[1], NULL, 10, &prefix_len))
+            {
+                error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
+                           "ipv6-prefixlen", "a number");
+                goto out;
             }
 
             qemu_opt_set(opts, "ipv6-prefix", prefix_addr, &error_abort);
Signature · 1 line
2.21.0
Reviewed-by on v5 2/126
#3 lore raw

Re: [RFC v5 002/126] net/net: Clean up variable shadowing in net_client_init()

Quoted 27 lines · Vladimir Sementsov-Ogievskiy

Variable int err in inner scope shadows Error *err in outer scope.

---
  net/net.c | 17 +++++++----------
  1 file changed, 7 insertions(+), 10 deletions(-)
net/net.c +0 -10
index 84aa6d8d00..9e93c3f8a1 100644
@@ -1126,16 +1126,13 @@ static int net_client_init(QemuOpts *opts, bool is_netdev, Error **errp)
 
              prefix_addr = substrings[0];
 
-            if (substrings[1]) {
-                /* User-specified prefix length.  */
-                int err;
-
-                err = qemu_strtoul(substrings[1], NULL, 10, &prefix_len);
-                if (err) {
-                    error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
-                               "ipv6-prefixlen", "a number");
-                    goto out;
-                }

net/net.c static int net_client_init(QemuOpts *opts, bool is_netdev, Error **errp) · line 1138

Quoted 10 lines
net/net.c +7 -0
+            /* Handle user-specified prefix length. */
+            if (substrings[1] &&
+                qemu_strtoul(substrings[1], NULL, 10, &prefix_len))
+            {
+                error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
+                           "ipv6-prefixlen", "a number");
+                goto out;
              }
 
              qemu_opt_set(opts, "ipv6-prefix", prefix_addr, &error_abort);
#4 lore raw

RFC v5 3/126 error: rename errp to errp_in where it is IN-argument

In reply to Vladimir Sementsov-Ogievskiy

Error **errp is almost always OUT-argument: it's assumed to be NULL, or pointer to NULL-initialized pointer, or pointer to error_abort or error_fatal, for callee to report error.

But very few functions instead get Error **errp as IN-argument:
it's assumed to be set (or, maybe, NULL), and callee should clean it, or add some information.

In such cases, rename errp to errp_in.

This patch updates only error API functions. There still a few functions with errp-in semantics, they will be updated in further commits.

---
 include/qapi/error.h |  8 ++++----
 util/error.c         | 30 +++++++++++++++---------------
 2 files changed, 19 insertions(+), 19 deletions(-)
include/qapi/error.h +4 -4
index 3f95141a01..12532bdf69 100644
@@ -233,13 +233,13 @@ void error_propagate_prepend(Error **dst_errp, Error *local_err,
  * Prepend some text to @errp's human-readable error message.
  * The text is made by formatting @fmt, @ap like vprintf().
  */
-void error_vprepend(Error **errp, const char *fmt, va_list ap);
+void error_vprepend(Error **errp_in, const char *fmt, va_list ap);
 
 /*
  * Prepend some text to @errp's human-readable error message.
  * The text is made by formatting @fmt, ... like printf().
  */
-void error_prepend(Error **errp, const char *fmt, ...)
+void error_prepend(Error **errp_in, const char *fmt, ...)
     GCC_FMT_ATTR(2, 3);
 
 /*
@@ -256,7 +256,7 @@ void error_prepend(Error **errp, const char *fmt, ...)
  * May be called multiple times.  The resulting hint should end with a
  * newline.
  */
-void error_append_hint(Error **errp, const char *fmt, ...)
+void error_append_hint(Error **errp_in, const char *fmt, ...)
     GCC_FMT_ATTR(2, 3);
 
 /*
@@ -283,7 +283,7 @@ void error_free(Error *err);
 /*
  * Convenience function to assert that *@errp is set, then silently free it.
  */
-void error_free_or_abort(Error **errp);
+void error_free_or_abort(Error **errp_in);
 
 /*
  * Convenience function to warn_report() and free @err.
util/error.c +15 -15
index d4532ce318..275586faa8 100644
@@ -121,41 +121,41 @@ void error_setg_file_open_internal(Error **errp,
                               "Could not open '%s'", filename);
 }
 
-void error_vprepend(Error **errp, const char *fmt, va_list ap)
+void error_vprepend(Error **errp_in, const char *fmt, va_list ap)
 {
     GString *newmsg;
 
-    if (!errp) {
+    if (!errp_in) {
         return;
     }
 
     newmsg = g_string_new(NULL);
     g_string_vprintf(newmsg, fmt, ap);
-    g_string_append(newmsg, (*errp)->msg);
-    g_free((*errp)->msg);
-    (*errp)->msg = g_string_free(newmsg, 0);
+    g_string_append(newmsg, (*errp_in)->msg);
+    g_free((*errp_in)->msg);
+    (*errp_in)->msg = g_string_free(newmsg, 0);
 }
 
-void error_prepend(Error **errp, const char *fmt, ...)
+void error_prepend(Error **errp_in, const char *fmt, ...)
 {
     va_list ap;
 
     va_start(ap, fmt);
-    error_vprepend(errp, fmt, ap);
+    error_vprepend(errp_in, fmt, ap);
     va_end(ap);
 }
 
-void error_append_hint(Error **errp, const char *fmt, ...)
+void error_append_hint(Error **errp_in, const char *fmt, ...)
 {
     va_list ap;
     int saved_errno = errno;
     Error *err;
 
-    if (!errp) {
+    if (!errp_in) {
         return;
     }
-    err = *errp;
-    assert(err && errp != &error_abort && errp != &error_fatal);
+    err = *errp_in;
+    assert(err && errp_in != &error_abort && errp_in != &error_fatal);
 
     if (!err->hint) {
         err->hint = g_string_new(NULL);
@@ -271,11 +271,11 @@ void error_free(Error *err)
     }
 }
 
-void error_free_or_abort(Error **errp)
+void error_free_or_abort(Error **errp_in)
 {
-    assert(errp && *errp);
-    error_free(*errp);
-    *errp = NULL;
+    assert(errp_in && *errp_in);
+    error_free(*errp_in);
+    *errp_in = NULL;
 }
 
 void error_propagate(Error **dst_errp, Error *local_err)
Signature · 1 line
2.21.0
Reviewed-by on v5 3/126
#5 lore raw

Re: [RFC v5 003/126] error: rename errp to errp_in where it is IN-argument

Quoted 23 lines · Vladimir Sementsov-Ogievskiy

Error **errp is almost always OUT-argument: it's assumed to be NULL, or pointer to NULL-initialized pointer, or pointer to error_abort or error_fatal, for callee to report error.

But very few functions instead get Error **errp as IN-argument:
it's assumed to be set (or, maybe, NULL), and callee should clean it, or add some information.

In such cases, rename errp to errp_in.

This patch updates only error API functions. There still a few functions with errp-in semantics, they will be updated in further commits.

---
  include/qapi/error.h |  8 ++++----
  util/error.c         | 30 +++++++++++++++---------------
  2 files changed, 19 insertions(+), 19 deletions(-)

+++ b/include/qapi/error.h

include/qapi/error.h void error_propagate_prepend(Error **dst_errp, Error *local_err, · line 236

Quoted 5 lines
include/qapi/error.h +1 -1
@@ -233,13 +233,13 @@ void error_propagate_prepend(Error **dst_errp, Error *local_err,
   * Prepend some text to @errp's human-readable error message.
   * The text is made by formatting @fmt, @ap like vprintf().
   */
-void error_vprepend(Error **errp, const char *fmt, va_list ap);
+void error_vprepend(Error **errp_in, const char *fmt, va_list ap);

Fails to update the comment.

include/qapi/error.h void error_propagate_prepend(Error **dst_errp, Error *local_err, · line 242

Quoted 7 lines
include/qapi/error.h +1 -1
  /*
   * Prepend some text to @errp's human-readable error message.
   * The text is made by formatting @fmt, ... like printf().
   */
-void error_prepend(Error **errp, const char *fmt, ...)
+void error_prepend(Error **errp_in, const char *fmt, ...)

and again

Quoted 13 lines
include/qapi/error.h +1 -1
      GCC_FMT_ATTR(2, 3);
 
  /*
@@ -256,7 +256,7 @@ void error_prepend(Error **errp, const char *fmt, ...)
   * May be called multiple times.  The resulting hint should end with a
   * newline.
   */
-void error_append_hint(Error **errp, const char *fmt, ...)
+void error_append_hint(Error **errp_in, const char *fmt, ...)
      GCC_FMT_ATTR(2, 3);
 
  /*

include/qapi/error.h void error_free(Error *err); · line 286

Quoted 5 lines
include/qapi/error.h +1 -1
@@ -283,7 +283,7 @@ void error_free(Error *err);
  /*
   * Convenience function to assert that *@errp is set, then silently free it.
   */
-void error_free_or_abort(Error **errp);
+void error_free_or_abort(Error **errp_in);

and again.

Otherwise makes sense; if matching comments are the only things changed,

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org
#6 lore raw

RFC v5 4/126 hmp: drop Error pointer indirection in hmp_handle_error

In reply to Vladimir Sementsov-Ogievskiy

We don't need Error **, as all callers pass local Error object, which isn't used after the call. Use Error * instead.

---
 include/monitor/hmp.h      |   2 +-
 dump/dump-hmp-cmds.c       |   4 +-
 hw/core/machine-hmp-cmds.c |   6 +-
 monitor/hmp-cmds.c         | 155 ++++++++++++++++++-------------------
 qdev-monitor.c             |   4 +-
 qom/qom-hmp-cmds.c         |   4 +-
 6 files changed, 87 insertions(+), 88 deletions(-)
include/monitor/hmp.h +1 -1
index a0e9511440..3d329853b2 100644
@@ -16,7 +16,7 @@
 
 #include "qemu/readline.h"
 
-void hmp_handle_error(Monitor *mon, Error **errp);
+void hmp_handle_error(Monitor *mon, Error *err);
 
 void hmp_info_name(Monitor *mon, const QDict *qdict);
 void hmp_info_version(Monitor *mon, const QDict *qdict);
dump/dump-hmp-cmds.c +2 -2
index 3dbf44372c..e5053b04cd 100644
@@ -32,7 +32,7 @@ void hmp_dump_guest_memory(Monitor *mon, const QDict *qdict)
 
     if (zlib + lzo + snappy + win_dmp > 1) {
         error_setg(&err, "only one of '-z|-l|-s|-w' can be set");
-        hmp_handle_error(mon, &err);
+        hmp_handle_error(mon, err);
         return;
     }
 
@@ -66,7 +66,7 @@ void hmp_dump_guest_memory(Monitor *mon, const QDict *qdict)
 
     qmp_dump_guest_memory(paging, prot, true, detach, has_begin, begin,
                           has_length, length, true, dump_format, &err);
-    hmp_handle_error(mon, &err);
+    hmp_handle_error(mon, err);
     g_free(prot);
 }
 
hw/core/machine-hmp-cmds.c +3 -3
index cd970cc4c5..b76f7223af 100644
@@ -55,7 +55,7 @@ void hmp_cpu_add(Monitor *mon, const QDict *qdict)
 
     cpuid = qdict_get_int(qdict, "id");
     qmp_cpu_add(cpuid, &err);
-    hmp_handle_error(mon, &err);
+    hmp_handle_error(mon, err);
 }
 
 void hmp_hotpluggable_cpus(Monitor *mon, const QDict *qdict)
@@ -66,7 +66,7 @@ void hmp_hotpluggable_cpus(Monitor *mon, const QDict *qdict)
     CpuInstanceProperties *c;
 
     if (err != NULL) {
-        hmp_handle_error(mon, &err);
+        hmp_handle_error(mon, err);
         return;
     }
 
@@ -135,7 +135,7 @@ void hmp_info_memdev(Monitor *mon, const QDict *qdict)
     monitor_printf(mon, "\n");
 
     qapi_free_MemdevList(memdev_list);
-    hmp_handle_error(mon, &err);
+    hmp_handle_error(mon, err);
 }
 
 void hmp_info_numa(Monitor *mon, const QDict *qdict)
monitor/hmp-cmds.c +77 -78

599 lines not on this page · raw message

qdev-monitor.c +2 -2
index 148df9cacf..85b58620d1 100644
@@ -857,7 +857,7 @@ void hmp_device_add(Monitor *mon, const QDict *qdict)
     Error *err = NULL;
 
     qmp_device_add((QDict *)qdict, NULL, &err);
-    hmp_handle_error(mon, &err);
+    hmp_handle_error(mon, err);
 }
 
 void hmp_device_del(Monitor *mon, const QDict *qdict)
@@ -866,7 +866,7 @@ void hmp_device_del(Monitor *mon, const QDict *qdict)
     Error *err = NULL;
 
     qmp_device_del(id, &err);
-    hmp_handle_error(mon, &err);
+    hmp_handle_error(mon, err);
 }
 
 BlockBackend *blk_by_qdev_id(const char *id, Error **errp)
qom/qom-hmp-cmds.c +2 -2
index a268e01eb4..cd08233a4c 100644
@@ -37,7 +37,7 @@ void hmp_qom_list(Monitor *mon, const QDict *qdict)
         }
         qapi_free_ObjectPropertyInfoList(start);
     }
-    hmp_handle_error(mon, &err);
+    hmp_handle_error(mon, err);
 }
 
 void hmp_qom_set(Monitor *mon, const QDict *qdict)
@@ -59,7 +59,7 @@ void hmp_qom_set(Monitor *mon, const QDict *qdict)
         }
         object_property_parse(obj, value, property, &err);
     }
-    hmp_handle_error(mon, &err);
+    hmp_handle_error(mon, err);
 }
 
 typedef struct QOMCompositionState {
Signature · 1 line
2.21.0
Acked-by on v5 4/126
#7 lore raw

Re: [RFC v5 004/126] hmp: drop Error pointer indirection in hmp_handle_error

Quoted 4 lines · * Vladimir Sementsov-Ogievskiy ([email protected]) wrote:

We don't need Error **, as all callers pass local Error object, which isn't used after the call. Use Error * instead.

for HMP

Quoted 797 lines
---
 include/monitor/hmp.h      |   2 +-
 dump/dump-hmp-cmds.c       |   4 +-
 hw/core/machine-hmp-cmds.c |   6 +-
 monitor/hmp-cmds.c         | 155 ++++++++++++++++++-------------------
 qdev-monitor.c             |   4 +-
 qom/qom-hmp-cmds.c         |   4 +-
 6 files changed, 87 insertions(+), 88 deletions(-)
include/monitor/hmp.h +1 -1
index a0e9511440..3d329853b2 100644
@@ -16,7 +16,7 @@
 
 #include "qemu/readline.h"
 
-void hmp_handle_error(Monitor *mon, Error **errp);
+void hmp_handle_error(Monitor *mon, Error *err);
 
 void hmp_info_name(Monitor *mon, const QDict *qdict);
 void hmp_info_version(Monitor *mon, const QDict *qdict);
dump/dump-hmp-cmds.c +2 -2
index 3dbf44372c..e5053b04cd 100644
@@ -32,7 +32,7 @@ void hmp_dump_guest_memory(Monitor *mon, const QDict *qdict)
 
     if (zlib + lzo + snappy + win_dmp > 1) {
         error_setg(&err, "only one of '-z|-l|-s|-w' can be set");
-        hmp_handle_error(mon, &err);
+        hmp_handle_error(mon, err);
         return;
     }
 
@@ -66,7 +66,7 @@ void hmp_dump_guest_memory(Monitor *mon, const QDict *qdict)
 
     qmp_dump_guest_memory(paging, prot, true, detach, has_begin, begin,
                           has_length, length, true, dump_format, &err);
-    hmp_handle_error(mon, &err);
+    hmp_handle_error(mon, err);
     g_free(prot);
 }
 
hw/core/machine-hmp-cmds.c +3 -3
index cd970cc4c5..b76f7223af 100644
@@ -55,7 +55,7 @@ void hmp_cpu_add(Monitor *mon, const QDict *qdict)
 
     cpuid = qdict_get_int(qdict, "id");
     qmp_cpu_add(cpuid, &err);
-    hmp_handle_error(mon, &err);
+    hmp_handle_error(mon, err);
 }
 
 void hmp_hotpluggable_cpus(Monitor *mon, const QDict *qdict)
@@ -66,7 +66,7 @@ void hmp_hotpluggable_cpus(Monitor *mon, const QDict *qdict)
     CpuInstanceProperties *c;
 
     if (err != NULL) {
-        hmp_handle_error(mon, &err);
+        hmp_handle_error(mon, err);
         return;
     }
 
@@ -135,7 +135,7 @@ void hmp_info_memdev(Monitor *mon, const QDict *qdict)
     monitor_printf(mon, "\n");
 
     qapi_free_MemdevList(memdev_list);
-    hmp_handle_error(mon, &err);
+    hmp_handle_error(mon, err);
 }
 
 void hmp_info_numa(Monitor *mon, const QDict *qdict)
monitor/hmp-cmds.c +77 -78
index b2551c16d1..c5dea307b6 100644
@@ -60,11 +60,10 @@
 #include <spice/enums.h>
 #endif
 
-void hmp_handle_error(Monitor *mon, Error **errp)
+void hmp_handle_error(Monitor *mon, Error *err)
 {
-    assert(errp);
-    if (*errp) {
-        error_reportf_err(*errp, "Error: ");
+    if (err) {
+        error_reportf_err(err, "Error: ");
     }
 }
 
@@ -734,7 +733,7 @@ void hmp_info_vnc(Monitor *mon, const QDict *qdict)
 
     info2l = qmp_query_vnc_servers(&err);
     if (err) {
-        hmp_handle_error(mon, &err);
+        hmp_handle_error(mon, err);
         return;
     }
     if (!info2l) {
@@ -850,7 +849,7 @@ void hmp_info_balloon(Monitor *mon, const QDict *qdict)
 
     info = qmp_query_balloon(&err);
     if (err) {
-        hmp_handle_error(mon, &err);
+        hmp_handle_error(mon, err);
         return;
     }
 
@@ -1172,7 +1171,7 @@ void hmp_sync_profile(Monitor *mon, const QDict *qdict)
         Error *err = NULL;
 
         error_setg(&err, QERR_INVALID_PARAMETER, op);
-        hmp_handle_error(mon, &err);
+        hmp_handle_error(mon, err);
     }
 }
 
@@ -1191,7 +1190,7 @@ void hmp_exit_preconfig(Monitor *mon, const QDict *qdict)
     Error *err = NULL;
 
     qmp_x_exit_preconfig(&err);
-    hmp_handle_error(mon, &err);
+    hmp_handle_error(mon, err);
 }
 
 void hmp_cpu(Monitor *mon, const QDict *qdict)
@@ -1220,7 +1219,7 @@ void hmp_memsave(Monitor *mon, const QDict *qdict)
     }
 
     qmp_memsave(addr, size, filename, true, cpu_index, &err);
-    hmp_handle_error(mon, &err);
+    hmp_handle_error(mon, err);
 }
 
 void hmp_pmemsave(Monitor *mon, const QDict *qdict)
@@ -1231,7 +1230,7 @@ void hmp_pmemsave(Monitor *mon, const QDict *qdict)
     Error *err = NULL;
 
     qmp_pmemsave(addr, size, filename, &err);
-    hmp_handle_error(mon, &err);
+    hmp_handle_error(mon, err);
 }
 
 void hmp_ringbuf_write(Monitor *mon, const QDict *qdict)
@@ -1242,7 +1241,7 @@ void hmp_ringbuf_write(Monitor *mon, const QDict *qdict)
 
     qmp_ringbuf_write(chardev, data, false, 0, &err);
 
-    hmp_handle_error(mon, &err);
+    hmp_handle_error(mon, err);
 }
 
 void hmp_ringbuf_read(Monitor *mon, const QDict *qdict)
@@ -1255,7 +1254,7 @@ void hmp_ringbuf_read(Monitor *mon, const QDict *qdict)
 
     data = qmp_ringbuf_read(chardev, size, false, 0, &err);
     if (err) {
-        hmp_handle_error(mon, &err);
+        hmp_handle_error(mon, err);
         return;
     }
 
@@ -1280,7 +1279,7 @@ void hmp_cont(Monitor *mon, const QDict *qdict)
     Error *err = NULL;
 
     qmp_cont(&err);
-    hmp_handle_error(mon, &err);
+    hmp_handle_error(mon, err);
 }
 
 void hmp_system_wakeup(Monitor *mon, const QDict *qdict)
@@ -1288,7 +1287,7 @@ void hmp_system_wakeup(Monitor *mon, const QDict *qdict)
     Error *err = NULL;
 
     qmp_system_wakeup(&err);
-    hmp_handle_error(mon, &err);
+    hmp_handle_error(mon, err);
 }
 
 void hmp_nmi(Monitor *mon, const QDict *qdict)
@@ -1296,7 +1295,7 @@ void hmp_nmi(Monitor *mon, const QDict *qdict)
     Error *err = NULL;
 
     qmp_inject_nmi(&err);
-    hmp_handle_error(mon, &err);
+    hmp_handle_error(mon, err);
 }
 
 void hmp_set_link(Monitor *mon, const QDict *qdict)
@@ -1306,7 +1305,7 @@ void hmp_set_link(Monitor *mon, const QDict *qdict)
     Error *err = NULL;
 
     qmp_set_link(name, up, &err);
-    hmp_handle_error(mon, &err);
+    hmp_handle_error(mon, err);
 }
 
 void hmp_block_passwd(Monitor *mon, const QDict *qdict)
@@ -1316,7 +1315,7 @@ void hmp_block_passwd(Monitor *mon, const QDict *qdict)
     Error *err = NULL;
 
     qmp_block_passwd(true, device, false, NULL, password, &err);
-    hmp_handle_error(mon, &err);
+    hmp_handle_error(mon, err);
 }
 
 void hmp_balloon(Monitor *mon, const QDict *qdict)
@@ -1325,7 +1324,7 @@ void hmp_balloon(Monitor *mon, const QDict *qdict)
     Error *err = NULL;
 
     qmp_balloon(value, &err);
-    hmp_handle_error(mon, &err);
+    hmp_handle_error(mon, err);
 }
 
 void hmp_block_resize(Monitor *mon, const QDict *qdict)
@@ -1335,7 +1334,7 @@ void hmp_block_resize(Monitor *mon, const QDict *qdict)
     Error *err = NULL;
 
     qmp_block_resize(true, device, false, NULL, size, &err);
-    hmp_handle_error(mon, &err);
+    hmp_handle_error(mon, err);
 }
 
 void hmp_drive_mirror(Monitor *mon, const QDict *qdict)
@@ -1358,11 +1357,11 @@ void hmp_drive_mirror(Monitor *mon, const QDict *qdict)
 
     if (!filename) {
         error_setg(&err, QERR_MISSING_PARAMETER, "target");
-        hmp_handle_error(mon, &err);
+        hmp_handle_error(mon, err);
         return;
     }
     qmp_drive_mirror(&mirror, &err);
-    hmp_handle_error(mon, &err);
+    hmp_handle_error(mon, err);
 }
 
 void hmp_drive_backup(Monitor *mon, const QDict *qdict)
@@ -1388,12 +1387,12 @@ void hmp_drive_backup(Monitor *mon, const QDict *qdict)
 
     if (!filename) {
         error_setg(&err, QERR_MISSING_PARAMETER, "target");
-        hmp_handle_error(mon, &err);
+        hmp_handle_error(mon, err);
         return;
     }
 
     qmp_drive_backup(&backup, &err);
-    hmp_handle_error(mon, &err);
+    hmp_handle_error(mon, err);
 }
 
 void hmp_snapshot_blkdev(Monitor *mon, const QDict *qdict)
@@ -1409,7 +1408,7 @@ void hmp_snapshot_blkdev(Monitor *mon, const QDict *qdict)
         /* In the future, if 'snapshot-file' is not specified, the snapshot
            will be taken internally. Today it's actually required. */
         error_setg(&err, QERR_MISSING_PARAMETER, "snapshot-file");
-        hmp_handle_error(mon, &err);
+        hmp_handle_error(mon, err);
         return;
     }
 
@@ -1418,7 +1417,7 @@ void hmp_snapshot_blkdev(Monitor *mon, const QDict *qdict)
                                filename, false, NULL,
                                !!format, format,
                                true, mode, &err);
-    hmp_handle_error(mon, &err);
+    hmp_handle_error(mon, err);
 }
 
 void hmp_snapshot_blkdev_internal(Monitor *mon, const QDict *qdict)
@@ -1428,7 +1427,7 @@ void hmp_snapshot_blkdev_internal(Monitor *mon, const QDict *qdict)
     Error *err = NULL;
 
     qmp_blockdev_snapshot_internal_sync(device, name, &err);
-    hmp_handle_error(mon, &err);
+    hmp_handle_error(mon, err);
 }
 
 void hmp_snapshot_delete_blkdev_internal(Monitor *mon, const QDict *qdict)
@@ -1440,7 +1439,7 @@ void hmp_snapshot_delete_blkdev_internal(Monitor *mon, const QDict *qdict)
 
     qmp_blockdev_snapshot_delete_internal_sync(device, !!id, id,
                                                true, name, &err);
-    hmp_handle_error(mon, &err);
+    hmp_handle_error(mon, err);
 }
 
 void hmp_loadvm(Monitor *mon, const QDict *qdict)
@@ -1454,7 +1453,7 @@ void hmp_loadvm(Monitor *mon, const QDict *qdict)
     if (load_snapshot(name, &err) == 0 && saved_vm_running) {
         vm_start();
     }
-    hmp_handle_error(mon, &err);
+    hmp_handle_error(mon, err);
 }
 
 void hmp_savevm(Monitor *mon, const QDict *qdict)
@@ -1462,7 +1461,7 @@ void hmp_savevm(Monitor *mon, const QDict *qdict)
     Error *err = NULL;
 
     save_snapshot(qdict_get_try_str(qdict, "name"), &err);
-    hmp_handle_error(mon, &err);
+    hmp_handle_error(mon, err);
 }
 
 void hmp_delvm(Monitor *mon, const QDict *qdict)
@@ -1476,7 +1475,7 @@ void hmp_delvm(Monitor *mon, const QDict *qdict)
                       "deleting snapshot on device '%s': ",
                       bdrv_get_device_name(bs));
     }
-    hmp_handle_error(mon, &err);
+    hmp_handle_error(mon, err);
 }
 
 void hmp_info_snapshots(Monitor *mon, const QDict *qdict)
@@ -1652,7 +1651,7 @@ void hmp_migrate_continue(Monitor *mon, const QDict *qdict)
         qmp_migrate_continue(val, &err);
     }
 
-    hmp_handle_error(mon, &err);
+    hmp_handle_error(mon, err);
 }
 
 void hmp_migrate_incoming(Monitor *mon, const QDict *qdict)
@@ -1662,7 +1661,7 @@ void hmp_migrate_incoming(Monitor *mon, const QDict *qdict)
 
     qmp_migrate_incoming(uri, &err);
 
-    hmp_handle_error(mon, &err);
+    hmp_handle_error(mon, err);
 }
 
 void hmp_migrate_recover(Monitor *mon, const QDict *qdict)
@@ -1672,7 +1671,7 @@ void hmp_migrate_recover(Monitor *mon, const QDict *qdict)
 
     qmp_migrate_recover(uri, &err);
 
-    hmp_handle_error(mon, &err);
+    hmp_handle_error(mon, err);
 }
 
 void hmp_migrate_pause(Monitor *mon, const QDict *qdict)
@@ -1681,7 +1680,7 @@ void hmp_migrate_pause(Monitor *mon, const QDict *qdict)
 
     qmp_migrate_pause(&err);
 
-    hmp_handle_error(mon, &err);
+    hmp_handle_error(mon, err);
 }
 
 /* Kept for backwards compatibility */
@@ -1697,7 +1696,7 @@ void hmp_migrate_set_cache_size(Monitor *mon, const QDict *qdict)
     Error *err = NULL;
 
     qmp_migrate_set_cache_size(value, &err);
-    hmp_handle_error(mon, &err);
+    hmp_handle_error(mon, err);
 }
 
 /* Kept for backwards compatibility */
@@ -1728,7 +1727,7 @@ void hmp_migrate_set_capability(Monitor *mon, const QDict *qdict)
 
 end:
     qapi_free_MigrationCapabilityStatusList(caps);
-    hmp_handle_error(mon, &err);
+    hmp_handle_error(mon, err);
 }
 
 void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict)
@@ -1869,7 +1868,7 @@ void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict)
  cleanup:
     qapi_free_MigrateSetParameters(p);
     visit_free(v);
-    hmp_handle_error(mon, &err);
+    hmp_handle_error(mon, err);
 }
 
 void hmp_client_migrate_info(Monitor *mon, const QDict *qdict)
@@ -1886,14 +1885,14 @@ void hmp_client_migrate_info(Monitor *mon, const QDict *qdict)
     qmp_client_migrate_info(protocol, hostname,
                             has_port, port, has_tls_port, tls_port,
                             !!cert_subject, cert_subject, &err);
-    hmp_handle_error(mon, &err);
+    hmp_handle_error(mon, err);
 }
 
 void hmp_migrate_start_postcopy(Monitor *mon, const QDict *qdict)
 {
     Error *err = NULL;
     qmp_migrate_start_postcopy(&err);
-    hmp_handle_error(mon, &err);
+    hmp_handle_error(mon, err);
 }
 
 void hmp_x_colo_lost_heartbeat(Monitor *mon, const QDict *qdict)
@@ -1901,7 +1900,7 @@ void hmp_x_colo_lost_heartbeat(Monitor *mon, const QDict *qdict)
     Error *err = NULL;
 
     qmp_x_colo_lost_heartbeat(&err);
-    hmp_handle_error(mon, &err);
+    hmp_handle_error(mon, err);
 }
 
 void hmp_set_password(Monitor *mon, const QDict *qdict)
@@ -1912,7 +1911,7 @@ void hmp_set_password(Monitor *mon, const QDict *qdict)
     Error *err = NULL;
 
     qmp_set_password(protocol, password, !!connected, connected, &err);
-    hmp_handle_error(mon, &err);
+    hmp_handle_error(mon, err);
 }
 
 void hmp_expire_password(Monitor *mon, const QDict *qdict)
@@ -1922,7 +1921,7 @@ void hmp_expire_password(Monitor *mon, const QDict *qdict)
     Error *err = NULL;
 
     qmp_expire_password(protocol, whenstr, &err);
-    hmp_handle_error(mon, &err);
+    hmp_handle_error(mon, err);
 }
 
 void hmp_eject(Monitor *mon, const QDict *qdict)
@@ -1932,7 +1931,7 @@ void hmp_eject(Monitor *mon, const QDict *qdict)
     Error *err = NULL;
 
     qmp_eject(true, device, false, NULL, true, force, &err);
-    hmp_handle_error(mon, &err);
+    hmp_handle_error(mon, err);
 }
 
 #ifdef CONFIG_VNC
@@ -1978,7 +1977,7 @@ void hmp_change(Monitor *mon, const QDict *qdict)
                                 read_only,
                                 BLOCKDEV_CHANGE_READ_ONLY_MODE_RETAIN, &err);
             if (err) {
-                hmp_handle_error(mon, &err);
+                hmp_handle_error(mon, err);
                 return;
             }
         }
@@ -1988,7 +1987,7 @@ void hmp_change(Monitor *mon, const QDict *qdict)
                                    &err);
     }
 
-    hmp_handle_error(mon, &err);
+    hmp_handle_error(mon, err);
 }
 
 void hmp_block_set_io_throttle(Monitor *mon, const QDict *qdict)
@@ -2016,7 +2015,7 @@ void hmp_block_set_io_throttle(Monitor *mon, const QDict *qdict)
     }
 
     qmp_block_set_io_throttle(&throttle, &err);
-    hmp_handle_error(mon, &err);
+    hmp_handle_error(mon, err);
 }
 
 void hmp_block_stream(Monitor *mon, const QDict *qdict)
@@ -2031,7 +2030,7 @@ void hmp_block_stream(Monitor *mon, const QDict *qdict)
                      BLOCKDEV_ON_ERROR_REPORT, false, false, false, false,
                      &error);
 
-    hmp_handle_error(mon, &error);
+    hmp_handle_error(mon, error);
 }
 
 void hmp_block_job_set_speed(Monitor *mon, const QDict *qdict)
@@ -2042,7 +2041,7 @@ void hmp_block_job_set_speed(Monitor *mon, const QDict *qdict)
 
     qmp_block_job_set_speed(device, value, &error);
 
-    hmp_handle_error(mon, &error);
+    hmp_handle_error(mon, error);
 }
 
 void hmp_block_job_cancel(Monitor *mon, const QDict *qdict)
@@ -2053,7 +2052,7 @@ void hmp_block_job_cancel(Monitor *mon, const QDict *qdict)
 
     qmp_block_job_cancel(device, true, force, &error);
 
-    hmp_handle_error(mon, &error);
+    hmp_handle_error(mon, error);
 }
 
 void hmp_block_job_pause(Monitor *mon, const QDict *qdict)
@@ -2063,7 +2062,7 @@ void hmp_block_job_pause(Monitor *mon, const QDict *qdict)
 
     qmp_block_job_pause(device, &error);
 
-    hmp_handle_error(mon, &error);
+    hmp_handle_error(mon, error);
 }
 
 void hmp_block_job_resume(Monitor *mon, const QDict *qdict)
@@ -2073,7 +2072,7 @@ void hmp_block_job_resume(Monitor *mon, const QDict *qdict)
 
     qmp_block_job_resume(device, &error);
 
-    hmp_handle_error(mon, &error);
+    hmp_handle_error(mon, error);
 }
 
 void hmp_block_job_complete(Monitor *mon, const QDict *qdict)
@@ -2083,7 +2082,7 @@ void hmp_block_job_complete(Monitor *mon, const QDict *qdict)
 
     qmp_block_job_complete(device, &error);
 
-    hmp_handle_error(mon, &error);
+    hmp_handle_error(mon, error);
 }
 
 typedef struct HMPMigrationStatus
@@ -2143,7 +2142,7 @@ void hmp_migrate(Monitor *mon, const QDict *qdict)
     qmp_migrate(uri, !!blk, blk, !!inc, inc,
                 false, false, true, resume, &err);
     if (err) {
-        hmp_handle_error(mon, &err);
+        hmp_handle_error(mon, err);
         return;
     }
 
@@ -2181,7 +2180,7 @@ void hmp_netdev_add(Monitor *mon, const QDict *qdict)
     }
 
 out:
-    hmp_handle_error(mon, &err);
+    hmp_handle_error(mon, err);
 }
 
 void hmp_netdev_del(Monitor *mon, const QDict *qdict)
@@ -2190,7 +2189,7 @@ void hmp_netdev_del(Monitor *mon, const QDict *qdict)
     Error *err = NULL;
 
     qmp_netdev_del(id, &err);
-    hmp_handle_error(mon, &err);
+    hmp_handle_error(mon, err);
 }
 
 void hmp_object_add(Monitor *mon, const QDict *qdict)
@@ -2201,7 +2200,7 @@ void hmp_object_add(Monitor *mon, const QDict *qdict)
 
     opts = qemu_opts_from_qdict(qemu_find_opts("object"), qdict, &err);
     if (err) {
-        hmp_handle_error(mon, &err);
+        hmp_handle_error(mon, err);
         return;
     }
 
@@ -2209,7 +2208,7 @@ void hmp_object_add(Monitor *mon, const QDict *qdict)
     qemu_opts_del(opts);
 
     if (err) {
-        hmp_handle_error(mon, &err);
+        hmp_handle_error(mon, err);
     }
     if (obj) {
         object_unref(obj);
@@ -2222,7 +2221,7 @@ void hmp_getfd(Monitor *mon, const QDict *qdict)
     Error *err = NULL;
 
     qmp_getfd(fdname, &err);
-    hmp_handle_error(mon, &err);
+    hmp_handle_error(mon, err);
 }
 
 void hmp_closefd(Monitor *mon, const QDict *qdict)
@@ -2231,7 +2230,7 @@ void hmp_closefd(Monitor *mon, const QDict *qdict)
     Error *err = NULL;
 
     qmp_closefd(fdname, &err);
-    hmp_handle_error(mon, &err);
+    hmp_handle_error(mon, err);
 }
 
 void hmp_sendkey(Monitor *mon, const QDict *qdict)
@@ -2290,7 +2289,7 @@ void hmp_sendkey(Monitor *mon, const QDict *qdict)
     }
 
     qmp_send_key(head, has_hold_time, hold_time, &err);
-    hmp_handle_error(mon, &err);
+    hmp_handle_error(mon, err);
 
 out:
     qapi_free_KeyValueList(head);
@@ -2309,7 +2308,7 @@ void hmp_screendump(Monitor *mon, const QDict *qdict)
     Error *err = NULL;
 
     qmp_screendump(filename, id != NULL, id, id != NULL, head, &err);
-    hmp_handle_error(mon, &err);
+    hmp_handle_error(mon, err);
 }
 
 void hmp_nbd_server_start(Monitor *mon, const QDict *qdict)
@@ -2364,7 +2363,7 @@ void hmp_nbd_server_start(Monitor *mon, const QDict *qdict)
     qapi_free_BlockInfoList(block_list);
 
 exit:
-    hmp_handle_error(mon, &local_err);
+    hmp_handle_error(mon, local_err);
 }
 
 void hmp_nbd_server_add(Monitor *mon, const QDict *qdict)
@@ -2376,7 +2375,7 @@ void hmp_nbd_server_add(Monitor *mon, const QDict *qdict)
 
     qmp_nbd_server_add(device, !!name, name, true, writable,
                        false, NULL, &local_err);
-    hmp_handle_error(mon, &local_err);
+    hmp_handle_error(mon, local_err);
 }
 
 void hmp_nbd_server_remove(Monitor *mon, const QDict *qdict)
@@ -2387,7 +2386,7 @@ void hmp_nbd_server_remove(Monitor *mon, const QDict *qdict)
 
     /* Rely on NBD_SERVER_REMOVE_MODE_SAFE being the default */
     qmp_nbd_server_remove(name, force, NBD_SERVER_REMOVE_MODE_HARD, &err);
-    hmp_handle_error(mon, &err);
+    hmp_handle_error(mon, err);
 }
 
 void hmp_nbd_server_stop(Monitor *mon, const QDict *qdict)
@@ -2395,7 +2394,7 @@ void hmp_nbd_server_stop(Monitor *mon, const QDict *qdict)
     Error *err = NULL;
 
     qmp_nbd_server_stop(&err);
-    hmp_handle_error(mon, &err);
+    hmp_handle_error(mon, err);
 }
 
 void hmp_chardev_add(Monitor *mon, const QDict *qdict)
@@ -2411,7 +2410,7 @@ void hmp_chardev_add(Monitor *mon, const QDict *qdict)
         qemu_chr_new_from_opts(opts, NULL, &err);
         qemu_opts_del(opts);
     }
-    hmp_handle_error(mon, &err);
+    hmp_handle_error(mon, err);
 }
 
 void hmp_chardev_change(Monitor *mon, const QDict *qdict)
@@ -2445,7 +2444,7 @@ end:
     qapi_free_ChardevReturn(ret);
     qapi_free_ChardevBackend(backend);
     qemu_opts_del(opts);
-    hmp_handle_error(mon, &err);
+    hmp_handle_error(mon, err);
 }
 
 void hmp_chardev_remove(Monitor *mon, const QDict *qdict)
@@ -2453,7 +2452,7 @@ void hmp_chardev_remove(Monitor *mon, const QDict *qdict)
     Error *local_err = NULL;
 
     qmp_chardev_remove(qdict_get_str(qdict, "id"), &local_err);
-    hmp_handle_error(mon, &local_err);
+    hmp_handle_error(mon, local_err);
 }
 
 void hmp_chardev_send_break(Monitor *mon, const QDict *qdict)
@@ -2461,7 +2460,7 @@ void hmp_chardev_send_break(Monitor *mon, const QDict *qdict)
     Error *local_err = NULL;
 
     qmp_chardev_send_break(qdict_get_str(qdict, "id"), &local_err);
-    hmp_handle_error(mon, &local_err);
+    hmp_handle_error(mon, local_err);
 }
 
 void hmp_qemu_io(Monitor *mon, const QDict *qdict)
@@ -2517,7 +2516,7 @@ void hmp_qemu_io(Monitor *mon, const QDict *qdict)
 
 fail:
     blk_unref(local_blk);
-    hmp_handle_error(mon, &err);
+    hmp_handle_error(mon, err);
 }
 
 void hmp_object_del(Monitor *mon, const QDict *qdict)
@@ -2526,7 +2525,7 @@ void hmp_object_del(Monitor *mon, const QDict *qdict)
     Error *err = NULL;
 
     user_creatable_del(id, &err);
-    hmp_handle_error(mon, &err);
+    hmp_handle_error(mon, err);
 }
 
 void hmp_info_memory_devices(Monitor *mon, const QDict *qdict)
@@ -2576,7 +2575,7 @@ void hmp_info_memory_devices(Monitor *mon, const QDict *qdict)
     }
 
     qapi_free_MemoryDeviceInfoList(info_list);
-    hmp_handle_error(mon, &err);
+    hmp_handle_error(mon, err);
 }
 
 void hmp_info_iothreads(Monitor *mon, const QDict *qdict)
@@ -2605,7 +2604,7 @@ void hmp_rocker(Monitor *mon, const QDict *qdict)
 
     rocker = qmp_query_rocker(name, &err);
     if (err != NULL) {
-        hmp_handle_error(mon, &err);
+        hmp_handle_error(mon, err);
         return;
     }
 
@@ -2624,7 +2623,7 @@ void hmp_rocker_ports(Monitor *mon, const QDict *qdict)
 
     list = qmp_query_rocker_ports(name, &err);
     if (err != NULL) {
-        hmp_handle_error(mon, &err);
+        hmp_handle_error(mon, err);
         return;
     }
 
@@ -2653,7 +2652,7 @@ void hmp_rocker_of_dpa_flows(Monitor *mon, const QDict *qdict)
 
     list = qmp_query_rocker_of_dpa_flows(name, tbl_id != -1, tbl_id, &err);
     if (err != NULL) {
-        hmp_handle_error(mon, &err);
+        hmp_handle_error(mon, err);
         return;
     }
 
@@ -2804,7 +2803,7 @@ void hmp_rocker_of_dpa_groups(Monitor *mon, const QDict *qdict)
 
     list = qmp_query_rocker_of_dpa_groups(name, type != 9, type, &err);
     if (err != NULL) {
-        hmp_handle_error(mon, &err);
+        hmp_handle_error(mon, err);
         return;
     }
 
@@ -2911,7 +2910,7 @@ void hmp_info_vm_generation_id(Monitor *mon, const QDict *qdict)
     if (info) {
         monitor_printf(mon, "%s\n", info->guid);
     }
-    hmp_handle_error(mon, &err);
+    hmp_handle_error(mon, err);
     qapi_free_GuidInfo(info);
 }
 
@@ -2930,5 +2929,5 @@ void hmp_info_memory_size_summary(Monitor *mon, const QDict *qdict)
 
         qapi_free_MemoryInfo(info);
     }
-    hmp_handle_error(mon, &err);
+    hmp_handle_error(mon, err);
 }
qdev-monitor.c +2 -2
index 148df9cacf..85b58620d1 100644
@@ -857,7 +857,7 @@ void hmp_device_add(Monitor *mon, const QDict *qdict)
     Error *err = NULL;
 
     qmp_device_add((QDict *)qdict, NULL, &err);
-    hmp_handle_error(mon, &err);
+    hmp_handle_error(mon, err);
 }
 
 void hmp_device_del(Monitor *mon, const QDict *qdict)
@@ -866,7 +866,7 @@ void hmp_device_del(Monitor *mon, const QDict *qdict)
     Error *err = NULL;
 
     qmp_device_del(id, &err);
-    hmp_handle_error(mon, &err);
+    hmp_handle_error(mon, err);
 }
 
 BlockBackend *blk_by_qdev_id(const char *id, Error **errp)
qom/qom-hmp-cmds.c +2 -2
index a268e01eb4..cd08233a4c 100644
@@ -37,7 +37,7 @@ void hmp_qom_list(Monitor *mon, const QDict *qdict)
         }
         qapi_free_ObjectPropertyInfoList(start);
     }
-    hmp_handle_error(mon, &err);
+    hmp_handle_error(mon, err);
 }
 
 void hmp_qom_set(Monitor *mon, const QDict *qdict)
@@ -59,7 +59,7 @@ void hmp_qom_set(Monitor *mon, const QDict *qdict)
         }
         object_property_parse(obj, value, property, &err);
     }
-    hmp_handle_error(mon, &err);
+    hmp_handle_error(mon, err);
 }
 
 typedef struct QOMCompositionState {
Signature · 1 line
2.21.0

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

#8 lore raw

Re: [RFC v5 004/126] hmp: drop Error pointer indirection in hmp_handle_error

In reply to Vladimir Sementsov-Ogievskiy
Quoted 16 lines · Vladimir Sementsov-Ogievskiy

We don't need Error **, as all callers pass local Error object, which isn't used after the call. Use Error * instead.

---
  include/monitor/hmp.h      |   2 +-
  dump/dump-hmp-cmds.c       |   4 +-
  hw/core/machine-hmp-cmds.c |   6 +-
  monitor/hmp-cmds.c         | 155 ++++++++++++++++++-------------------
  qdev-monitor.c             |   4 +-
  qom/qom-hmp-cmds.c         |   4 +-
  6 files changed, 87 insertions(+), 88 deletions(-)

+++ b/dump/dump-hmp-cmds.c

dump/dump-hmp-cmds.c void hmp_dump_guest_memory(Monitor *mon, const QDict *qdict) · line 37

Quoted 7 lines
dump/dump-hmp-cmds.c +1 -1
@@ -32,7 +32,7 @@ void hmp_dump_guest_memory(Monitor *mon, const QDict *qdict)
 
      if (zlib + lzo + snappy + win_dmp > 1) {
          error_setg(&err, "only one of '-z|-l|-s|-w' can be set");
-        hmp_handle_error(mon, &err);
+        hmp_handle_error(mon, err);
          return;
      }

Probably not for this series, but would a patch to various HMP files to have a g_auto() sort of reporting on an error the moment it goes out of scope (rather than having to manually call hmp_handle_error() everywhere) make sense?

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org
#9 lore raw

Re: [RFC v5 004/126] hmp: drop Error pointer indirection in hmp_handle_error

Quoted 15 lines · * Eric Blake ([email protected]) wrote:
Quoted 13 lines · Vladimir Sementsov-Ogievskiy

We don't need Error **, as all callers pass local Error object, which isn't used after the call. Use Error * instead.

---
  include/monitor/hmp.h      |   2 +-
  dump/dump-hmp-cmds.c       |   4 +-
  hw/core/machine-hmp-cmds.c |   6 +-
  monitor/hmp-cmds.c         | 155 ++++++++++++++++++-------------------
  qdev-monitor.c             |   4 +-
  qom/qom-hmp-cmds.c         |   4 +-
  6 files changed, 87 insertions(+), 88 deletions(-)
Quoted 13 lines

dump/dump-hmp-cmds.c void hmp_dump_guest_memory(Monitor *mon, const QDict *qdict) · line 36

Quoted 8 lines

+++ b/dump/dump-hmp-cmds.c

dump/dump-hmp-cmds.c +1 -1
@@ -32,7 +32,7 @@ void hmp_dump_guest_memory(Monitor *mon, const QDict *qdict)
      if (zlib + lzo + snappy + win_dmp > 1) {
          error_setg(&err, "only one of '-z|-l|-s|-w' can be set");
-        hmp_handle_error(mon, &err);
+        hmp_handle_error(mon, err);
          return;
      }

Probably not for this series, but would a patch to various HMP files to have a g_auto() sort of reporting on an error the moment it goes out of scope (rather than having to manually call hmp_handle_error() everywhere) make sense?

Maybe; although lets be a bit careful just how much we hide behind g_auto.

Dave

Quoted 4 lines
Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

#10 lore raw

RFC v5 5/126 vnc: drop Error pointer indirection in vnc_client_io_error

In reply to Vladimir Sementsov-Ogievskiy

We don't need Error **, as all callers pass local Error object, which isn't used after the call, or NULL. Use Error * instead.

---
 ui/vnc.h |  2 +-
 ui/vnc.c | 20 +++++++-------------
 2 files changed, 8 insertions(+), 14 deletions(-)
ui/vnc.h +1 -1
index fea79c2fc9..4e2637ce6c 100644
@@ -547,7 +547,7 @@ uint32_t read_u32(uint8_t *data, size_t offset);
 
 /* Protocol stage functions */
 void vnc_client_error(VncState *vs);
-size_t vnc_client_io_error(VncState *vs, ssize_t ret, Error **errp);
+size_t vnc_client_io_error(VncState *vs, ssize_t ret, Error *err);
 
 void start_client_init(VncState *vs);
 void start_auth_vnc(VncState *vs);
ui/vnc.c +7 -13
index 87b8045afe..4100d6e404 100644
@@ -1312,7 +1312,7 @@ void vnc_disconnect_finish(VncState *vs)
     g_free(vs);
 }
 
-size_t vnc_client_io_error(VncState *vs, ssize_t ret, Error **errp)
+size_t vnc_client_io_error(VncState *vs, ssize_t ret, Error *err)
 {
     if (ret <= 0) {
         if (ret == 0) {
@@ -1320,15 +1320,11 @@ size_t vnc_client_io_error(VncState *vs, ssize_t ret, Error **errp)
             vnc_disconnect_start(vs);
         } else if (ret != QIO_CHANNEL_ERR_BLOCK) {
             trace_vnc_client_io_error(vs, vs->ioc,
-                                      errp ? error_get_pretty(*errp) :
-                                      "Unknown");
+                                      err ? error_get_pretty(err) : "Unknown");
             vnc_disconnect_start(vs);
         }
 
-        if (errp) {
-            error_free(*errp);
-            *errp = NULL;
-        }
+        error_free(err);
         return 0;
     }
     return ret;
@@ -1361,10 +1357,9 @@ size_t vnc_client_write_buf(VncState *vs, const uint8_t *data, size_t datalen)
 {
     Error *err = NULL;
     ssize_t ret;
-    ret = qio_channel_write(
-        vs->ioc, (const char *)data, datalen, &err);
+    ret = qio_channel_write(vs->ioc, (const char *)data, datalen, &err);
     VNC_DEBUG("Wrote wire %p %zd -> %ld\n", data, datalen, ret);
-    return vnc_client_io_error(vs, ret, &err);
+    return vnc_client_io_error(vs, ret, err);
 }
 
 
@@ -1488,10 +1483,9 @@ size_t vnc_client_read_buf(VncState *vs, uint8_t *data, size_t datalen)
 {
     ssize_t ret;
     Error *err = NULL;
-    ret = qio_channel_read(
-        vs->ioc, (char *)data, datalen, &err);
+    ret = qio_channel_read(vs->ioc, (char *)data, datalen, &err);
     VNC_DEBUG("Read wire %p %zd -> %ld\n", data, datalen, ret);
-    return vnc_client_io_error(vs, ret, &err);
+    return vnc_client_io_error(vs, ret, err);
 }
 
 
Signature · 1 line
2.21.0
#11 lore raw

RFC v5 6/126 qdev-monitor: well form error hint helpers

In reply to Vladimir Sementsov-Ogievskiy

Make qbus_list_bus and qbus_list_dev hint append helpers well formed:
rename errp to errp_in, as it is IN-parameter here (which is unusual for errp), rename functions to be error_append_*_hint.

---
 qdev-monitor.c | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)
qdev-monitor.c +12 -12
index 85b58620d1..d14ef6af01 100644
@@ -326,36 +326,36 @@ static Object *qdev_get_peripheral_anon(void)
     return dev;
 }
 
-static void qbus_list_bus(DeviceState *dev, Error **errp)
+static void error_append_qbus_bus_list_hint(DeviceState *dev, Error **errp_in)
 {
     BusState *child;
     const char *sep = " ";
 
-    error_append_hint(errp, "child buses at \"%s\":",
+    error_append_hint(errp_in, "child buses at \"%s\":",
                       dev->id ? dev->id : object_get_typename(OBJECT(dev)));
     QLIST_FOREACH(child, &dev->child_bus, sibling) {
-        error_append_hint(errp, "%s\"%s\"", sep, child->name);
+        error_append_hint(errp_in, "%s\"%s\"", sep, child->name);
         sep = ", ";
     }
-    error_append_hint(errp, "\n");
+    error_append_hint(errp_in, "\n");
 }
 
-static void qbus_list_dev(BusState *bus, Error **errp)
+static void error_append_qbus_dev_list_hint(BusState *bus, Error **errp_in)
 {
     BusChild *kid;
     const char *sep = " ";
 
-    error_append_hint(errp, "devices at \"%s\":", bus->name);
+    error_append_hint(errp_in, "devices at \"%s\":", bus->name);
     QTAILQ_FOREACH(kid, &bus->children, sibling) {
         DeviceState *dev = kid->child;
-        error_append_hint(errp, "%s\"%s\"", sep,
+        error_append_hint(errp_in, "%s\"%s\"", sep,
                           object_get_typename(OBJECT(dev)));
         if (dev->id) {
-            error_append_hint(errp, "/\"%s\"", dev->id);
+            error_append_hint(errp_in, "/\"%s\"", dev->id);
         }
         sep = ", ";
     }
-    error_append_hint(errp, "\n");
+    error_append_hint(errp_in, "\n");
 }
 
 static BusState *qbus_find_bus(DeviceState *dev, char *elem)
@@ -498,7 +498,7 @@ static BusState *qbus_find(const char *path, Error **errp)
         if (!dev) {
             error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND,
                       "Device '%s' not found", elem);
-            qbus_list_dev(bus, errp);
+            error_append_qbus_dev_list_hint(bus, errp);
             return NULL;
         }
 
@@ -516,7 +516,7 @@ static BusState *qbus_find(const char *path, Error **errp)
             if (dev->num_child_bus) {
                 error_setg(errp, "Device '%s' has multiple child buses",
                            elem);
-                qbus_list_bus(dev, errp);
+                error_append_qbus_bus_list_hint(dev, errp);
             } else {
                 error_setg(errp, "Device '%s' has no child bus", elem);
             }
@@ -532,7 +532,7 @@ static BusState *qbus_find(const char *path, Error **errp)
         bus = qbus_find_bus(dev, elem);
         if (!bus) {
             error_setg(errp, "Bus '%s' not found", elem);
-            qbus_list_bus(dev, errp);
+            error_append_qbus_bus_list_hint(dev, errp);
             return NULL;
         }
     }
Signature · 1 line
2.21.0
Reviewed-by on v5 6/126
#12 lore raw

Re: [RFC v5 006/126] qdev-monitor: well form error hint helpers

Hi

Quoted 15 lines · Vladimir Sementsov-Ogievskiy

Make qbus_list_bus and qbus_list_dev hint append helpers well formed:
rename errp to errp_in, as it is IN-parameter here (which is unusual for errp), rename functions to be error_append_*_hint.

---
 qdev-monitor.c | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)
qdev-monitor.c +0 -0
index 85b58620d1..d14ef6af01 100644

qdev-monitor.c static Object *qdev_get_peripheral_anon(void) · line 329

Quoted 5 lines
qdev-monitor.c +1 -1
@@ -326,36 +326,36 @@ static Object *qdev_get_peripheral_anon(void)
     return dev;
 }
 
-static void qbus_list_bus(DeviceState *dev, Error **errp)
+static void error_append_qbus_bus_list_hint(DeviceState *dev, Error **errp_in)

Please keep the qbus_ prefix

Quoted 8 lines
qdev-monitor.c +1 -1
 {
     BusState *child;
     const char *sep = " ";
 
-    error_append_hint(errp, "child buses at \"%s\":",
+    error_append_hint(errp_in, "child buses at \"%s\":",
                       dev->id ? dev->id : object_get_typename(OBJECT(dev)));
     QLIST_FOREACH(child, &dev->child_bus, sibling) {

qdev-monitor.c static Object *qdev_get_peripheral_anon(void) · line 343

Quoted 10 lines
qdev-monitor.c +3 -3
-        error_append_hint(errp, "%s\"%s\"", sep, child->name);
+        error_append_hint(errp_in, "%s\"%s\"", sep, child->name);
         sep = ", ";
     }
-    error_append_hint(errp, "\n");
+    error_append_hint(errp_in, "\n");
 }
 
-static void qbus_list_dev(BusState *bus, Error **errp)
+static void error_append_qbus_dev_list_hint(BusState *bus, Error **errp_in)

here too

Quoted 50 lines
qdev-monitor.c +7 -8
 {
     BusChild *kid;
     const char *sep = " ";
 
-    error_append_hint(errp, "devices at \"%s\":", bus->name);
+    error_append_hint(errp_in, "devices at \"%s\":", bus->name);
     QTAILQ_FOREACH(kid, &bus->children, sibling) {
         DeviceState *dev = kid->child;
-        error_append_hint(errp, "%s\"%s\"", sep,
+        error_append_hint(errp_in, "%s\"%s\"", sep,
                           object_get_typename(OBJECT(dev)));
         if (dev->id) {
-            error_append_hint(errp, "/\"%s\"", dev->id);
+            error_append_hint(errp_in, "/\"%s\"", dev->id);
         }
         sep = ", ";
     }
-    error_append_hint(errp, "\n");
+    error_append_hint(errp_in, "\n");
 }
 
 static BusState *qbus_find_bus(DeviceState *dev, char *elem)
@@ -498,7 +498,7 @@ static BusState *qbus_find(const char *path, Error **errp)
         if (!dev) {
             error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND,
                       "Device '%s' not found", elem);
-            qbus_list_dev(bus, errp);
+            error_append_qbus_dev_list_hint(bus, errp);
             return NULL;
         }
 
@@ -516,7 +516,7 @@ static BusState *qbus_find(const char *path, Error **errp)
             if (dev->num_child_bus) {
                 error_setg(errp, "Device '%s' has multiple child buses",
                            elem);
-                qbus_list_bus(dev, errp);
+                error_append_qbus_bus_list_hint(dev, errp);
             } else {
                 error_setg(errp, "Device '%s' has no child bus", elem);
             }
@@ -532,7 +532,7 @@ static BusState *qbus_find(const char *path, Error **errp)
         bus = qbus_find_bus(dev, elem);
         if (!bus) {
             error_setg(errp, "Bus '%s' not found", elem);
-            qbus_list_bus(dev, errp);
+            error_append_qbus_bus_list_hint(dev, errp);
             return NULL;
         }
     }
--
Quoted 3 lines

2.21.0

other than that:

Signature · 1 line
Marc-André Lureau
#13 lore raw

RFC v5 7/126 nbd: well form nbd_iter_channel_error errp handler

In reply to Vladimir Sementsov-Ogievskiy

Make nbd_iter_channel_error errp handler well formed:
rename errp to errp_in, as it is IN-parameter here (which is unusual for errp).

---
 block/nbd.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
block/nbd.c +5 -5
index 813c40d8f0..c66fdf54b9 100644
@@ -684,18 +684,18 @@ typedef struct NBDReplyChunkIter {
 } NBDReplyChunkIter;
 
 static void nbd_iter_channel_error(NBDReplyChunkIter *iter,
-                                   int ret, Error **local_err)
+                                   int ret, Error **errp_in)
 {
-    assert(ret < 0);
+    assert(ret < 0 && errp_in && *errp_in);
 
     if (!iter->ret) {
         iter->ret = ret;
-        error_propagate(&iter->err, *local_err);
+        error_propagate(&iter->err, *errp_in);
     } else {
-        error_free(*local_err);
+        error_free(*errp_in);
     }
 
-    *local_err = NULL;
+    *errp_in = NULL;
 }
 
 static void nbd_iter_request_error(NBDReplyChunkIter *iter, int ret)
Signature · 1 line
2.21.0
Reviewed-by on v5 7/126
#14 lore raw

Re: [RFC v5 007/126] nbd: well form nbd_iter_channel_error errp handler

Quoted 2 lines · Vladimir Sementsov-Ogievskiy

Make nbd_iter_channel_error errp handler well formed:
rename errp to errp_in, as it is IN-parameter here (which is unusual

Actually, rename local_err to errp_in.

Quoted 7 lines

for errp).

---
  block/nbd.c | 10 +++++-----
  1 file changed, 5 insertions(+), 5 deletions(-)

With commit message fixed,

Quoted 3 lines

static void nbd_iter_channel_error(NBDReplyChunkIter *iter,

block/nbd.c +1 -1
-                                   int ret, Error **local_err)
+                                   int ret, Error **errp_in)
Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org
#15 lore raw

RFC v5 8/126 ppc: well form kvmppc_hint_smt_possible error hint helper

In reply to Vladimir Sementsov-Ogievskiy

Make kvmppc_hint_smt_possible hint append helper well formed:
rename errp to errp_in, as it is IN-parameter here (which is unusual for errp), rename function to be error_append_*_hint.

---
 target/ppc/kvm_ppc.h | 4 ++--
 hw/ppc/spapr.c       | 2 +-
 target/ppc/kvm.c     | 6 +++---
 3 files changed, 6 insertions(+), 6 deletions(-)
target/ppc/kvm_ppc.h +2 -2
index 98bd7d5da6..35f1d499ad 100644
@@ -28,7 +28,7 @@ void kvmppc_set_papr(PowerPCCPU *cpu);
 int kvmppc_set_compat(PowerPCCPU *cpu, uint32_t compat_pvr);
 void kvmppc_set_mpic_proxy(PowerPCCPU *cpu, int mpic_proxy);
 int kvmppc_smt_threads(void);
-void kvmppc_hint_smt_possible(Error **errp);
+void error_append_kvmppc_smt_possible_hint(Error **errp_in);
 int kvmppc_set_smt_threads(int smt);
 int kvmppc_clear_tsr_bits(PowerPCCPU *cpu, uint32_t tsr_bits);
 int kvmppc_or_tsr_bits(PowerPCCPU *cpu, uint32_t tsr_bits);
@@ -164,7 +164,7 @@ static inline int kvmppc_smt_threads(void)
     return 1;
 }
 
-static inline void kvmppc_hint_smt_possible(Error **errp)
+static inline void error_append_kvmppc_smt_possible_hint(Error **errp_in)
 {
     return;
 }
hw/ppc/spapr.c +1 -1
index 514a17ae74..6729269aa9 100644
@@ -2565,7 +2565,7 @@ static void spapr_set_vsmt_mode(SpaprMachineState *spapr, Error **errp)
                                       " requires the use of VSMT mode %d.\n",
                                       smp_threads, kvm_smt, spapr->vsmt);
                 }
-                kvmppc_hint_smt_possible(&local_err);
+                error_append_kvmppc_smt_possible_hint(&local_err);
                 goto out;
             }
         }
target/ppc/kvm.c +3 -3
index 820724cc7d..af6e667bf8 100644
@@ -2076,7 +2076,7 @@ int kvmppc_set_smt_threads(int smt)
     return ret;
 }
 
-void kvmppc_hint_smt_possible(Error **errp)
+void error_append_kvmppc_smt_possible_hint(Error **errp_in)
 {
     int i;
     GString *g;
@@ -2091,10 +2091,10 @@ void kvmppc_hint_smt_possible(Error **errp)
             }
         }
         s = g_string_free(g, false);
-        error_append_hint(errp, "%s.\n", s);
+        error_append_hint(errp_in, "%s.\n", s);
         g_free(s);
     } else {
-        error_append_hint(errp,
+        error_append_hint(errp_in,
                           "This KVM seems to be too old to support VSMT.\n");
     }
 }
Signature · 1 line
2.21.0
Reviewed-by on v5 8/126
#16 lore raw

Re: [RFC v5 008/126] ppc: well form kvmppc_hint_smt_possible error hint helper

Quoted 26 lines · Vladimir Sementsov-Ogievskiy

Make kvmppc_hint_smt_possible hint append helper well formed:
rename errp to errp_in, as it is IN-parameter here (which is unusual for errp), rename function to be error_append_*_hint.

---
 target/ppc/kvm_ppc.h | 4 ++--
 hw/ppc/spapr.c       | 2 +-
 target/ppc/kvm.c     | 6 +++---
 3 files changed, 6 insertions(+), 6 deletions(-)
target/ppc/kvm_ppc.h +1 -1
index 98bd7d5da6..35f1d499ad 100644
@@ -28,7 +28,7 @@ void kvmppc_set_papr(PowerPCCPU *cpu);
 int kvmppc_set_compat(PowerPCCPU *cpu, uint32_t compat_pvr);
 void kvmppc_set_mpic_proxy(PowerPCCPU *cpu, int mpic_proxy);
 int kvmppc_smt_threads(void);
-void kvmppc_hint_smt_possible(Error **errp);
+void error_append_kvmppc_smt_possible_hint(Error **errp_in);
 int kvmppc_set_smt_threads(int smt);
 int kvmppc_clear_tsr_bits(PowerPCCPU *cpu, uint32_t tsr_bits);
 int kvmppc_or_tsr_bits(PowerPCCPU *cpu, uint32_t tsr_bits);

target/ppc/kvm_ppc.h static inline int kvmppc_smt_threads(void) · line 167

Quoted 5 lines
target/ppc/kvm_ppc.h +1 -1
@@ -164,7 +164,7 @@ static inline int kvmppc_smt_threads(void)
     return 1;
 }
 
-static inline void kvmppc_hint_smt_possible(Error **errp)
+static inline void error_append_kvmppc_smt_possible_hint(Error **errp_in)

Please keep the kvmppc_ prefix

other than that:

Quoted 46 lines
target/ppc/kvm_ppc.h +0 -0
 {
     return;
 }
hw/ppc/spapr.c +1 -1
index 514a17ae74..6729269aa9 100644
@@ -2565,7 +2565,7 @@ static void spapr_set_vsmt_mode(SpaprMachineState *spapr, Error **errp)
                                       " requires the use of VSMT mode %d.\n",
                                       smp_threads, kvm_smt, spapr->vsmt);
                 }
-                kvmppc_hint_smt_possible(&local_err);
+                error_append_kvmppc_smt_possible_hint(&local_err);
                 goto out;
             }
         }
target/ppc/kvm.c +3 -4
index 820724cc7d..af6e667bf8 100644
@@ -2076,7 +2076,7 @@ int kvmppc_set_smt_threads(int smt)
     return ret;
 }
 
-void kvmppc_hint_smt_possible(Error **errp)
+void error_append_kvmppc_smt_possible_hint(Error **errp_in)
 {
     int i;
     GString *g;
@@ -2091,10 +2091,10 @@ void kvmppc_hint_smt_possible(Error **errp)
             }
         }
         s = g_string_free(g, false);
-        error_append_hint(errp, "%s.\n", s);
+        error_append_hint(errp_in, "%s.\n", s);
         g_free(s);
     } else {
-        error_append_hint(errp,
+        error_append_hint(errp_in,
                           "This KVM seems to be too old to support VSMT.\n");
     }
 }
--

2.21.0

Signature · 1 line
Marc-André Lureau
#17 lore raw

RFC v5 9/126 9pfs: well form error hint helpers

In reply to Vladimir Sementsov-Ogievskiy

Make error_append_security_model_hint and error_append_socket_sockfd_hint hint append helpers well formed:
rename errp to errp_in, as it is IN-parameter here (which is unusual for errp).

---
 hw/9pfs/9p-local.c | 4 ++--
 hw/9pfs/9p-proxy.c | 5 +++--
 2 files changed, 5 insertions(+), 4 deletions(-)
hw/9pfs/9p-local.c +2 -2
index 08e673a79c..35635e7e7e 100644
@@ -1469,9 +1469,9 @@ static void local_cleanup(FsContext *ctx)
     g_free(data);
 }
 
-static void error_append_security_model_hint(Error **errp)
+static void error_append_security_model_hint(Error **errp_in)
 {
-    error_append_hint(errp, "Valid options are: security_model="
+    error_append_hint(errp_in, "Valid options are: security_model="
                       "[passthrough|mapped-xattr|mapped-file|none]\n");
 }
 
hw/9pfs/9p-proxy.c +3 -2
index 57a8c1c808..0cea8b19fa 100644
@@ -1114,9 +1114,10 @@ static int connect_namedsocket(const char *path, Error **errp)
     return sockfd;
 }
 
-static void error_append_socket_sockfd_hint(Error **errp)
+static void error_append_socket_sockfd_hint(Error **errp_in)
 {
-    error_append_hint(errp, "Either specify socket=/some/path where /some/path"
+    error_append_hint(errp_in,
+                      "Either specify socket=/some/path where /some/path"
                       " points to a listening AF_UNIX socket or sock_fd=fd"
                       " where fd is a file descriptor to a connected AF_UNIX"
                       " socket\n");
Signature · 1 line
2.21.0
Acked-by on v5 9/126
#18 lore raw

Re: [RFC v5 009/126] 9pfs: well form error hint helpers

Quoted 7 lines · On Fri, 11 Oct 2019 19:03:55 +0300 Vladimir Sementsov-Ogievskiy…

Make error_append_security_model_hint and error_append_socket_sockfd_hint hint append helpers well formed:
rename errp to errp_in, as it is IN-parameter here (which is unusual for errp).

---

Quoted 37 lines
 hw/9pfs/9p-local.c | 4 ++--
 hw/9pfs/9p-proxy.c | 5 +++--
 2 files changed, 5 insertions(+), 4 deletions(-)
hw/9pfs/9p-local.c +2 -2
index 08e673a79c..35635e7e7e 100644
@@ -1469,9 +1469,9 @@ static void local_cleanup(FsContext *ctx)
     g_free(data);
 }
 
-static void error_append_security_model_hint(Error **errp)
+static void error_append_security_model_hint(Error **errp_in)
 {
-    error_append_hint(errp, "Valid options are: security_model="
+    error_append_hint(errp_in, "Valid options are: security_model="
                       "[passthrough|mapped-xattr|mapped-file|none]\n");
 }
 
hw/9pfs/9p-proxy.c +3 -2
index 57a8c1c808..0cea8b19fa 100644
@@ -1114,9 +1114,10 @@ static int connect_namedsocket(const char *path, Error **errp)
     return sockfd;
 }
 
-static void error_append_socket_sockfd_hint(Error **errp)
+static void error_append_socket_sockfd_hint(Error **errp_in)
 {
-    error_append_hint(errp, "Either specify socket=/some/path where /some/path"
+    error_append_hint(errp_in,
+                      "Either specify socket=/some/path where /some/path"
                       " points to a listening AF_UNIX socket or sock_fd=fd"
                       " where fd is a file descriptor to a connected AF_UNIX"
                       " socket\n");
#19 lore raw

RFC v5 10/126 hw/core/qdev: cleanup Error ** variables

In reply to Vladimir Sementsov-Ogievskiy

Rename Error ** parameter in check_only_migratable to common errp.

In device_set_realized:

- Move "if (local_err != NULL)" closer to error setters.

- Drop 'Error **local_errp': it doesn't save any LoCs, but it's very unusual.

---
 hw/core/qdev.c | 28 +++++++++++++---------------
 1 file changed, 13 insertions(+), 15 deletions(-)
hw/core/qdev.c +13 -15
index cbad6c1d55..e3be8cc3c4 100644
@@ -796,12 +796,12 @@ static bool device_get_realized(Object *obj, Error **errp)
     return dev->realized;
 }
 
-static bool check_only_migratable(Object *obj, Error **err)
+static bool check_only_migratable(Object *obj, Error **errp)
 {
     DeviceClass *dc = DEVICE_GET_CLASS(obj);
 
     if (!vmstate_check_only_migratable(dc->vmsd)) {
-        error_setg(err, "Device %s is not migratable, but "
+        error_setg(errp, "Device %s is not migratable, but "
                    "--only-migratable was specified",
                    object_get_typename(obj));
         return false;
@@ -850,10 +850,9 @@ static void device_set_realized(Object *obj, bool value, Error **errp)
 
         if (dc->realize) {
             dc->realize(dev, &local_err);
-        }
-
-        if (local_err != NULL) {
-            goto fail;
+            if (local_err != NULL) {
+                goto fail;
+            }
         }
 
         DEVICE_LISTENER_CALL(realize, Forward, dev);
@@ -894,27 +893,26 @@ static void device_set_realized(Object *obj, bool value, Error **errp)
        }
 
     } else if (!value && dev->realized) {
-        Error **local_errp = NULL;
+        /* We want to catch in local_err only first error */
         QLIST_FOREACH(bus, &dev->child_bus, sibling) {
-            local_errp = local_err ? NULL : &local_err;
             object_property_set_bool(OBJECT(bus), false, "realized",
-                                     local_errp);
+                                     local_err ? NULL : &local_err);
         }
         if (qdev_get_vmsd(dev)) {
             vmstate_unregister(dev, qdev_get_vmsd(dev), dev);
         }
         if (dc->unrealize) {
-            local_errp = local_err ? NULL : &local_err;
-            dc->unrealize(dev, local_errp);
+            dc->unrealize(dev, local_err ? NULL : &local_err);
         }
         dev->pending_deleted_event = true;
         DEVICE_LISTENER_CALL(unrealize, Reverse, dev);
-    }
 
-    if (local_err != NULL) {
-        goto fail;
+        if (local_err != NULL) {
+            goto fail;
+        }
     }
 
+    assert(local_err == NULL);
     dev->realized = value;
     return;
 
@@ -952,7 +950,7 @@ static bool device_get_hotpluggable(Object *obj, Error **errp)
                                 qbus_is_hotpluggable(dev->parent_bus));
 }
 
-static bool device_get_hotplugged(Object *obj, Error **err)
+static bool device_get_hotplugged(Object *obj, Error **errp)
 {
     DeviceState *dev = DEVICE(obj);
 
Signature · 1 line
2.21.0
Reviewed-by on v5 10/126
#20 lore raw

Re: [RFC v5 010/126] hw/core/qdev: cleanup Error ** variables

Quoted 16 lines · Vladimir Sementsov-Ogievskiy

Rename Error ** parameter in check_only_migratable to common errp.

In device_set_realized:

- Move "if (local_err != NULL)" closer to error setters.

- Drop 'Error **local_errp': it doesn't save any LoCs, but it's very unusual.

---
  hw/core/qdev.c | 28 +++++++++++++---------------
  1 file changed, 13 insertions(+), 15 deletions(-)

hw/core/qdev.c static void device_set_realized(Object *obj, bool value, Error **errp) · line 896

Quoted 5 lines
hw/core/qdev.c +1 -1
@@ -894,27 +893,26 @@ static void device_set_realized(Object *obj, bool value, Error **errp)
         }
 
      } else if (!value && dev->realized) {
-        Error **local_errp = NULL;
+        /* We want to catch in local_err only first error */

grammar:
/* We want local_err to track only the first error */

hw/core/qdev.c static void device_set_realized(Object *obj, bool value, Error **errp) · line 900

Quoted 6 lines
hw/core/qdev.c +1 -2
          QLIST_FOREACH(bus, &dev->child_bus, sibling) {
-            local_errp = local_err ? NULL : &local_err;
              object_property_set_bool(OBJECT(bus), false, "realized",
-                                     local_errp);
+                                     local_err ? NULL : &local_err);
          }

Otherwise,

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org
Reviewed-by on v5 10/126
#21 lore raw

Re: [RFC v5 010/126] hw/core/qdev: cleanup Error ** variables

In reply to Vladimir Sementsov-Ogievskiy
Quoted 93 lines · Vladimir Sementsov-Ogievskiy

Rename Error ** parameter in check_only_migratable to common errp.

In device_set_realized:

- Move "if (local_err != NULL)" closer to error setters.

- Drop 'Error **local_errp': it doesn't save any LoCs, but it's very unusual.

---
 hw/core/qdev.c | 28 +++++++++++++---------------
 1 file changed, 13 insertions(+), 15 deletions(-)
hw/core/qdev.c +13 -16
index cbad6c1d55..e3be8cc3c4 100644
@@ -796,12 +796,12 @@ static bool device_get_realized(Object *obj, Error **errp)
     return dev->realized;
 }
 
-static bool check_only_migratable(Object *obj, Error **err)
+static bool check_only_migratable(Object *obj, Error **errp)
 {
     DeviceClass *dc = DEVICE_GET_CLASS(obj);
 
     if (!vmstate_check_only_migratable(dc->vmsd)) {
-        error_setg(err, "Device %s is not migratable, but "
+        error_setg(errp, "Device %s is not migratable, but "
                    "--only-migratable was specified",
                    object_get_typename(obj));
         return false;
@@ -850,10 +850,9 @@ static void device_set_realized(Object *obj, bool value, Error **errp)
 
         if (dc->realize) {
             dc->realize(dev, &local_err);
-        }
-
-        if (local_err != NULL) {
-            goto fail;
+            if (local_err != NULL) {
+                goto fail;
+            }
         }
 
         DEVICE_LISTENER_CALL(realize, Forward, dev);
@@ -894,27 +893,26 @@ static void device_set_realized(Object *obj, bool value, Error **errp)
        }
 
     } else if (!value && dev->realized) {
-        Error **local_errp = NULL;
+        /* We want to catch in local_err only first error */
         QLIST_FOREACH(bus, &dev->child_bus, sibling) {
-            local_errp = local_err ? NULL : &local_err;
             object_property_set_bool(OBJECT(bus), false, "realized",
-                                     local_errp);
+                                     local_err ? NULL : &local_err);
         }
         if (qdev_get_vmsd(dev)) {
             vmstate_unregister(dev, qdev_get_vmsd(dev), dev);
         }
         if (dc->unrealize) {
-            local_errp = local_err ? NULL : &local_err;
-            dc->unrealize(dev, local_errp);
+            dc->unrealize(dev, local_err ? NULL : &local_err);
         }
         dev->pending_deleted_event = true;
         DEVICE_LISTENER_CALL(unrealize, Reverse, dev);
-    }
 
-    if (local_err != NULL) {
-        goto fail;
+        if (local_err != NULL) {
+            goto fail;
+        }
     }
 
+    assert(local_err == NULL);
     dev->realized = value;
     return;
 
@@ -952,7 +950,7 @@ static bool device_get_hotpluggable(Object *obj, Error **errp)
                                 qbus_is_hotpluggable(dev->parent_bus));
 }
 
-static bool device_get_hotplugged(Object *obj, Error **err)
+static bool device_get_hotplugged(Object *obj, Error **errp)
 {
     DeviceState *dev = DEVICE(obj);
 
--
Quoted 3 lines

2.21.0

Signature · 1 line
Marc-André Lureau
#22 lore raw

RFC v5 11/126 block/snapshot: rename Error ** parameter to more common errp

In reply to Vladimir Sementsov-Ogievskiy
---
 block/snapshot.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
block/snapshot.c +2 -2
index 8081616ae9..bd9fb01817 100644
@@ -426,7 +426,7 @@ fail:
 }
 
 int bdrv_all_delete_snapshot(const char *name, BlockDriverState **first_bad_bs,
-                             Error **err)
+                             Error **errp)
 {
     int ret = 0;
     BlockDriverState *bs;
@@ -441,7 +441,7 @@ int bdrv_all_delete_snapshot(const char *name, BlockDriverState **first_bad_bs,
             bdrv_snapshot_find(bs, snapshot, name) >= 0)
         {
             ret = bdrv_snapshot_delete(bs, snapshot->id_str,
-                                       snapshot->name, err);
+                                       snapshot->name, errp);
         }
         aio_context_release(ctx);
         if (ret < 0) {
Signature · 1 line
2.21.0
Reviewed-by on v5 11/126
#23 lore raw

Re: [RFC v5 011/126] block/snapshot: rename Error ** parameter to more common errp

Quoted 5 lines · Vladimir Sementsov-Ogievskiy
---
  block/snapshot.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
Quoted 23 lines
block/snapshot.c +2 -2
index 8081616ae9..bd9fb01817 100644
@@ -426,7 +426,7 @@ fail:
  }
 
  int bdrv_all_delete_snapshot(const char *name, BlockDriverState **first_bad_bs,
-                             Error **err)
+                             Error **errp)
  {
      int ret = 0;
      BlockDriverState *bs;
@@ -441,7 +441,7 @@ int bdrv_all_delete_snapshot(const char *name, BlockDriverState **first_bad_bs,
              bdrv_snapshot_find(bs, snapshot, name) >= 0)
          {
              ret = bdrv_snapshot_delete(bs, snapshot->id_str,
-                                       snapshot->name, err);
+                                       snapshot->name, errp);
          }
          aio_context_release(ctx);
          if (ret < 0) {
Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org
#24 lore raw

RFC v5 12/126 hw/i386/amd_iommu: rename Error ** parameter to more common errp

In reply to Vladimir Sementsov-Ogievskiy
---
 hw/i386/amd_iommu.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
hw/i386/amd_iommu.c +7 -7
index d3726361dd..c496a0679b 100644
@@ -1533,7 +1533,7 @@ static void amdvi_reset(DeviceState *dev)
     amdvi_init(s);
 }
 
-static void amdvi_realize(DeviceState *dev, Error **err)
+static void amdvi_realize(DeviceState *dev, Error **errp)
 {
     int ret = 0;
     AMDVIState *s = AMD_IOMMU_DEVICE(dev);
@@ -1548,21 +1548,21 @@ static void amdvi_realize(DeviceState *dev, Error **err)
     /* This device should take care of IOMMU PCI properties */
     x86_iommu->type = TYPE_AMD;
     qdev_set_parent_bus(DEVICE(&s->pci), &bus->qbus);
-    object_property_set_bool(OBJECT(&s->pci), true, "realized", err);
+    object_property_set_bool(OBJECT(&s->pci), true, "realized", errp);
     ret = pci_add_capability(&s->pci.dev, AMDVI_CAPAB_ID_SEC, 0,
-                                         AMDVI_CAPAB_SIZE, err);
+                                         AMDVI_CAPAB_SIZE, errp);
     if (ret < 0) {
         return;
     }
     s->capab_offset = ret;
 
     ret = pci_add_capability(&s->pci.dev, PCI_CAP_ID_MSI, 0,
-                             AMDVI_CAPAB_REG_SIZE, err);
+                             AMDVI_CAPAB_REG_SIZE, errp);
     if (ret < 0) {
         return;
     }
     ret = pci_add_capability(&s->pci.dev, PCI_CAP_ID_HT, 0,
-                             AMDVI_CAPAB_REG_SIZE, err);
+                             AMDVI_CAPAB_REG_SIZE, errp);
     if (ret < 0) {
         return;
     }
@@ -1577,8 +1577,8 @@ static void amdvi_realize(DeviceState *dev, Error **err)
     sysbus_init_mmio(SYS_BUS_DEVICE(s), &s->mmio);
     sysbus_mmio_map(SYS_BUS_DEVICE(s), 0, AMDVI_BASE_ADDR);
     pci_setup_iommu(bus, amdvi_host_dma_iommu, s);
-    s->devid = object_property_get_int(OBJECT(&s->pci), "addr", err);
-    msi_init(&s->pci.dev, 0, 1, true, false, err);
+    s->devid = object_property_get_int(OBJECT(&s->pci), "addr", errp);
+    msi_init(&s->pci.dev, 0, 1, true, false, errp);
     amdvi_init(s);
 }
 
Signature · 1 line
2.21.0
#25 lore raw

RFC v5 13/126 qga: rename Error ** parameter to more common errp

In reply to Vladimir Sementsov-Ogievskiy
---
 qga/commands-posix.c |  2 +-
 qga/commands-win32.c |  2 +-
 qga/commands.c       | 12 ++++++------
 3 files changed, 8 insertions(+), 8 deletions(-)
qga/commands-posix.c +1 -1
index dfc05f5b8a..6dcd2d5db6 100644
@@ -2780,7 +2780,7 @@ static double ga_get_login_time(struct utmpx *user_info)
     return seconds + useconds;
 }
 
-GuestUserList *qmp_guest_get_users(Error **err)
+GuestUserList *qmp_guest_get_users(Error **errp)
 {
     GHashTable *cache = NULL;
     GuestUserList *head = NULL, *cur_item = NULL;
qga/commands-win32.c +1 -1
index 6b67f16faf..9789465b4a 100644
@@ -1946,7 +1946,7 @@ typedef struct _GA_WTSINFOA {
 
 } GA_WTSINFOA;
 
-GuestUserList *qmp_guest_get_users(Error **err)
+GuestUserList *qmp_guest_get_users(Error **errp)
 {
 #define QGA_NANOSECONDS 10000000
 
qga/commands.c +6 -6
index 0c7d1385c2..43c323cead 100644
@@ -143,7 +143,7 @@ static GuestExecInfo *guest_exec_info_find(int64_t pid_numeric)
     return NULL;
 }
 
-GuestExecStatus *qmp_guest_exec_status(int64_t pid, Error **err)
+GuestExecStatus *qmp_guest_exec_status(int64_t pid, Error **errp)
 {
     GuestExecInfo *gei;
     GuestExecStatus *ges;
@@ -152,7 +152,7 @@ GuestExecStatus *qmp_guest_exec_status(int64_t pid, Error **err)
 
     gei = guest_exec_info_find(pid);
     if (gei == NULL) {
-        error_setg(err, QERR_INVALID_PARAMETER, "pid");
+        error_setg(errp, QERR_INVALID_PARAMETER, "pid");
         return NULL;
     }
 
@@ -385,7 +385,7 @@ GuestExec *qmp_guest_exec(const char *path,
                        bool has_env, strList *env,
                        bool has_input_data, const char *input_data,
                        bool has_capture_output, bool capture_output,
-                       Error **err)
+                       Error **errp)
 {
     GPid pid;
     GuestExec *ge = NULL;
@@ -405,7 +405,7 @@ GuestExec *qmp_guest_exec(const char *path,
     arglist.next = has_arg ? arg : NULL;
 
     if (has_input_data) {
-        input = qbase64_decode(input_data, -1, &ninput, err);
+        input = qbase64_decode(input_data, -1, &ninput, errp);
         if (!input) {
             return NULL;
         }
@@ -424,7 +424,7 @@ GuestExec *qmp_guest_exec(const char *path,
             guest_exec_task_setup, NULL, &pid, has_input_data ? &in_fd : NULL,
             has_output ? &out_fd : NULL, has_output ? &err_fd : NULL, &gerr);
     if (!ret) {
-        error_setg(err, QERR_QGA_COMMAND_FAILED, gerr->message);
+        error_setg(errp, QERR_QGA_COMMAND_FAILED, gerr->message);
         g_error_free(gerr);
         goto done;
     }
@@ -499,7 +499,7 @@ int ga_parse_whence(GuestFileWhence *whence, Error **errp)
     return -1;
 }
 
-GuestHostName *qmp_guest_get_host_name(Error **err)
+GuestHostName *qmp_guest_get_host_name(Error **errp)
 {
     GuestHostName *result = NULL;
     gchar const *hostname = g_get_host_name();
Signature · 1 line
2.21.0
#26 lore raw

RFC v5 14/126 monitor/qmp-cmds: rename Error ** parameter to more common errp

In reply to Vladimir Sementsov-Ogievskiy
---
 monitor/qmp-cmds.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
monitor/qmp-cmds.c +1 -1
index 0880341a2d..c6faa3eaf0 100644
@@ -109,7 +109,7 @@ void qmp_system_reset(Error **errp)
     qemu_system_reset_request(SHUTDOWN_CAUSE_HOST_QMP_SYSTEM_RESET);
 }
 
-void qmp_system_powerdown(Error **erp)
+void qmp_system_powerdown(Error **errp)
 {
     qemu_system_powerdown_request();
 }
Signature · 1 line
2.21.0
#27 lore raw

RFC v5 15/126 hw/s390x: rename Error ** parameter to more common errp

In reply to Vladimir Sementsov-Ogievskiy
---
 hw/s390x/event-facility.c | 2 +-
 hw/s390x/s390-stattrib.c  | 3 ++-
 2 files changed, 3 insertions(+), 2 deletions(-)
hw/s390x/event-facility.c +1 -1
index 66205697ae..dc733ee2af 100644
@@ -439,7 +439,7 @@ static void sclp_event_set_allow_all_mask_sizes(Object *obj, bool value,
     ef->allow_all_mask_sizes = value;
 }
 
-static bool sclp_event_get_allow_all_mask_sizes(Object *obj, Error **e)
+static bool sclp_event_get_allow_all_mask_sizes(Object *obj, Error **errp)
 {
     SCLPEventFacility *ef = (SCLPEventFacility *)obj;
 
hw/s390x/s390-stattrib.c +2 -1
index bf5ac014c4..58121b9f68 100644
@@ -352,7 +352,8 @@ static void s390_stattrib_class_init(ObjectClass *oc, void *data)
     dc->realize = s390_stattrib_realize;
 }
 
-static inline bool s390_stattrib_get_migration_enabled(Object *obj, Error **e)
+static inline bool s390_stattrib_get_migration_enabled(Object *obj,
+                                                       Error **errp)
 {
     S390StAttribState *s = S390_STATTRIB(obj);
 
Signature · 1 line
2.21.0
#29 lore raw

RFC v5 16/126 hw/sd: rename Error ** parameter to more common errp

In reply to Vladimir Sementsov-Ogievskiy
---
 hw/sd/sdhci.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/sd/sdhci.c +1 -1
index e08ec3e398..e56031b5e4 100644
@@ -1459,7 +1459,7 @@ static void sdhci_sysbus_finalize(Object *obj)
     sdhci_uninitfn(s);
 }
 
-static void sdhci_sysbus_realize(DeviceState *dev, Error ** errp)
+static void sdhci_sysbus_realize(DeviceState *dev, Error **errp)
 {
     SDHCIState *s = SYSBUS_SDHCI(dev);
     SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
Signature · 1 line
2.21.0
Reviewed-by on v5 16/126
#30 lore raw

Re: [RFC v5 016/126] hw/sd: rename Error ** parameter to more common errp

Quoted 10 lines · Vladimir Sementsov-Ogievskiy
---
  hw/sd/sdhci.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
hw/sd/sdhci.c +0 -0
index e08ec3e398..e56031b5e4 100644

hw/sd/sdhci.c static void sdhci_sysbus_finalize(Object *obj) · line 1462

Quoted 5 lines
hw/sd/sdhci.c +1 -1
@@ -1459,7 +1459,7 @@ static void sdhci_sysbus_finalize(Object *obj)
      sdhci_uninitfn(s);
  }
 
-static void sdhci_sysbus_realize(DeviceState *dev, Error ** errp)
+static void sdhci_sysbus_realize(DeviceState *dev, Error **errp)

This is not a rename, but reformatting.

With a better commit message,

Quoted 4 lines
hw/sd/sdhci.c +0 -0
  {
      SDHCIState *s = SYSBUS_SDHCI(dev);
      SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org
#31 lore raw

RFC v5 17/126 hw/tpm: rename Error ** parameter to more common errp

In reply to Vladimir Sementsov-Ogievskiy
---
 hw/tpm/tpm_emulator.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
hw/tpm/tpm_emulator.c +4 -4
index 22f9113432..10d587ed40 100644
@@ -155,7 +155,7 @@ static int tpm_emulator_unix_tx_bufs(TPMEmulator *tpm_emu,
                                      const uint8_t *in, uint32_t in_len,
                                      uint8_t *out, uint32_t out_len,
                                      bool *selftest_done,
-                                     Error **err)
+                                     Error **errp)
 {
     ssize_t ret;
     bool is_selftest = false;
@@ -165,20 +165,20 @@ static int tpm_emulator_unix_tx_bufs(TPMEmulator *tpm_emu,
         is_selftest = tpm_util_is_selftest(in, in_len);
     }
 
-    ret = qio_channel_write_all(tpm_emu->data_ioc, (char *)in, in_len, err);
+    ret = qio_channel_write_all(tpm_emu->data_ioc, (char *)in, in_len, errp);
     if (ret != 0) {
         return -1;
     }
 
     ret = qio_channel_read_all(tpm_emu->data_ioc, (char *)out,
-              sizeof(struct tpm_resp_hdr), err);
+              sizeof(struct tpm_resp_hdr), errp);
     if (ret != 0) {
         return -1;
     }
 
     ret = qio_channel_read_all(tpm_emu->data_ioc,
               (char *)out + sizeof(struct tpm_resp_hdr),
-              tpm_cmd_get_size(out) - sizeof(struct tpm_resp_hdr), err);
+              tpm_cmd_get_size(out) - sizeof(struct tpm_resp_hdr), errp);
     if (ret != 0) {
         return -1;
     }
Signature · 1 line
2.21.0
Reviewed-by on v5 17/126
#32 lore raw

Re: [RFC v5 017/126] hw/tpm: rename Error ** parameter to more common errp

Quoted 1 line · Vladimir Sementsov-Ogievskiy
Quoted 41 lines
---
  hw/tpm/tpm_emulator.c | 8 ++++----
  1 file changed, 4 insertions(+), 4 deletions(-)
hw/tpm/tpm_emulator.c +4 -4
index 22f9113432..10d587ed40 100644
@@ -155,7 +155,7 @@ static int tpm_emulator_unix_tx_bufs(TPMEmulator *tpm_emu,
                                       const uint8_t *in, uint32_t in_len,
                                       uint8_t *out, uint32_t out_len,
                                       bool *selftest_done,
-                                     Error **err)
+                                     Error **errp)
  {
      ssize_t ret;
      bool is_selftest = false;
@@ -165,20 +165,20 @@ static int tpm_emulator_unix_tx_bufs(TPMEmulator *tpm_emu,
          is_selftest = tpm_util_is_selftest(in, in_len);
      }
 
-    ret = qio_channel_write_all(tpm_emu->data_ioc, (char *)in, in_len, err);
+    ret = qio_channel_write_all(tpm_emu->data_ioc, (char *)in, in_len, errp);
      if (ret != 0) {
          return -1;
      }
 
      ret = qio_channel_read_all(tpm_emu->data_ioc, (char *)out,
-              sizeof(struct tpm_resp_hdr), err);
+              sizeof(struct tpm_resp_hdr), errp);
      if (ret != 0) {
          return -1;
      }
 
      ret = qio_channel_read_all(tpm_emu->data_ioc,
                (char *)out + sizeof(struct tpm_resp_hdr),
-              tpm_cmd_get_size(out) - sizeof(struct tpm_resp_hdr), err);
+              tpm_cmd_get_size(out) - sizeof(struct tpm_resp_hdr), errp);
      if (ret != 0) {
          return -1;
      }
#33 lore raw

RFC v5 18/126 hw/usb: rename Error ** parameter to more common errp

In reply to Vladimir Sementsov-Ogievskiy
---
 hw/usb/dev-network.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/usb/dev-network.c +1 -1
index 5de6213cc4..b81a8abe83 100644
@@ -1342,7 +1342,7 @@ static NetClientInfo net_usbnet_info = {
     .cleanup = usbnet_cleanup,
 };
 
-static void usb_net_realize(USBDevice *dev, Error **errrp)
+static void usb_net_realize(USBDevice *dev, Error **errp)
 {
     USBNetState *s = USB_NET(dev);
 
Signature · 1 line
2.21.0
#34 lore raw

RFC v5 19/126 include/block/snapshot.h: rename Error ** parameter to more common errp

In reply to Vladimir Sementsov-Ogievskiy
---
 include/block/snapshot.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/block/snapshot.h +1 -1
index b5d5084a12..2bfcd57578 100644
@@ -78,7 +78,7 @@ int bdrv_snapshot_load_tmp_by_id_or_name(BlockDriverState *bs,
 
 bool bdrv_all_can_snapshot(BlockDriverState **first_bad_bs);
 int bdrv_all_delete_snapshot(const char *name, BlockDriverState **first_bsd_bs,
-                             Error **err);
+                             Error **errp);
 int bdrv_all_goto_snapshot(const char *name, BlockDriverState **first_bad_bs,
                            Error **errp);
 int bdrv_all_find_snapshot(const char *name, BlockDriverState **first_bad_bs);
Signature · 1 line
2.21.0
Reviewed-by on v5 19/126
#35 lore raw

Re: [RFC v5 019/126] include/block/snapshot.h: rename Error ** parameter to more common errp

Quoted 4 lines · Vladimir Sementsov-Ogievskiy
---
  include/block/snapshot.h | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 15 lines
include/block/snapshot.h +1 -1
index b5d5084a12..2bfcd57578 100644
@@ -78,7 +78,7 @@ int bdrv_snapshot_load_tmp_by_id_or_name(BlockDriverState *bs,
 
  bool bdrv_all_can_snapshot(BlockDriverState **first_bad_bs);
  int bdrv_all_delete_snapshot(const char *name, BlockDriverState **first_bsd_bs,
-                             Error **err);
+                             Error **errp);
  int bdrv_all_goto_snapshot(const char *name, BlockDriverState **first_bad_bs,
                             Error **errp);
  int bdrv_all_find_snapshot(const char *name, BlockDriverState **first_bad_bs);
Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org
#36 lore raw

RFC v5 20/126 include/qom/object.h: rename Error ** parameter to more common errp

In reply to Vladimir Sementsov-Ogievskiy
---
 include/qom/object.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
include/qom/object.h +2 -2
index 128d00c77f..716f6f655d 100644
@@ -1635,9 +1635,9 @@ void object_class_property_add_uint32_ptr(ObjectClass *klass, const char *name,
  * property of type 'uint64'.
  */
 void object_property_add_uint64_ptr(Object *obj, const char *name,
-                                    const uint64_t *v, Error **Errp);
+                                    const uint64_t *v, Error **errp);
 void object_class_property_add_uint64_ptr(ObjectClass *klass, const char *name,
-                                          const uint64_t *v, Error **Errp);
+                                          const uint64_t *v, Error **errp);
 
 /**
  * object_property_add_alias:
Signature · 1 line
2.21.0
Reviewed-by on v5 20/126
#37 lore raw

Re: [RFC v5 020/126] include/qom/object.h: rename Error ** parameter to more common errp

Quoted 10 lines · Vladimir Sementsov-Ogievskiy
---
  include/qom/object.h | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
include/qom/object.h +0 -0
index 128d00c77f..716f6f655d 100644

include/qom/object.h void object_class_property_add_uint32_ptr(ObjectClass *klass, const char *name, · line 1640

Quoted 8 lines
include/qom/object.h +2 -2
@@ -1635,9 +1635,9 @@ void object_class_property_add_uint32_ptr(ObjectClass *klass, const char *name,
   * property of type 'uint64'.
   */
  void object_property_add_uint64_ptr(Object *obj, const char *name,
-                                    const uint64_t *v, Error **Errp);
+                                    const uint64_t *v, Error **errp);
  void object_class_property_add_uint64_ptr(ObjectClass *klass, const char *name,
-                                          const uint64_t *v, Error **Errp);
+                                          const uint64_t *v, Error **errp);

Oddly the implementation already use lowercase.

Quoted 4 lines
include/qom/object.h +0 -0
  /**
   * object_property_add_alias:
 
#38 lore raw

RFC v5 21/126 qapi/error: add (Error **errp) cleaning APIs

In reply to Vladimir Sementsov-Ogievskiy
---
 include/qapi/error.h | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)
include/qapi/error.h +23 -0
index 12532bdf69..d6898d833b 100644
@@ -309,6 +309,29 @@ void warn_reportf_err(Error *err, const char *fmt, ...)
 void error_reportf_err(Error *err, const char *fmt, ...)
     GCC_FMT_ATTR(2, 3);
 
+/*
+ * Functions to clean Error **errp: call corresponding Error *err cleaning
+ * function an set pointer to NULL
+ */
+static inline void error_free_errp(Error **errp_in)
+{
+    error_free(*errp_in);
+    *errp_in = NULL;
+}
+
+static inline void error_report_errp(Error **errp_in)
+{
+    error_report_err(*errp_in);
+    *errp_in = NULL;
+}
+
+static inline void warn_report_errp(Error **errp_in)
+{
+    warn_report_err(*errp_in);
+    *errp_in = NULL;
+}
+
+
 /*
  * Just like error_setg(), except you get to specify the error class.
  * Note: use of error classes other than ERROR_CLASS_GENERIC_ERROR is
Signature · 1 line
2.21.0
#39 lore raw

RFC v5 22/126 backends/cryptodev: drop local_err from cryptodev_backend_complete()

In reply to Vladimir Sementsov-Ogievskiy

No reason for local_err here, use errp directly instead.

---
 backends/cryptodev.c | 11 +----------
 1 file changed, 1 insertion(+), 10 deletions(-)
backends/cryptodev.c +1 -10
index 3c071eab95..5a9735684e 100644
@@ -176,19 +176,10 @@ cryptodev_backend_complete(UserCreatable *uc, Error **errp)
 {
     CryptoDevBackend *backend = CRYPTODEV_BACKEND(uc);
     CryptoDevBackendClass *bc = CRYPTODEV_BACKEND_GET_CLASS(uc);
-    Error *local_err = NULL;
 
     if (bc->init) {
-        bc->init(backend, &local_err);
-        if (local_err) {
-            goto out;
-        }
+        bc->init(backend, errp);
     }
-
-    return;
-
-out:
-    error_propagate(errp, local_err);
 }
 
 void cryptodev_backend_set_used(CryptoDevBackend *backend, bool used)
Signature · 1 line
2.21.0
Reviewed-by on v5 22/126
#40 lore raw

Re: [RFC v5 022/126] backends/cryptodev: drop local_err from cryptodev_backend_complete()

Quoted 23 lines · Vladimir Sementsov-Ogievskiy

No reason for local_err here, use errp directly instead.

---
  backends/cryptodev.c | 11 +----------
  1 file changed, 1 insertion(+), 10 deletions(-)
backends/cryptodev.c +0 -5
index 3c071eab95..5a9735684e 100644
@@ -176,19 +176,10 @@ cryptodev_backend_complete(UserCreatable *uc, Error **errp)
  {
      CryptoDevBackend *backend = CRYPTODEV_BACKEND(uc);
      CryptoDevBackendClass *bc = CRYPTODEV_BACKEND_GET_CLASS(uc);
-    Error *local_err = NULL;
 
      if (bc->init) {
-        bc->init(backend, &local_err);
-        if (local_err) {
-            goto out;
-        }

backends/cryptodev.c cryptodev_backend_complete(UserCreatable *uc, Error **errp) · line 185

Quoted 10 lines
backends/cryptodev.c +1 -5
+        bc->init(backend, errp);
      }
-
-    return;
-
-out:
-    error_propagate(errp, local_err);
  }
 
  void cryptodev_backend_set_used(CryptoDevBackend *backend, bool used)
Reviewed-by on v5 22/126
#41 lore raw

Re: [RFC v5 022/126] backends/cryptodev: drop local_err from cryptodev_backend_complete()

In reply to Vladimir Sementsov-Ogievskiy
Quoted 34 lines · Vladimir Sementsov-Ogievskiy

No reason for local_err here, use errp directly instead.

---
 backends/cryptodev.c | 11 +----------
 1 file changed, 1 insertion(+), 10 deletions(-)
backends/cryptodev.c +1 -11
index 3c071eab95..5a9735684e 100644
@@ -176,19 +176,10 @@ cryptodev_backend_complete(UserCreatable *uc, Error **errp)
 {
     CryptoDevBackend *backend = CRYPTODEV_BACKEND(uc);
     CryptoDevBackendClass *bc = CRYPTODEV_BACKEND_GET_CLASS(uc);
-    Error *local_err = NULL;
 
     if (bc->init) {
-        bc->init(backend, &local_err);
-        if (local_err) {
-            goto out;
-        }
+        bc->init(backend, errp);
     }
-
-    return;
-
-out:
-    error_propagate(errp, local_err);
 }
 
 void cryptodev_backend_set_used(CryptoDevBackend *backend, bool used)
--
Quoted 3 lines

2.21.0

Signature · 1 line
Marc-André Lureau
#42 lore raw

RFC v5 23/126 hw/vfio/ap: drop local_err from vfio_ap_realize

In reply to Vladimir Sementsov-Ogievskiy

No reason for local_err here, use errp directly instead.

---
 hw/vfio/ap.c | 16 +++-------------
 1 file changed, 3 insertions(+), 13 deletions(-)
hw/vfio/ap.c +3 -13
index da6a20669d..db816e1860 100644
@@ -87,16 +87,14 @@ static VFIOGroup *vfio_ap_get_group(VFIOAPDevice *vapdev, Error **errp)
 
 static void vfio_ap_realize(DeviceState *dev, Error **errp)
 {
-    int ret;
     char *mdevid;
-    Error *local_err = NULL;
     VFIOGroup *vfio_group;
     APDevice *apdev = AP_DEVICE(dev);
     VFIOAPDevice *vapdev = VFIO_AP_DEVICE(apdev);
 
-    vfio_group = vfio_ap_get_group(vapdev, &local_err);
+    vfio_group = vfio_ap_get_group(vapdev, errp);
     if (!vfio_group) {
-        goto out_err;
+        return;
     }
 
     vapdev->vdev.ops = &vfio_ap_ops;
@@ -113,18 +111,10 @@ static void vfio_ap_realize(DeviceState *dev, Error **errp)
      */
     vapdev->vdev.balloon_allowed = true;
 
-    ret = vfio_get_device(vfio_group, mdevid, &vapdev->vdev, &local_err);
-    if (ret) {
-        goto out_get_dev_err;
-    }
-
-    return;
+    vfio_get_device(vfio_group, mdevid, &vapdev->vdev, errp);
 
-out_get_dev_err:
     vfio_ap_put_device(vapdev);
     vfio_put_group(vfio_group);
-out_err:
-    error_propagate(errp, local_err);
 }
 
 static void vfio_ap_unrealize(DeviceState *dev, Error **errp)
Signature · 1 line
2.21.0
Reviewed-by on v5 23/126
#43 lore raw

Re: [RFC v5 023/126] hw/vfio/ap: drop local_err from vfio_ap_realize

Quoted 52 lines · Vladimir Sementsov-Ogievskiy

No reason for local_err here, use errp directly instead.

---
 hw/vfio/ap.c | 16 +++-------------
 1 file changed, 3 insertions(+), 13 deletions(-)
hw/vfio/ap.c +3 -14
index da6a20669d..db816e1860 100644
@@ -87,16 +87,14 @@ static VFIOGroup *vfio_ap_get_group(VFIOAPDevice *vapdev, Error **errp)
 
 static void vfio_ap_realize(DeviceState *dev, Error **errp)
 {
-    int ret;
     char *mdevid;
-    Error *local_err = NULL;
     VFIOGroup *vfio_group;
     APDevice *apdev = AP_DEVICE(dev);
     VFIOAPDevice *vapdev = VFIO_AP_DEVICE(apdev);
 
-    vfio_group = vfio_ap_get_group(vapdev, &local_err);
+    vfio_group = vfio_ap_get_group(vapdev, errp);
     if (!vfio_group) {
-        goto out_err;
+        return;
     }
 
     vapdev->vdev.ops = &vfio_ap_ops;
@@ -113,18 +111,10 @@ static void vfio_ap_realize(DeviceState *dev, Error **errp)
      */
     vapdev->vdev.balloon_allowed = true;
 
-    ret = vfio_get_device(vfio_group, mdevid, &vapdev->vdev, &local_err);
-    if (ret) {
-        goto out_get_dev_err;
-    }
-
-    return;
+    vfio_get_device(vfio_group, mdevid, &vapdev->vdev, errp);
 
-out_get_dev_err:
     vfio_ap_put_device(vapdev);
     vfio_put_group(vfio_group);
-out_err:
-    error_propagate(errp, local_err);
 }
 
 static void vfio_ap_unrealize(DeviceState *dev, Error **errp)
--
Quoted 3 lines

2.21.0

Signature · 1 line
Marc-André Lureau
#44 lore raw

Re: [RFC v5 023/126] hw/vfio/ap: drop local_err from vfio_ap_realize

In reply to Vladimir Sementsov-Ogievskiy
Quoted 31 lines · On Fri, 11 Oct 2019 19:04:09 +0300 Vladimir Sementsov-Ogievskiy…

No reason for local_err here, use errp directly instead.

---
 hw/vfio/ap.c | 16 +++-------------
 1 file changed, 3 insertions(+), 13 deletions(-)
hw/vfio/ap.c +2 -4
index da6a20669d..db816e1860 100644
@@ -87,16 +87,14 @@ static VFIOGroup *vfio_ap_get_group(VFIOAPDevice *vapdev, Error **errp)
 
 static void vfio_ap_realize(DeviceState *dev, Error **errp)
 {
-    int ret;
     char *mdevid;
-    Error *local_err = NULL;
     VFIOGroup *vfio_group;
     APDevice *apdev = AP_DEVICE(dev);
     VFIOAPDevice *vapdev = VFIO_AP_DEVICE(apdev);
 
-    vfio_group = vfio_ap_get_group(vapdev, &local_err);
+    vfio_group = vfio_ap_get_group(vapdev, errp);
     if (!vfio_group) {
-        goto out_err;
+        return;
     }
 
     vapdev->vdev.ops = &vfio_ap_ops;

hw/vfio/ap.c static void vfio_ap_realize(DeviceState *dev, Error **errp) · line 114

Quoted 10 lines
hw/vfio/ap.c +1 -6
@@ -113,18 +111,10 @@ static void vfio_ap_realize(DeviceState *dev, Error **errp)
      */
     vapdev->vdev.balloon_allowed = true;
 
-    ret = vfio_get_device(vfio_group, mdevid, &vapdev->vdev, &local_err);
-    if (ret) {
-        goto out_get_dev_err;
-    }
-
-    return;
+    vfio_get_device(vfio_group, mdevid, &vapdev->vdev, errp);

This looks wrong; you still need to check for the outcome of vfio_get_device().

Quoted 9 lines
hw/vfio/ap.c +0 -3
-out_get_dev_err:
     vfio_ap_put_device(vapdev);
     vfio_put_group(vfio_group);
-out_err:
-    error_propagate(errp, local_err);
 }
 
 static void vfio_ap_unrealize(DeviceState *dev, Error **errp)
#45 lore raw

Re: [RFC v5 023/126] hw/vfio/ap: drop local_err from vfio_ap_realize

Quoted 37 lines · Cornelia Huck
Quoted 34 lines · On Fri, 11 Oct 2019 19:04:09 +0300 Vladimir Sementsov-Ogievskiy…

No reason for local_err here, use errp directly instead.

---
  hw/vfio/ap.c | 16 +++-------------
  1 file changed, 3 insertions(+), 13 deletions(-)
hw/vfio/ap.c +2 -4
index da6a20669d..db816e1860 100644
@@ -87,16 +87,14 @@ static VFIOGroup *vfio_ap_get_group(VFIOAPDevice *vapdev, Error **errp)
 
  static void vfio_ap_realize(DeviceState *dev, Error **errp)
  {
-    int ret;
      char *mdevid;
-    Error *local_err = NULL;
      VFIOGroup *vfio_group;
      APDevice *apdev = AP_DEVICE(dev);
      VFIOAPDevice *vapdev = VFIO_AP_DEVICE(apdev);
 
-    vfio_group = vfio_ap_get_group(vapdev, &local_err);
+    vfio_group = vfio_ap_get_group(vapdev, errp);
      if (!vfio_group) {
-        goto out_err;
+        return;
      }
 
      vapdev->vdev.ops = &vfio_ap_ops;
@@ -113,18 +111,10 @@ static void vfio_ap_realize(DeviceState *dev, Error **errp)
       */
      vapdev->vdev.balloon_allowed = true;
 
Quoted 10 lines

hw/vfio/ap.c static void vfio_ap_realize(DeviceState *dev, Error **errp) · line 114

Quoted 7 lines
hw/vfio/ap.c +1 -6
-    ret = vfio_get_device(vfio_group, mdevid, &vapdev->vdev, &local_err);
-    if (ret) {
-        goto out_get_dev_err;
-    }
-
-    return;
+    vfio_get_device(vfio_group, mdevid, &vapdev->vdev, errp);

This looks wrong; you still need to check for the outcome of vfio_get_device().

Oops, agree, will fix.

Quoted 11 lines
Quoted 10 lines
hw/vfio/ap.c +0 -3
-out_get_dev_err:
      vfio_ap_put_device(vapdev);
      vfio_put_group(vfio_group);
-out_err:
-    error_propagate(errp, local_err);
  }
 
  static void vfio_ap_unrealize(DeviceState *dev, Error **errp)
Signature · 2 lines
Best regards,
Vladimir
#46 lore raw

RFC v5 24/126 error: auto propagated local_err

In reply to Vladimir Sementsov-Ogievskiy

Here is introduced ERRP_AUTO_PROPAGATE macro, to be used at start of functions with errp OUT parameter.

It has three goals:

1. Fix issue with error_fatal & error_prepend/error_append_hint: user can't see this additional information, because exit() happens in error_setg earlier than information is added. [Reported by Greg Kurz]

2. Fix issue with error_abort & error_propagate: when we wrap error_abort by local_err+error_propagate, resulting coredump will refer to error_propagate and not to the place where error happened. (the macro itself doesn't fix the issue, but it allows to [3.] drop all local_err+error_propagate pattern, which will definitely fix the issue) [Reported by Kevin Wolf]

3. Drop local_err+error_propagate pattern, which is used to workaround void functions with errp parameter, when caller wants to know resulting status. (Note: actually these functions could be merely updated to return int error code).

To achieve these goals, we need to add invocation of the macro at start of functions, which needs error_prepend/error_append_hint (1.); add invocation of the macro at start of functions which do local_err+error_propagate scenario the check errors, drop local errors from them and just use *errp instead (2., 3.).

---

CC Gerd Hoffmann <[email protected]>
CC "Gonglei (Arei)" <[email protected]>
CC Eduardo Habkost <[email protected]>
CC Igor Mammedov <[email protected]>
CC Laurent Vivier <[email protected]>
CC Amit Shah <[email protected]>
CC Kevin Wolf <[email protected]>
CC Max Reitz <[email protected]>
CC John Snow <[email protected]>
CC Ari Sundholm <[email protected]>
CC Pavel Dovgalyuk <[email protected]>
CC Paolo Bonzini <[email protected]>
CC Stefan Hajnoczi <[email protected]>
CC Fam Zheng <[email protected]>
CC Stefan Weil <[email protected]>
CC Ronnie Sahlberg <[email protected]>
CC Peter Lieven <[email protected]>
CC Eric Blake <[email protected]>
CC "Denis V. Lunev" <[email protected]>
CC Markus Armbruster <[email protected]>
CC Alberto Garcia <[email protected]>
CC Jason Dillaman <[email protected]>
CC Wen Congyang <[email protected]>
CC Xie Changlong <[email protected]>
CC Liu Yuan <[email protected]>
CC "Richard W.M. Jones" <[email protected]>
CC Jeff Cody <[email protected]>
CC "Marc-André Lureau" <[email protected]>
CC "Daniel P. Berrangé" <[email protected]>
CC Richard Henderson <[email protected]>
CC Greg Kurz <[email protected]>
CC "Michael S. Tsirkin" <[email protected]>
CC Marcel Apfelbaum <[email protected]>
CC Beniamino Galvani <[email protected]>
CC Peter Maydell <[email protected]>
CC "Cédric Le Goater" <[email protected]>
CC Andrew Jeffery <[email protected]>
CC Joel Stanley <[email protected]>
CC Andrew Baumann <[email protected]>
CC "Philippe Mathieu-Daudé" <[email protected]>
CC Antony Pavlov <[email protected]>
CC Jean-Christophe Dubois <[email protected]>
CC Peter Chubb <[email protected]>
CC Subbaraya Sundeep <[email protected]>
CC Eric Auger <[email protected]>
CC Alistair Francis <[email protected]>
CC "Edgar E. Iglesias" <[email protected]>
CC Stefano Stabellini <[email protected]>
CC Anthony Perard <[email protected]>
CC Paul Durrant <[email protected]>
CC Paul Burton <[email protected]>
CC Aleksandar Rikalo <[email protected]>
CC Chris Wulff <[email protected]>
CC Marek Vasut <[email protected]>
CC David Gibson <[email protected]>
CC Cornelia Huck <[email protected]>
CC Halil Pasic <[email protected]>
CC Christian Borntraeger <[email protected]>
CC "Hervé Poussineau" <[email protected]>
CC Xiao Guangrong <[email protected]>
CC Aurelien Jarno <[email protected]>
CC Aleksandar Markovic <[email protected]>
CC Mark Cave-Ayland <[email protected]>
CC Jason Wang <[email protected]>
CC Laszlo Ersek <[email protected]>
CC Yuval Shaia <[email protected]>
CC Palmer Dabbelt <[email protected]>
CC Sagar Karandikar <[email protected]>
CC Bastian Koppelmann <[email protected]>
CC David Hildenbrand <[email protected]>
CC Thomas Huth <[email protected]>
CC Eric Farman <[email protected]>
CC Matthew Rosato <[email protected]>
CC Hannes Reinecke <[email protected]>
CC Michael Walle <[email protected]>
CC Artyom Tarasenko <[email protected]>
CC Stefan Berger <[email protected]>
CC Samuel Thibault <[email protected]>
CC Alex Williamson <[email protected]>
CC Tony Krowiak <[email protected]>
CC Pierre Morel <[email protected]>
CC Michael Roth <[email protected]>
CC Hailiang Zhang <[email protected]>
CC Juan Quintela <[email protected]>
CC "Dr. David Alan Gilbert" <[email protected]>
CC Luigi Rizzo <[email protected]>
CC Giuseppe Lettieri <[email protected]>
CC Vincenzo Maffione <[email protected]>
CC Jan Kiszka <[email protected]>
CC Anthony Green <[email protected]>
CC Stafford Horne <[email protected]>
CC Guan Xuetao <[email protected]>
CC Max Filippov <[email protected]>
 include/qapi/error.h | 38 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)
include/qapi/error.h +38 -0
index d6898d833b..47238d9065 100644
@@ -345,6 +345,44 @@ void error_set_internal(Error **errp,
                         ErrorClass err_class, const char *fmt, ...)
     GCC_FMT_ATTR(6, 7);
 
+typedef struct ErrorPropagator {
+    Error *local_err;
+    Error **errp;
+} ErrorPropagator;
+
+static inline void error_propagator_cleanup(ErrorPropagator *prop)
+{
+    error_propagate(prop->errp, prop->local_err);
+}
+
+G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(ErrorPropagator, error_propagator_cleanup);
+
+/*
+ * ERRP_AUTO_PROPAGATE
+ *
+ * This macro is created to be the first line of a function with Error **errp
+ * OUT parameter. It's needed only in cases where we want to use error_prepend,
+ * error_append_hint or dereference *errp. It's still safe (but useless) in
+ * other cases.
+ *
+ * If errp is NULL or points to error_fatal, it is rewritten to point to a
+ * local Error object, which will be automatically propagated to the original
+ * errp on function exit (see error_propagator_cleanup).
+ *
+ * After invocation of this macro it is always safe to dereference errp
+ * (as it's not NULL anymore) and to add information (by error_prepend or
+ * error_append_hint)
+ * (as, if it was error_fatal, we swapped it with a local_error to be
+ * propagated on cleanup).
+ *
+ * Note: we don't wrap the error_abort case, as we want resulting coredump
+ * to point to the place where the error happened, not to error_propagate.
+ */
+#define ERRP_AUTO_PROPAGATE()                                  \
+    g_auto(ErrorPropagator) _auto_errp_prop = {.errp = errp};  \
+    errp = ((errp == NULL || *errp == error_fatal)             \
+            ? &_auto_errp_prop.local_err : errp)
+
 /*
  * Special error destination to abort on error.
  * See error_setg() and error_propagate() for details.
Signature · 1 line
2.21.0
Reviewed-by on v5 24/126
#47 lore raw
Quoted 164 lines · Vladimir Sementsov-Ogievskiy

Here is introduced ERRP_AUTO_PROPAGATE macro, to be used at start of functions with errp OUT parameter.

It has three goals:

1. Fix issue with error_fatal & error_prepend/error_append_hint: user can't see this additional information, because exit() happens in error_setg earlier than information is added. [Reported by Greg Kurz]

2. Fix issue with error_abort & error_propagate: when we wrap error_abort by local_err+error_propagate, resulting coredump will refer to error_propagate and not to the place where error happened. (the macro itself doesn't fix the issue, but it allows to [3.] drop all local_err+error_propagate pattern, which will definitely fix the issue) [Reported by Kevin Wolf]

3. Drop local_err+error_propagate pattern, which is used to workaround void functions with errp parameter, when caller wants to know resulting status. (Note: actually these functions could be merely updated to return int error code).

To achieve these goals, we need to add invocation of the macro at start of functions, which needs error_prepend/error_append_hint (1.); add invocation of the macro at start of functions which do local_err+error_propagate scenario the check errors, drop local errors from them and just use *errp instead (2., 3.).

---

CC Gerd Hoffmann <[email protected]>
CC "Gonglei (Arei)" <[email protected]>
CC Eduardo Habkost <[email protected]>
CC Igor Mammedov <[email protected]>
CC Laurent Vivier <[email protected]>
CC Amit Shah <[email protected]>
CC Kevin Wolf <[email protected]>
CC Max Reitz <[email protected]>
CC John Snow <[email protected]>
CC Ari Sundholm <[email protected]>
CC Pavel Dovgalyuk <[email protected]>
CC Paolo Bonzini <[email protected]>
CC Stefan Hajnoczi <[email protected]>
CC Fam Zheng <[email protected]>
CC Stefan Weil <[email protected]>
CC Ronnie Sahlberg <[email protected]>
CC Peter Lieven <[email protected]>
CC Eric Blake <[email protected]>
CC "Denis V. Lunev" <[email protected]>
CC Markus Armbruster <[email protected]>
CC Alberto Garcia <[email protected]>
CC Jason Dillaman <[email protected]>
CC Wen Congyang <[email protected]>
CC Xie Changlong <[email protected]>
CC Liu Yuan <[email protected]>
CC "Richard W.M. Jones" <[email protected]>
CC Jeff Cody <[email protected]>
CC "Marc-André Lureau" <[email protected]>
CC "Daniel P. Berrangé" <[email protected]>
CC Richard Henderson <[email protected]>
CC Greg Kurz <[email protected]>
CC "Michael S. Tsirkin" <[email protected]>
CC Marcel Apfelbaum <[email protected]>
CC Beniamino Galvani <[email protected]>
CC Peter Maydell <[email protected]>
CC "Cédric Le Goater" <[email protected]>
CC Andrew Jeffery <[email protected]>
CC Joel Stanley <[email protected]>
CC Andrew Baumann <[email protected]>
CC "Philippe Mathieu-Daudé" <[email protected]>
CC Antony Pavlov <[email protected]>
CC Jean-Christophe Dubois <[email protected]>
CC Peter Chubb <[email protected]>
CC Subbaraya Sundeep <[email protected]>
CC Eric Auger <[email protected]>
CC Alistair Francis <[email protected]>
CC "Edgar E. Iglesias" <[email protected]>
CC Stefano Stabellini <[email protected]>
CC Anthony Perard <[email protected]>
CC Paul Durrant <[email protected]>
CC Paul Burton <[email protected]>
CC Aleksandar Rikalo <[email protected]>
CC Chris Wulff <[email protected]>
CC Marek Vasut <[email protected]>
CC David Gibson <[email protected]>
CC Cornelia Huck <[email protected]>
CC Halil Pasic <[email protected]>
CC Christian Borntraeger <[email protected]>
CC "Hervé Poussineau" <[email protected]>
CC Xiao Guangrong <[email protected]>
CC Aurelien Jarno <[email protected]>
CC Aleksandar Markovic <[email protected]>
CC Mark Cave-Ayland <[email protected]>
CC Jason Wang <[email protected]>
CC Laszlo Ersek <[email protected]>
CC Yuval Shaia <[email protected]>
CC Palmer Dabbelt <[email protected]>
CC Sagar Karandikar <[email protected]>
CC Bastian Koppelmann <[email protected]>
CC David Hildenbrand <[email protected]>
CC Thomas Huth <[email protected]>
CC Eric Farman <[email protected]>
CC Matthew Rosato <[email protected]>
CC Hannes Reinecke <[email protected]>
CC Michael Walle <[email protected]>
CC Artyom Tarasenko <[email protected]>
CC Stefan Berger <[email protected]>
CC Samuel Thibault <[email protected]>
CC Alex Williamson <[email protected]>
CC Tony Krowiak <[email protected]>
CC Pierre Morel <[email protected]>
CC Michael Roth <[email protected]>
CC Hailiang Zhang <[email protected]>
CC Juan Quintela <[email protected]>
CC "Dr. David Alan Gilbert" <[email protected]>
CC Luigi Rizzo <[email protected]>
CC Giuseppe Lettieri <[email protected]>
CC Vincenzo Maffione <[email protected]>
CC Jan Kiszka <[email protected]>
CC Anthony Green <[email protected]>
CC Stafford Horne <[email protected]>
CC Guan Xuetao <[email protected]>
CC Max Filippov <[email protected]>
 include/qapi/error.h | 38 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)
include/qapi/error.h +19 -0
index d6898d833b..47238d9065 100644
@@ -345,6 +345,44 @@ void error_set_internal(Error **errp,
                         ErrorClass err_class, const char *fmt, ...)
     GCC_FMT_ATTR(6, 7);
 
+typedef struct ErrorPropagator {
+    Error *local_err;
+    Error **errp;
+} ErrorPropagator;
+
+static inline void error_propagator_cleanup(ErrorPropagator *prop)
+{
+    error_propagate(prop->errp, prop->local_err);
+}
+
+G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(ErrorPropagator, error_propagator_cleanup);
+
+/*
+ * ERRP_AUTO_PROPAGATE
+ *
+ * This macro is created to be the first line of a function with Error **errp
+ * OUT parameter. It's needed only in cases where we want to use error_prepend,
+ * error_append_hint or dereference *errp. It's still safe (but useless) in
+ * other cases.

include/qapi/error.h void error_set_internal(Error **errp, · line 376

Quoted 10 lines
include/qapi/error.h +10 -0
+ *
+ * If errp is NULL or points to error_fatal, it is rewritten to point to a
+ * local Error object, which will be automatically propagated to the original
+ * errp on function exit (see error_propagator_cleanup).
+ *
+ * After invocation of this macro it is always safe to dereference errp
+ * (as it's not NULL anymore) and to add information (by error_prepend or
+ * error_append_hint)
+ * (as, if it was error_fatal, we swapped it with a local_error to be
+ * propagated on cleanup).

Nice improvements. Minor drawback, the abort()/exit() will now take place when going out of scope and running the cleanup instead of error location. Not a big problem I guess.

Quoted 13 lines
include/qapi/error.h +9 -1
+ *
+ * Note: we don't wrap the error_abort case, as we want resulting coredump
+ * to point to the place where the error happened, not to error_propagate.
+ */
+#define ERRP_AUTO_PROPAGATE()                                  \
+    g_auto(ErrorPropagator) _auto_errp_prop = {.errp = errp};  \
+    errp = ((errp == NULL || *errp == error_fatal)             \
+            ? &_auto_errp_prop.local_err : errp)
+
 /*
  * Special error destination to abort on error.
  * See error_setg() and error_propagate() for details.
--
Quoted 3 lines

2.21.0

Signature · 1 line
Marc-André Lureau
#48 lore raw
Quoted 18 lines · Marc-André Lureau
Quoted 9 lines

+/*
+ * ERRP_AUTO_PROPAGATE
+ *
+ * This macro is created to be the first line of a function with Error **errp
+ * OUT parameter. It's needed only in cases where we want to use error_prepend,
+ * error_append_hint or dereference *errp. It's still safe (but useless) in
+ * other cases.
+ *
+ * If errp is NULL or points to error_fatal, it is rewritten to point to a

Quoted 8 lines

+ * local Error object, which will be automatically propagated to the original
+ * errp on function exit (see error_propagator_cleanup).
+ *
+ * After invocation of this macro it is always safe to dereference errp
+ * (as it's not NULL anymore) and to add information (by error_prepend or
+ * error_append_hint)
+ * (as, if it was error_fatal, we swapped it with a local_error to be
+ * propagated on cleanup).

Quoted 3 lines

Nice improvements. Minor drawback, the abort()/exit() will now take place when going out of scope and running the cleanup instead of error location. Not a big problem I guess.

Your assessment is not quite right:

Any abort() will happen at the leaf node (because we are no longer wrapping thing into a local err and skipping error_propagate altogether for &error_abort).

You are correct that any exit() will now happen during cleanup, but that is an undetectable change (there is no stack trace present for &error_fatal, so calling error_propagate at a later point in time does not affect the observable end behavior).

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org
#49 lore raw
In reply to Vladimir Sementsov-Ogievskiy
Quoted 5 lines · Vladimir Sementsov-Ogievskiy

Here is introduced ERRP_AUTO_PROPAGATE macro, to be used at start of functions with errp OUT parameter.

It has three goals:

Quoted 7 lines

1. Fix issue with error_fatal & error_prepend/error_append_hint: user can't see this additional information, because exit() happens in error_setg earlier than information is added. [Reported by Greg Kurz]

2. Fix issue with error_abort & error_propagate: when we wrap error_abort by local_err+error_propagate, resulting coredump will refer to error_propagate and not to the place where error happened.

I get what you mean, but I have plenty of context.

Quoted 2 lines

(the macro itself doesn't fix the issue, but it allows to [3.] drop all local_err+error_propagate pattern, which will definitely fix the issue)

The parenthesis is not part of the goal.

Quoted 7 lines

[Reported by Kevin Wolf]

3. Drop local_err+error_propagate pattern, which is used to workaround void functions with errp parameter, when caller wants to know resulting status. (Note: actually these functions could be merely updated to return int error code).

Quoted 5 lines

To achieve these goals, we need to add invocation of the macro at start of functions, which needs error_prepend/error_append_hint (1.); add invocation of the macro at start of functions which do local_err+error_propagate scenario the check errors, drop local errors from them and just use *errp instead (2., 3.).

The paragraph talks about two cases: 1. and 2.+3. Makes me think we want two paragraphs, each illustrated with an example.

What about you provide the examples, and then I try to polish the prose?

Quoted 148 lines

---

CC Gerd Hoffmann <[email protected]>
CC "Gonglei (Arei)" <[email protected]>
CC Eduardo Habkost <[email protected]>
CC Igor Mammedov <[email protected]>
CC Laurent Vivier <[email protected]>
CC Amit Shah <[email protected]>
CC Kevin Wolf <[email protected]>
CC Max Reitz <[email protected]>
CC John Snow <[email protected]>
CC Ari Sundholm <[email protected]>
CC Pavel Dovgalyuk <[email protected]>
CC Paolo Bonzini <[email protected]>
CC Stefan Hajnoczi <[email protected]>
CC Fam Zheng <[email protected]>
CC Stefan Weil <[email protected]>
CC Ronnie Sahlberg <[email protected]>
CC Peter Lieven <[email protected]>
CC Eric Blake <[email protected]>
CC "Denis V. Lunev" <[email protected]>
CC Markus Armbruster <[email protected]>
CC Alberto Garcia <[email protected]>
CC Jason Dillaman <[email protected]>
CC Wen Congyang <[email protected]>
CC Xie Changlong <[email protected]>
CC Liu Yuan <[email protected]>
CC "Richard W.M. Jones" <[email protected]>
CC Jeff Cody <[email protected]>
CC "Marc-André Lureau" <[email protected]>
CC "Daniel P. Berrangé" <[email protected]>
CC Richard Henderson <[email protected]>
CC Greg Kurz <[email protected]>
CC "Michael S. Tsirkin" <[email protected]>
CC Marcel Apfelbaum <[email protected]>
CC Beniamino Galvani <[email protected]>
CC Peter Maydell <[email protected]>
CC "Cédric Le Goater" <[email protected]>
CC Andrew Jeffery <[email protected]>
CC Joel Stanley <[email protected]>
CC Andrew Baumann <[email protected]>
CC "Philippe Mathieu-Daudé" <[email protected]>
CC Antony Pavlov <[email protected]>
CC Jean-Christophe Dubois <[email protected]>
CC Peter Chubb <[email protected]>
CC Subbaraya Sundeep <[email protected]>
CC Eric Auger <[email protected]>
CC Alistair Francis <[email protected]>
CC "Edgar E. Iglesias" <[email protected]>
CC Stefano Stabellini <[email protected]>
CC Anthony Perard <[email protected]>
CC Paul Durrant <[email protected]>
CC Paul Burton <[email protected]>
CC Aleksandar Rikalo <[email protected]>
CC Chris Wulff <[email protected]>
CC Marek Vasut <[email protected]>
CC David Gibson <[email protected]>
CC Cornelia Huck <[email protected]>
CC Halil Pasic <[email protected]>
CC Christian Borntraeger <[email protected]>
CC "Hervé Poussineau" <[email protected]>
CC Xiao Guangrong <[email protected]>
CC Aurelien Jarno <[email protected]>
CC Aleksandar Markovic <[email protected]>
CC Mark Cave-Ayland <[email protected]>
CC Jason Wang <[email protected]>
CC Laszlo Ersek <[email protected]>
CC Yuval Shaia <[email protected]>
CC Palmer Dabbelt <[email protected]>
CC Sagar Karandikar <[email protected]>
CC Bastian Koppelmann <[email protected]>
CC David Hildenbrand <[email protected]>
CC Thomas Huth <[email protected]>
CC Eric Farman <[email protected]>
CC Matthew Rosato <[email protected]>
CC Hannes Reinecke <[email protected]>
CC Michael Walle <[email protected]>
CC Artyom Tarasenko <[email protected]>
CC Stefan Berger <[email protected]>
CC Samuel Thibault <[email protected]>
CC Alex Williamson <[email protected]>
CC Tony Krowiak <[email protected]>
CC Pierre Morel <[email protected]>
CC Michael Roth <[email protected]>
CC Hailiang Zhang <[email protected]>
CC Juan Quintela <[email protected]>
CC "Dr. David Alan Gilbert" <[email protected]>
CC Luigi Rizzo <[email protected]>
CC Giuseppe Lettieri <[email protected]>
CC Vincenzo Maffione <[email protected]>
CC Jan Kiszka <[email protected]>
CC Anthony Green <[email protected]>
CC Stafford Horne <[email protected]>
CC Guan Xuetao <[email protected]>
CC Max Filippov <[email protected]>
 include/qapi/error.h | 38 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)
include/qapi/error.h +31 -0
index d6898d833b..47238d9065 100644
@@ -345,6 +345,44 @@ void error_set_internal(Error **errp,
                         ErrorClass err_class, const char *fmt, ...)
     GCC_FMT_ATTR(6, 7);
 
+typedef struct ErrorPropagator {
+    Error *local_err;
+    Error **errp;
+} ErrorPropagator;
+
+static inline void error_propagator_cleanup(ErrorPropagator *prop)
+{
+    error_propagate(prop->errp, prop->local_err);
+}
+
+G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(ErrorPropagator, error_propagator_cleanup);
+
+/*
+ * ERRP_AUTO_PROPAGATE
+ *
+ * This macro is created to be the first line of a function with Error **errp
+ * OUT parameter. It's needed only in cases where we want to use error_prepend,
+ * error_append_hint or dereference *errp. It's still safe (but useless) in
+ * other cases.
+ *
+ * If errp is NULL or points to error_fatal, it is rewritten to point to a
+ * local Error object, which will be automatically propagated to the original
+ * errp on function exit (see error_propagator_cleanup).
+ *
+ * After invocation of this macro it is always safe to dereference errp
+ * (as it's not NULL anymore) and to add information (by error_prepend or
+ * error_append_hint)
+ * (as, if it was error_fatal, we swapped it with a local_error to be
+ * propagated on cleanup).
+ *
+ * Note: we don't wrap the error_abort case, as we want resulting coredump

include/qapi/error.h void error_set_internal(Error **errp, · line 388

Quoted 10 lines
include/qapi/error.h +7 -0
+ * to point to the place where the error happened, not to error_propagate.
+ */
+#define ERRP_AUTO_PROPAGATE()                                  \
+    g_auto(ErrorPropagator) _auto_errp_prop = {.errp = errp};  \
+    errp = ((errp == NULL || *errp == error_fatal)             \
+            ? &_auto_errp_prop.local_err : errp)
+
 /*
  * Special error destination to abort on error.
  * See error_setg() and error_propagate() for details.

Missing: update of the big comment starting with "Error reporting system loosely patterned after Glib's GError."

#50 lore raw
Quoted 29 lines · Markus Armbruster
Quoted 5 lines · Vladimir Sementsov-Ogievskiy

Here is introduced ERRP_AUTO_PROPAGATE macro, to be used at start of functions with errp OUT parameter.

It has three goals:

Quoted 7 lines

1. Fix issue with error_fatal & error_prepend/error_append_hint: user can't see this additional information, because exit() happens in error_setg earlier than information is added. [Reported by Greg Kurz]

2. Fix issue with error_abort & error_propagate: when we wrap error_abort by local_err+error_propagate, resulting coredump will refer to error_propagate and not to the place where error happened.

I get what you mean, but I have plenty of context.

Quoted 2 lines

(the macro itself doesn't fix the issue, but it allows to [3.] drop all local_err+error_propagate pattern, which will definitely fix the issue)

The parenthesis is not part of the goal.

Quoted 7 lines

[Reported by Kevin Wolf]

3. Drop local_err+error_propagate pattern, which is used to workaround void functions with errp parameter, when caller wants to know resulting status. (Note: actually these functions could be merely updated to return int error code).

Quoted 7 lines
Quoted 5 lines

To achieve these goals, we need to add invocation of the macro at start of functions, which needs error_prepend/error_append_hint (1.); add invocation of the macro at start of functions which do local_err+error_propagate scenario the check errors, drop local errors from them and just use *errp instead (2., 3.).

The paragraph talks about two cases: 1. and 2.+3.

Hmm, I don't think so.. 1. and 2. are issues. 3. is a refactoring.. We just fix achieve 2 and 3 by one action.

Quoted 4 lines

Makes me think we
want two paragraphs, each illustrated with an example.

What about you provide the examples, and then I try to polish the prose?

1: error_fatal problem

Assume the following code flow:

int f1(errp) {
    ...
    ret = f2(errp);
    if (ret < 0) {
       error_append_hint(errp, "very useful hint");
       return ret;
    }
    ...
}

Now, if we call f1 with &error_fatal argument and f2 fails, the program will exit immediately inside f2, when setting the errp. User will not see the hint.

So, in this case we should use local_err.

2: error_abort problem

Now, consider functions without return value. We normally use local_err variable to catch failures:

void f1(errp) {
    Error *local_err = NULL;
    ...
    f2(&local_err);
    if (local_err) {
        error_propagate(errp, local_err);
        return;
    }
    ...
}

Now, if we call f2 with &error_abort and f2 fails, the stack in resulting crash dump will point to error_propagate, not to the failure point in f2, which complicates debugging.

So, we should never wrap error_abort by local_err.

===

Our solution:

- Fixes [1.], adding invocation of new macro into functions with error_appen_hint/error_prepend, New macro will wrap error_fatal.
- Fixes [2.], by switching from hand-written local_err to smart macro, which never wraps error_abort.
- Handles [3.], by switching to macro, which is less code
- Additionally, macro doesn't wrap normal non-zero errp, to avoid extra propagations (in fact, error_propagate is called, but returns immediately on first if (!local_err))

Quoted 163 lines
Quoted 149 lines

---

CC Gerd Hoffmann <[email protected]>
CC "Gonglei (Arei)" <[email protected]>
CC Eduardo Habkost <[email protected]>
CC Igor Mammedov <[email protected]>
CC Laurent Vivier <[email protected]>
CC Amit Shah <[email protected]>
CC Kevin Wolf <[email protected]>
CC Max Reitz <[email protected]>
CC John Snow <[email protected]>
CC Ari Sundholm <[email protected]>
CC Pavel Dovgalyuk <[email protected]>
CC Paolo Bonzini <[email protected]>
CC Stefan Hajnoczi <[email protected]>
CC Fam Zheng <[email protected]>
CC Stefan Weil <[email protected]>
CC Ronnie Sahlberg <[email protected]>
CC Peter Lieven <[email protected]>
CC Eric Blake <[email protected]>
CC "Denis V. Lunev" <[email protected]>
CC Markus Armbruster <[email protected]>
CC Alberto Garcia <[email protected]>
CC Jason Dillaman <[email protected]>
CC Wen Congyang <[email protected]>
CC Xie Changlong <[email protected]>
CC Liu Yuan <[email protected]>
CC "Richard W.M. Jones" <[email protected]>
CC Jeff Cody <[email protected]>
CC "Marc-André Lureau" <[email protected]>
CC "Daniel P. Berrangé" <[email protected]>
CC Richard Henderson <[email protected]>
CC Greg Kurz <[email protected]>
CC "Michael S. Tsirkin" <[email protected]>
CC Marcel Apfelbaum <[email protected]>
CC Beniamino Galvani <[email protected]>
CC Peter Maydell <[email protected]>
CC "Cédric Le Goater" <[email protected]>
CC Andrew Jeffery <[email protected]>
CC Joel Stanley <[email protected]>
CC Andrew Baumann <[email protected]>
CC "Philippe Mathieu-Daudé" <[email protected]>
CC Antony Pavlov <[email protected]>
CC Jean-Christophe Dubois <[email protected]>
CC Peter Chubb <[email protected]>
CC Subbaraya Sundeep <[email protected]>
CC Eric Auger <[email protected]>
CC Alistair Francis <[email protected]>
CC "Edgar E. Iglesias" <[email protected]>
CC Stefano Stabellini <[email protected]>
CC Anthony Perard <[email protected]>
CC Paul Durrant <[email protected]>
CC Paul Burton <[email protected]>
CC Aleksandar Rikalo <[email protected]>
CC Chris Wulff <[email protected]>
CC Marek Vasut <[email protected]>
CC David Gibson <[email protected]>
CC Cornelia Huck <[email protected]>
CC Halil Pasic <[email protected]>
CC Christian Borntraeger <[email protected]>
CC "Hervé Poussineau" <[email protected]>
CC Xiao Guangrong <[email protected]>
CC Aurelien Jarno <[email protected]>
CC Aleksandar Markovic <[email protected]>
CC Mark Cave-Ayland <[email protected]>
CC Jason Wang <[email protected]>
CC Laszlo Ersek <[email protected]>
CC Yuval Shaia <[email protected]>
CC Palmer Dabbelt <[email protected]>
CC Sagar Karandikar <[email protected]>
CC Bastian Koppelmann <[email protected]>
CC David Hildenbrand <[email protected]>
CC Thomas Huth <[email protected]>
CC Eric Farman <[email protected]>
CC Matthew Rosato <[email protected]>
CC Hannes Reinecke <[email protected]>
CC Michael Walle <[email protected]>
CC Artyom Tarasenko <[email protected]>
CC Stefan Berger <[email protected]>
CC Samuel Thibault <[email protected]>
CC Alex Williamson <[email protected]>
CC Tony Krowiak <[email protected]>
CC Pierre Morel <[email protected]>
CC Michael Roth <[email protected]>
CC Hailiang Zhang <[email protected]>
CC Juan Quintela <[email protected]>
CC "Dr. David Alan Gilbert" <[email protected]>
CC Luigi Rizzo <[email protected]>
CC Giuseppe Lettieri <[email protected]>
CC Vincenzo Maffione <[email protected]>
CC Jan Kiszka <[email protected]>
CC Anthony Green <[email protected]>
CC Stafford Horne <[email protected]>
CC Guan Xuetao <[email protected]>
CC Max Filippov <[email protected]>
  include/qapi/error.h | 38 ++++++++++++++++++++++++++++++++++++++
  1 file changed, 38 insertions(+)
include/qapi/error.h +31 -0
index d6898d833b..47238d9065 100644
@@ -345,6 +345,44 @@ void error_set_internal(Error **errp,
                          ErrorClass err_class, const char *fmt, ...)
      GCC_FMT_ATTR(6, 7);
 
+typedef struct ErrorPropagator {
+    Error *local_err;
+    Error **errp;
+} ErrorPropagator;
+
+static inline void error_propagator_cleanup(ErrorPropagator *prop)
+{
+    error_propagate(prop->errp, prop->local_err);
+}
+
+G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(ErrorPropagator, error_propagator_cleanup);
+
+/*
+ * ERRP_AUTO_PROPAGATE
+ *
+ * This macro is created to be the first line of a function with Error **errp
+ * OUT parameter. It's needed only in cases where we want to use error_prepend,
+ * error_append_hint or dereference *errp. It's still safe (but useless) in
+ * other cases.
+ *
+ * If errp is NULL or points to error_fatal, it is rewritten to point to a
+ * local Error object, which will be automatically propagated to the original
+ * errp on function exit (see error_propagator_cleanup).
+ *
+ * After invocation of this macro it is always safe to dereference errp
+ * (as it's not NULL anymore) and to add information (by error_prepend or
+ * error_append_hint)
+ * (as, if it was error_fatal, we swapped it with a local_error to be
+ * propagated on cleanup).
+ *
+ * Note: we don't wrap the error_abort case, as we want resulting coredump

include/qapi/error.h void error_set_internal(Error **errp, · line 388

Quoted 10 lines
include/qapi/error.h +7 -0
+ * to point to the place where the error happened, not to error_propagate.
+ */
+#define ERRP_AUTO_PROPAGATE()                                  \
+    g_auto(ErrorPropagator) _auto_errp_prop = {.errp = errp};  \
+    errp = ((errp == NULL || *errp == error_fatal)             \
+            ? &_auto_errp_prop.local_err : errp)
+
  /*
   * Special error destination to abort on error.
   * See error_setg() and error_propagate() for details.

Missing: update of the big comment starting with "Error reporting system loosely patterned after Glib's GError."

Signature · 2 lines
Best regards,
Vladimir
#51 lore raw
Quoted 60 lines · Vladimir Sementsov-Ogievskiy
Quoted 29 lines · Markus Armbruster
Quoted 5 lines · Vladimir Sementsov-Ogievskiy

Here is introduced ERRP_AUTO_PROPAGATE macro, to be used at start of functions with errp OUT parameter.

It has three goals:

Quoted 7 lines

1. Fix issue with error_fatal & error_prepend/error_append_hint: user can't see this additional information, because exit() happens in error_setg earlier than information is added. [Reported by Greg Kurz]

2. Fix issue with error_abort & error_propagate: when we wrap error_abort by local_err+error_propagate, resulting coredump will refer to error_propagate and not to the place where error happened.

I get what you mean, but I have plenty of context.

Quoted 2 lines

(the macro itself doesn't fix the issue, but it allows to [3.] drop all local_err+error_propagate pattern, which will definitely fix the issue)

The parenthesis is not part of the goal.

Quoted 7 lines

[Reported by Kevin Wolf]

3. Drop local_err+error_propagate pattern, which is used to workaround void functions with errp parameter, when caller wants to know resulting status. (Note: actually these functions could be merely updated to return int error code).

Quoted 7 lines
Quoted 5 lines

To achieve these goals, we need to add invocation of the macro at start of functions, which needs error_prepend/error_append_hint (1.); add invocation of the macro at start of functions which do local_err+error_propagate scenario the check errors, drop local errors from them and just use *errp instead (2., 3.).

The paragraph talks about two cases: 1. and 2.+3.

Hmm, I don't think so.. 1. and 2. are issues. 3. is a refactoring.. We just fix achieve 2 and 3 by one action.

Quoted 4 lines

Makes me think we
want two paragraphs, each illustrated with an example.

What about you provide the examples, and then I try to polish the prose?

1: error_fatal problem

Assume the following code flow:

int f1(errp) {
    ...
    ret = f2(errp);
    if (ret < 0) {
       error_append_hint(errp, "very useful hint");
       return ret;
    }
    ...
}
Quoted 5 lines

Now, if we call f1 with &error_fatal argument and f2 fails, the program will exit immediately inside f2, when setting the errp. User will not see the hint.

So, in this case we should use local_err.

How does this example look after the transformation?

Quoted 16 lines

2: error_abort problem

Now, consider functions without return value. We normally use local_err variable to catch failures:

void f1(errp) {
    Error *local_err = NULL;
    ...
    f2(&local_err);
    if (local_err) {
        error_propagate(errp, local_err);
        return;
    }
    ...
}
Quoted 5 lines

Now, if we call f2 with &error_abort and f2 fails, the stack in resulting crash dump will point to error_propagate, not to the failure point in f2, which complicates debugging.

So, we should never wrap error_abort by local_err.

Likewise.

Quoted 12 lines

===

Our solution:

- Fixes [1.], adding invocation of new macro into functions with error_appen_hint/error_prepend, New macro will wrap error_fatal.
- Fixes [2.], by switching from hand-written local_err to smart macro, which never wraps error_abort.
- Handles [3.], by switching to macro, which is less code
- Additionally, macro doesn't wrap normal non-zero errp, to avoid extra propagations (in fact, error_propagate is called, but returns immediately on first if (!local_err))

#52 lore raw
Quoted 62 lines · Markus Armbruster
Quoted 60 lines · Vladimir Sementsov-Ogievskiy
Quoted 29 lines · Markus Armbruster
Quoted 5 lines · Vladimir Sementsov-Ogievskiy

Here is introduced ERRP_AUTO_PROPAGATE macro, to be used at start of functions with errp OUT parameter.

It has three goals:

Quoted 7 lines

1. Fix issue with error_fatal & error_prepend/error_append_hint: user can't see this additional information, because exit() happens in error_setg earlier than information is added. [Reported by Greg Kurz]

2. Fix issue with error_abort & error_propagate: when we wrap error_abort by local_err+error_propagate, resulting coredump will refer to error_propagate and not to the place where error happened.

I get what you mean, but I have plenty of context.

Quoted 2 lines

(the macro itself doesn't fix the issue, but it allows to [3.] drop all local_err+error_propagate pattern, which will definitely fix the issue)

The parenthesis is not part of the goal.

Quoted 7 lines

[Reported by Kevin Wolf]

3. Drop local_err+error_propagate pattern, which is used to workaround void functions with errp parameter, when caller wants to know resulting status. (Note: actually these functions could be merely updated to return int error code).

Quoted 7 lines
Quoted 5 lines

To achieve these goals, we need to add invocation of the macro at start of functions, which needs error_prepend/error_append_hint (1.); add invocation of the macro at start of functions which do local_err+error_propagate scenario the check errors, drop local errors from them and just use *errp instead (2., 3.).

The paragraph talks about two cases: 1. and 2.+3.

Hmm, I don't think so.. 1. and 2. are issues. 3. is a refactoring.. We just fix achieve 2 and 3 by one action.

Quoted 4 lines

Makes me think we
want two paragraphs, each illustrated with an example.

What about you provide the examples, and then I try to polish the prose?

1: error_fatal problem

Assume the following code flow:

int f1(errp) {
     ...
     ret = f2(errp);
     if (ret < 0) {
        error_append_hint(errp, "very useful hint");
        return ret;
     }
     ...
}
Quoted 7 lines
Quoted 5 lines

Now, if we call f1 with &error_fatal argument and f2 fails, the program will exit immediately inside f2, when setting the errp. User will not see the hint.

So, in this case we should use local_err.

How does this example look after the transformation?

Good point.

int f1(errp) {
    ERRP_AUTO_PROPAGATE();
    ...
    ret = f2(errp);
    if (ret < 0) {
       error_append_hint(errp, "very useful hint");
       return ret;
    }
    ...
}

- nothing changed, only add macro at start. But now errp is safe, if it was error_fatal it is wrapped by local error, and will only call exit on automatic propagation on f1 finish.

Quoted 17 lines
Quoted 17 lines

2: error_abort problem

Now, consider functions without return value. We normally use local_err variable to catch failures:

void f1(errp) {
     Error *local_err = NULL;
     ...
     f2(&local_err);
     if (local_err) {
         error_propagate(errp, local_err);
         return;
     }
     ...
}
Quoted 7 lines
Quoted 5 lines

Now, if we call f2 with &error_abort and f2 fails, the stack in resulting crash dump will point to error_propagate, not to the failure point in f2, which complicates debugging.

So, we should never wrap error_abort by local_err.

Likewise.

And here:

void f1(errp) {
     ERRP_AUTO_PROPAGATE();
     ...
     f2(errp);
     if (*errp) {
         return;
     }
     ...

- if errp was NULL, it is wrapped, so dereferencing errp is safe. On return, local error is automatically propagated to original one.

Quoted 14 lines
Quoted 13 lines

===

Our solution:

- Fixes [1.], adding invocation of new macro into functions with error_appen_hint/error_prepend, New macro will wrap error_fatal.
- Fixes [2.], by switching from hand-written local_err to smart macro, which never wraps error_abort.
- Handles [3.], by switching to macro, which is less code
- Additionally, macro doesn't wrap normal non-zero errp, to avoid extra propagations (in fact, error_propagate is called, but returns immediately on first if (!local_err))

Signature · 2 lines
Best regards,
Vladimir
#53 lore raw
Quoted 124 lines · Vladimir Sementsov-Ogievskiy
Quoted 62 lines · Markus Armbruster
Quoted 60 lines · Vladimir Sementsov-Ogievskiy
Quoted 29 lines · Markus Armbruster
Quoted 5 lines · Vladimir Sementsov-Ogievskiy

Here is introduced ERRP_AUTO_PROPAGATE macro, to be used at start of functions with errp OUT parameter.

It has three goals:

Quoted 7 lines

1. Fix issue with error_fatal & error_prepend/error_append_hint: user can't see this additional information, because exit() happens in error_setg earlier than information is added. [Reported by Greg Kurz]

2. Fix issue with error_abort & error_propagate: when we wrap error_abort by local_err+error_propagate, resulting coredump will refer to error_propagate and not to the place where error happened.

I get what you mean, but I have plenty of context.

Quoted 2 lines

(the macro itself doesn't fix the issue, but it allows to [3.] drop all local_err+error_propagate pattern, which will definitely fix the issue)

The parenthesis is not part of the goal.

Quoted 7 lines

[Reported by Kevin Wolf]

3. Drop local_err+error_propagate pattern, which is used to workaround void functions with errp parameter, when caller wants to know resulting status. (Note: actually these functions could be merely updated to return int error code).

Quoted 7 lines
Quoted 5 lines

To achieve these goals, we need to add invocation of the macro at start of functions, which needs error_prepend/error_append_hint (1.); add invocation of the macro at start of functions which do local_err+error_propagate scenario the check errors, drop local errors from them and just use *errp instead (2., 3.).

The paragraph talks about two cases: 1. and 2.+3.

Hmm, I don't think so.. 1. and 2. are issues. 3. is a refactoring.. We just fix achieve 2 and 3 by one action.

Quoted 4 lines

Makes me think we
want two paragraphs, each illustrated with an example.

What about you provide the examples, and then I try to polish the prose?

1: error_fatal problem

Assume the following code flow:

int f1(errp) {
      ...
      ret = f2(errp);
      if (ret < 0) {
         error_append_hint(errp, "very useful hint");
         return ret;
      }
      ...
}
Quoted 7 lines
Quoted 5 lines

Now, if we call f1 with &error_fatal argument and f2 fails, the program will exit immediately inside f2, when setting the errp. User will not see the hint.

So, in this case we should use local_err.

How does this example look after the transformation?

Good point.

int f1(errp) {
     ERRP_AUTO_PROPAGATE();
     ...
     ret = f2(errp);
     if (ret < 0) {
        error_append_hint(errp, "very useful hint");
        return ret;
     }
     ...
}

- nothing changed, only add macro at start. But now errp is safe, if it was error_fatal it is wrapped by local error, and will only call exit on automatic propagation on f1 finish.

Quoted 17 lines
Quoted 17 lines

2: error_abort problem

Now, consider functions without return value. We normally use local_err variable to catch failures:

void f1(errp) {
      Error *local_err = NULL;
      ...
      f2(&local_err);
      if (local_err) {
          error_propagate(errp, local_err);
          return;
      }
      ...
}
Quoted 7 lines
Quoted 5 lines

Now, if we call f2 with &error_abort and f2 fails, the stack in resulting crash dump will point to error_propagate, not to the failure point in f2, which complicates debugging.

So, we should never wrap error_abort by local_err.

Likewise.

And here:

void f1(errp) {
      ERRP_AUTO_PROPAGATE();
      ...
      f2(errp);
      if (*errp) {
          return;
      }
      ...
Quoted 2 lines

- if errp was NULL, it is wrapped, so dereferencing errp is safe. On return, local error is automatically propagated to original one.

and if it was error_abort, it is not wrapped, so will crash where failed.

Quoted 17 lines
Quoted 15 lines
Quoted 14 lines

===

Our solution:

- Fixes [1.], adding invocation of new macro into functions with error_appen_hint/error_prepend, New macro will wrap error_fatal.
- Fixes [2.], by switching from hand-written local_err to smart macro, which never wraps error_abort.
- Handles [3.], by switching to macro, which is less code
- Additionally, macro doesn't wrap normal non-zero errp, to avoid extra propagations (in fact, error_propagate is called, but returns immediately on first if (!local_err))

Signature · 2 lines
Best regards,
Vladimir
#54 lore raw
Quoted 125 lines · Vladimir Sementsov-Ogievskiy
Quoted 124 lines · Vladimir Sementsov-Ogievskiy
Quoted 62 lines · Markus Armbruster
Quoted 60 lines · Vladimir Sementsov-Ogievskiy
Quoted 29 lines · Markus Armbruster
Quoted 5 lines · Vladimir Sementsov-Ogievskiy

Here is introduced ERRP_AUTO_PROPAGATE macro, to be used at start of functions with errp OUT parameter.

It has three goals:

Quoted 7 lines

1. Fix issue with error_fatal & error_prepend/error_append_hint: user can't see this additional information, because exit() happens in error_setg earlier than information is added. [Reported by Greg Kurz]

2. Fix issue with error_abort & error_propagate: when we wrap error_abort by local_err+error_propagate, resulting coredump will refer to error_propagate and not to the place where error happened.

I get what you mean, but I have plenty of context.

Quoted 2 lines

(the macro itself doesn't fix the issue, but it allows to [3.] drop all local_err+error_propagate pattern, which will definitely fix the issue)

The parenthesis is not part of the goal.

Quoted 7 lines

[Reported by Kevin Wolf]

3. Drop local_err+error_propagate pattern, which is used to workaround void functions with errp parameter, when caller wants to know resulting status. (Note: actually these functions could be merely updated to return int error code).

Quoted 7 lines
Quoted 5 lines

To achieve these goals, we need to add invocation of the macro at start of functions, which needs error_prepend/error_append_hint (1.); add invocation of the macro at start of functions which do local_err+error_propagate scenario the check errors, drop local errors from them and just use *errp instead (2., 3.).

The paragraph talks about two cases: 1. and 2.+3.

Hmm, I don't think so.. 1. and 2. are issues. 3. is a refactoring.. We just fix achieve 2 and 3 by one action.

Quoted 4 lines

Makes me think we
want two paragraphs, each illustrated with an example.

What about you provide the examples, and then I try to polish the prose?

1: error_fatal problem

Assume the following code flow:

int f1(errp) {
      ...
      ret = f2(errp);
      if (ret < 0) {
         error_append_hint(errp, "very useful hint");
         return ret;
      }
      ...
}
Quoted 7 lines
Quoted 5 lines

Now, if we call f1 with &error_fatal argument and f2 fails, the program will exit immediately inside f2, when setting the errp. User will not see the hint.

So, in this case we should use local_err.

How does this example look after the transformation?

Good point.

int f1(errp) {
     ERRP_AUTO_PROPAGATE();
     ...
     ret = f2(errp);
     if (ret < 0) {
        error_append_hint(errp, "very useful hint");
        return ret;
     }
     ...
}

- nothing changed, only add macro at start. But now errp is safe, if it was error_fatal it is wrapped by local error, and will only call exit on automatic propagation on f1 finish.

Quoted 17 lines
Quoted 17 lines

2: error_abort problem

Now, consider functions without return value. We normally use local_err variable to catch failures:

void f1(errp) {
      Error *local_err = NULL;
      ...
      f2(&local_err);
      if (local_err) {
          error_propagate(errp, local_err);
          return;
      }
      ...
}
Quoted 7 lines
Quoted 5 lines

Now, if we call f2 with &error_abort and f2 fails, the stack in resulting crash dump will point to error_propagate, not to the failure point in f2, which complicates debugging.

So, we should never wrap error_abort by local_err.

Likewise.

And here:

void f1(errp) {
      ERRP_AUTO_PROPAGATE();
      ...
      f2(errp);
      if (*errp) {
          return;
      }
      ...
Quoted 4 lines
Quoted 2 lines

- if errp was NULL, it is wrapped, so dereferencing errp is safe. On return, local error is automatically propagated to original one.

and if it was error_abort, it is not wrapped, so will crash where failed.

We still need to avoid passing on unwrapped @errp when we want to ignore some errors, as in fit_load_fdt(), but that should be quite rare. Doesn't invalidate your approach.

[...]

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#55 lore raw
In reply to Vladimir Sementsov-Ogievskiy
Quoted 16 lines · Vladimir Sementsov-Ogievskiy
Quoted 16 lines
Quoted 16 lines
Quoted 1 line

What about you provide the examples, and then I try to polish the prose?

1: error_fatal problem

Assume the following code flow:

int f1(errp) {
      ...
      ret = f2(errp);
      if (ret < 0) {
         error_append_hint(errp, "very useful hint");
         return ret;
      }
      ...
}
Quoted 7 lines
Quoted 7 lines
Quoted 5 lines

Now, if we call f1 with &error_fatal argument and f2 fails, the program will exit immediately inside f2, when setting the errp. User will not see the hint.

So, in this case we should use local_err.

How does this example look after the transformation?

Without ERRP_AUTO_PROPAGATE(), the transformation is a lot of boilerplate:

int f1(errp) {
    Error *err = NULL;
    ret = f2(&err);
    if (ret < 0) {
        error_append_hint(&err, "very useful hint");
        error_propagate(errp, err);
        return ret;
    }
}

what's worse, that boilerplate to solve problem 1 turns out to be...

Quoted 14 lines

Good point.

int f1(errp) {
     ERRP_AUTO_PROPAGATE();
     ...
     ret = f2(errp);
     if (ret < 0) {
        error_append_hint(errp, "very useful hint");
        return ret;
     }
     ...
}
Quoted 20 lines

- nothing changed, only add macro at start. But now errp is safe, if it was error_fatal it is wrapped by local error, and will only call exit on automatic propagation on f1 finish.

Quoted 16 lines
Quoted 16 lines

2: error_abort problem

Now, consider functions without return value. We normally use local_err variable to catch failures:

void f1(errp) {
      Error *local_err = NULL;
      ...
      f2(&local_err);
      if (local_err) {
          error_propagate(errp, local_err);
          return;
      }
      ...
}

the very same code as the cause of problem 2.

Quoted 20 lines
Quoted 8 lines
Quoted 6 lines

Now, if we call f2 with &error_abort and f2 fails, the stack in resulting crash dump will point to error_propagate, not to the failure point in f2, which complicates debugging.

So, we should never wrap error_abort by local_err.

Likewise.

And here:

void f1(errp) {
      ERRP_AUTO_PROPAGATE();
      ...
      f2(errp);
      if (*errp) {
          return;
      }
      ...
Quoted 2 lines

- if errp was NULL, it is wrapped, so dereferencing errp is safe. On return, local error is automatically propagated to original one.

So, the use of ERRP_AUTO_PROPAGATE() solves BOTH problems 1 and 2 - we avoid the boilerplate that trades one problem for another, by consolidating ALL of the boilerplate into a single-line macro, such that error_propagate() no longer needs to be called anywhere except inside the ERRP_AUTO_PROPAGATE macro.

Quoted 17 lines
Quoted 15 lines
Quoted 14 lines

===

Our solution:

- Fixes [1.], adding invocation of new macro into functions with error_appen_hint/error_prepend, New macro will wrap error_fatal.
- Fixes [2.], by switching from hand-written local_err to smart macro, which never wraps error_abort.
- Handles [3.], by switching to macro, which is less code
- Additionally, macro doesn't wrap normal non-zero errp, to avoid extra propagations (in fact, error_propagate is called, but returns immediately on first if (!local_err))

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org
#56 lore raw

RFC v5 25/126 scripts: add coccinelle script to use auto propagated errp

In reply to Vladimir Sementsov-Ogievskiy

---

CC Gerd Hoffmann <[email protected]>
CC "Gonglei (Arei)" <[email protected]>
CC Eduardo Habkost <[email protected]>
CC Igor Mammedov <[email protected]>
CC Laurent Vivier <[email protected]>
CC Amit Shah <[email protected]>
CC Kevin Wolf <[email protected]>
CC Max Reitz <[email protected]>
CC John Snow <[email protected]>
CC Ari Sundholm <[email protected]>
CC Pavel Dovgalyuk <[email protected]>
CC Paolo Bonzini <[email protected]>
CC Stefan Hajnoczi <[email protected]>
CC Fam Zheng <[email protected]>
CC Stefan Weil <[email protected]>
CC Ronnie Sahlberg <[email protected]>
CC Peter Lieven <[email protected]>
CC Eric Blake <[email protected]>
CC "Denis V. Lunev" <[email protected]>
CC Markus Armbruster <[email protected]>
CC Alberto Garcia <[email protected]>
CC Jason Dillaman <[email protected]>
CC Wen Congyang <[email protected]>
CC Xie Changlong <[email protected]>
CC Liu Yuan <[email protected]>
CC "Richard W.M. Jones" <[email protected]>
CC Jeff Cody <[email protected]>
CC "Marc-André Lureau" <[email protected]>
CC "Daniel P. Berrangé" <[email protected]>
CC Richard Henderson <[email protected]>
CC Greg Kurz <[email protected]>
CC "Michael S. Tsirkin" <[email protected]>
CC Marcel Apfelbaum <[email protected]>
CC Beniamino Galvani <[email protected]>
CC Peter Maydell <[email protected]>
CC "Cédric Le Goater" <[email protected]>
CC Andrew Jeffery <[email protected]>
CC Joel Stanley <[email protected]>
CC Andrew Baumann <[email protected]>
CC "Philippe Mathieu-Daudé" <[email protected]>
CC Antony Pavlov <[email protected]>
CC Jean-Christophe Dubois <[email protected]>
CC Peter Chubb <[email protected]>
CC Subbaraya Sundeep <[email protected]>
CC Eric Auger <[email protected]>
CC Alistair Francis <[email protected]>
CC "Edgar E. Iglesias" <[email protected]>
CC Stefano Stabellini <[email protected]>
CC Anthony Perard <[email protected]>
CC Paul Durrant <[email protected]>
CC Paul Burton <[email protected]>
CC Aleksandar Rikalo <[email protected]>
CC Chris Wulff <[email protected]>
CC Marek Vasut <[email protected]>
CC David Gibson <[email protected]>
CC Cornelia Huck <[email protected]>
CC Halil Pasic <[email protected]>
CC Christian Borntraeger <[email protected]>
CC "Hervé Poussineau" <[email protected]>
CC Xiao Guangrong <[email protected]>
CC Aurelien Jarno <[email protected]>
CC Aleksandar Markovic <[email protected]>
CC Mark Cave-Ayland <[email protected]>
CC Jason Wang <[email protected]>
CC Laszlo Ersek <[email protected]>
CC Yuval Shaia <[email protected]>
CC Palmer Dabbelt <[email protected]>
CC Sagar Karandikar <[email protected]>
CC Bastian Koppelmann <[email protected]>
CC David Hildenbrand <[email protected]>
CC Thomas Huth <[email protected]>
CC Eric Farman <[email protected]>
CC Matthew Rosato <[email protected]>
CC Hannes Reinecke <[email protected]>
CC Michael Walle <[email protected]>
CC Artyom Tarasenko <[email protected]>
CC Stefan Berger <[email protected]>
CC Samuel Thibault <[email protected]>
CC Alex Williamson <[email protected]>
CC Tony Krowiak <[email protected]>
CC Pierre Morel <[email protected]>
CC Michael Roth <[email protected]>
CC Hailiang Zhang <[email protected]>
CC Juan Quintela <[email protected]>
CC "Dr. David Alan Gilbert" <[email protected]>
CC Luigi Rizzo <[email protected]>
CC Giuseppe Lettieri <[email protected]>
CC Vincenzo Maffione <[email protected]>
CC Jan Kiszka <[email protected]>
CC Anthony Green <[email protected]>
CC Stafford Horne <[email protected]>
CC Guan Xuetao <[email protected]>
CC Max Filippov <[email protected]>
 scripts/coccinelle/auto-propagated-errp.cocci | 118 ++++++++++++++++++
 1 file changed, 118 insertions(+)
 create mode 100644 scripts/coccinelle/auto-propagated-errp.cocci
scripts/coccinelle/auto-propagated-errp.cocci new file +118 -0
new file mode 100644
index 0000000000..d9731620aa
@@ -0,0 +1,118 @@
+@rule0@
+// Add invocation to errp-functions where necessary
+identifier fn, local_err;
+symbol errp;
+@@
+
+ fn(..., Error **errp, ...)
+ {
++   ERRP_AUTO_PROPAGATE();
+    <+...
+(
+    error_append_hint(errp, ...);
+|
+    error_prepend(errp, ...);
+|
+    Error *local_err = NULL;
+)
+    ...+>
+ }
+
+@@
+// Drop doubled invocation
+identifier rule0.fn;
+@@
+
+ fn(...)
+{
+-   ERRP_AUTO_PROPAGATE();
+    ERRP_AUTO_PROPAGATE();
+    ...
+}
+
+@rule1@
+// Drop local_err
+identifier fn, local_err;
+symbol errp;
+@@
+
+ fn(..., Error **errp, ...)
+ {
+     <...
+-    Error *local_err = NULL;
+     ...>
+ }
+
+@@
+// Handle pattern with goto, otherwise we'll finish up
+// with labels at function end which will not compile.
+identifier rule1.fn;
+identifier rule1.local_err;
+identifier OUT;
+@@
+
+ fn(...)
+ {
+     <...
+-    goto OUT;
++    return;
+     ...>
+- OUT:
+-    error_propagate(errp, local_err);
+ }
+
+@@
+identifier rule1.fn;
+identifier rule1.local_err;
+@@
+
+ fn(...)
+ {
+     <...
+(
+-    error_free(local_err);
+-    local_err = NULL;
++    error_free_errp(errp);
+|
+-    error_free(local_err);
++    error_free_errp(errp);
+|
+-    error_report_err(local_err);
++    error_report_errp(errp);
+|
+-    warn_report_err(local_err);
++    warn_report_errp(errp);
+|
+-    error_propagate_prepend(errp, local_err,
++    error_prepend(errp,
+                              ...);
+|
+-    error_propagate(errp, local_err);
+)
+     ...>
+ }
+
+@@
+identifier rule1.fn;
+identifier rule1.local_err;
+@@
+
+ fn(...)
+ {
+     <...
+(
+-    &local_err
++    errp
+|
+-    local_err
++    *errp
+)
+     ...>
+ }
+
+@@
+symbol errp;
+@@
+
+- *errp != NULL
++ *errp
Signature · 1 line
2.21.0
#57 lore raw

Re: [RFC v5 025/126] scripts: add coccinelle script to use auto propagated errp

Quoted 17 lines · Vladimir Sementsov-Ogievskiy

---

  scripts/coccinelle/auto-propagated-errp.cocci | 118 ++++++++++++++++++
  1 file changed, 118 insertions(+)

create mode 100644 scripts/coccinelle/auto-propagated-errp.cocci

scripts/coccinelle/auto-propagated-errp.cocci new file +3 -0
new file mode 100644
index 0000000000..d9731620aa
 
+@rule1@
+// Drop local_err
+identifier fn, local_err;

scripts/coccinelle/auto-propagated-errp.cocci line 45

Quoted 10 lines
scripts/coccinelle/auto-propagated-errp.cocci new file +10 -0
+symbol errp;
+@@
+
+ fn(..., Error **errp, ...)
+ {
+     <...
+-    Error *local_err = NULL;
+     ...>
+ }
+

So our goal is to automate removal of all local_err (including when it is spelled err)...

Quoted 8 lines

+@@

scripts/coccinelle/auto-propagated-errp.cocci new file +7 -0
+// Handle pattern with goto, otherwise we'll finish up
+// with labels at function end which will not compile.
+identifier rule1.fn;
+identifier rule1.local_err;
+identifier OUT;
+@@
+

scripts/coccinelle/auto-propagated-errp.cocci line 63

Quoted 10 lines
scripts/coccinelle/auto-propagated-errp.cocci new file +10 -0
+ fn(...)
+ {
+     <...
+-    goto OUT;
++    return;
+     ...>
+- OUT:
+-    error_propagate(errp, local_err);
+ }
+

this dangling label cleanup makes sense

scripts/coccinelle/auto-propagated-errp.cocci line 75

Quoted 12 lines

+@@

scripts/coccinelle/auto-propagated-errp.cocci new file +11 -0
+identifier rule1.fn;
+identifier rule1.local_err;
+@@
+
+ fn(...)
+ {
+     <...
+(
+-    error_free(local_err);
+-    local_err = NULL;
++    error_free_errp(errp);

This does not make sense - error_free_errp() is not defined prior to this series or anywhere in patches 1-24, if I'm reading it correctly.

Quoted 3 lines

+|

+-    error_free(local_err);
++    error_free_errp(errp);

and again

Quoted 9 lines

+|

+-    error_report_err(local_err);
++    error_report_errp(errp);
+|
+-    warn_report_err(local_err);
++    warn_report_errp(errp);
+|
+-    error_propagate_prepend(errp, local_err,
++    error_prepend(errp,

scripts/coccinelle/auto-propagated-errp.cocci line 94

Quoted 7 lines
scripts/coccinelle/auto-propagated-errp.cocci new file +7 -0
+                              ...);
+|
+-    error_propagate(errp, local_err);
+)
+     ...>
+ }
+

It looks like once this script is run, error_propagate_prepend() will have no clients. Is there a non-generated cleanup patch that removes it (and once it is removed, it can also be removed from the .cocci script as no further clients will reappear later)?

Quoted 15 lines

+@@

scripts/coccinelle/auto-propagated-errp.cocci new file +13 -0
+identifier rule1.fn;
+identifier rule1.local_err;
+@@
+
+ fn(...)
+ {
+     <...
+(
+-    &local_err
++    errp
+|
+-    local_err
++    *errp

scripts/coccinelle/auto-propagated-errp.cocci line 118

Quoted 10 lines
scripts/coccinelle/auto-propagated-errp.cocci new file +10 -0
+)
+     ...>
+ }
+
+@@
+symbol errp;
+@@
+
+- *errp != NULL
++ *errp

Seems to make sense.

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org
#58 lore raw

Re: [RFC v5 025/126] scripts: add coccinelle script to use auto propagated errp

Quoted 5 lines · Eric Blake
Quoted 3 lines · Vladimir Sementsov-Ogievskiy

---

Quoted 14 lines

scripts/coccinelle/auto-propagated-errp.cocci line 75

Quoted 12 lines

+@@

scripts/coccinelle/auto-propagated-errp.cocci new file +11 -0
+identifier rule1.fn;
+identifier rule1.local_err;
+@@
+
+ fn(...)
+ {
+     <...
+(
+-    error_free(local_err);
+-    local_err = NULL;
++    error_free_errp(errp);

This does not make sense - error_free_errp() is not defined prior to this series or anywhere in patches 1-24, if I'm reading it correctly.

Apologies - I sent my reply to this message before 21/126 showed up in my inbox, and didn't realize that I had skipped over sequencing. This part is fine after all, but it points to the perils of reviewing a thread as it comes in piecemeal, vs. reviewing an actual branch with all patches instantly available.

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org
#59 lore raw

Re: [RFC v5 025/126] scripts: add coccinelle script to use auto propagated errp

In reply to Eric Blake
Quoted 83 lines · Eric Blake
Quoted 17 lines · Vladimir Sementsov-Ogievskiy

---

  scripts/coccinelle/auto-propagated-errp.cocci | 118 ++++++++++++++++++

  1 file changed, 118 insertions(+)

  create mode 100644 scripts/coccinelle/auto-propagated-errp.cocci

scripts/coccinelle/auto-propagated-errp.cocci new file +3 -0
new file mode 100644
index 0000000000..d9731620aa
 
+@rule1@
+// Drop local_err
+identifier fn, local_err;

scripts/coccinelle/auto-propagated-errp.cocci line 45

Quoted 10 lines
scripts/coccinelle/auto-propagated-errp.cocci new file +10 -0
+symbol errp;
+@@
+
+ fn(..., Error **errp, ...)
+ {
+     <...
+-    Error *local_err = NULL;
+     ...>
+ }
+

So our goal is to automate removal of all local_err (including when it is spelled err)...

Quoted 8 lines

+@@

scripts/coccinelle/auto-propagated-errp.cocci new file +7 -0
+// Handle pattern with goto, otherwise we'll finish up
+// with labels at function end which will not compile.
+identifier rule1.fn;
+identifier rule1.local_err;
+identifier OUT;
+@@
+

scripts/coccinelle/auto-propagated-errp.cocci line 63

Quoted 10 lines
scripts/coccinelle/auto-propagated-errp.cocci new file +10 -0
+ fn(...)
+ {
+     <...
+-    goto OUT;
++    return;
+     ...>
+- OUT:
+-    error_propagate(errp, local_err);
+ }
+

this dangling label cleanup makes sense

scripts/coccinelle/auto-propagated-errp.cocci line 75

Quoted 12 lines

+@@

scripts/coccinelle/auto-propagated-errp.cocci new file +11 -0
+identifier rule1.fn;
+identifier rule1.local_err;
+@@
+
+ fn(...)
+ {
+     <...
+(
+-    error_free(local_err);
+-    local_err = NULL;
++    error_free_errp(errp);

This does not make sense - error_free_errp() is not defined prior to this series or anywhere in patches 1-24, if I'm reading it correctly.

Quoted 3 lines

+|
+-    error_free(local_err);
++    error_free_errp(errp);

and again

Quoted 10 lines

+|
+-    error_report_err(local_err);
++    error_report_errp(errp);
+|
+-    warn_report_err(local_err);
++    warn_report_errp(errp);
+|
+-    error_propagate_prepend(errp, local_err,
++    error_prepend(errp,
+                              ...);

Quoted 8 lines

scripts/coccinelle/auto-propagated-errp.cocci line 45

Quoted 6 lines

+|
+-    error_propagate(errp, local_err);

scripts/coccinelle/auto-propagated-errp.cocci new file +4 -0
+)
+     ...>
+ }
+

It looks like once this script is run, error_propagate_prepend() will have no clients.

No, it still have a bit, when working with error_copy, and/or moving errors from/to structures.

Quoted 1 line

Is there a non-generated cleanup patch that removes it (and once it is removed, it can also be removed from the .cocci script as no further clients will reappear later)?

Maybe.

Quoted 30 lines
Quoted 17 lines

+@@

scripts/coccinelle/auto-propagated-errp.cocci new file +13 -0
+identifier rule1.fn;
+identifier rule1.local_err;
+@@
+
+ fn(...)
+ {
+     <...
+(
+-    &local_err
++    errp
+|
+-    local_err
++    *errp

scripts/coccinelle/auto-propagated-errp.cocci line 118

Quoted 10 lines
scripts/coccinelle/auto-propagated-errp.cocci new file +10 -0
+)
+     ...>
+ }
+
+@@
+symbol errp;
+@@
+
+- *errp != NULL
++ *errp

Seems to make sense.

Signature · 2 lines
Best regards,
Vladimir
#60 lore raw

Re: [RFC v5 025/126] scripts: add coccinelle script to use auto propagated errp

Quoted 10 lines · Vladimir Sementsov-Ogievskiy
Quoted 8 lines

scripts/coccinelle/auto-propagated-errp.cocci line 45

Quoted 6 lines

+|
+-    error_propagate(errp, local_err);

scripts/coccinelle/auto-propagated-errp.cocci new file +4 -0
+)
+     ...>
+ }
+

It looks like once this script is run, error_propagate_prepend() will have no clients.

No, it still have a bit, when working with error_copy, and/or moving errors from/to structures.

No public clients. So can we turn it into a static function only used by error.c?

Quoted 5 lines
Quoted 2 lines

Is there a non-generated cleanup patch that removes it (and once it is removed, it can also be removed from the .cocci script as no further clients will reappear later)?

Maybe.

Basically, if we can get error_propagate out of error.h, that's a good sign. But it's not a show-stopper if we can't do it for some legitimate reason (such a reason might include that the definition of the ERRP_AUTO_PROPAGATE macro is easier to write if error_propagate remains in the .h), so we'll just have to see what is possible.

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org
#61 lore raw

RFC v5 26/126 python: add commit-per-subsystem.py

In reply to Vladimir Sementsov-Ogievskiy

Add script to automatically commit tree-wide changes per-subsystem.

---

CC Gerd Hoffmann <[email protected]>
CC "Gonglei (Arei)" <[email protected]>
CC Eduardo Habkost <[email protected]>
CC Igor Mammedov <[email protected]>
CC Laurent Vivier <[email protected]>
CC Amit Shah <[email protected]>
CC Kevin Wolf <[email protected]>
CC Max Reitz <[email protected]>
CC John Snow <[email protected]>
CC Ari Sundholm <[email protected]>
CC Pavel Dovgalyuk <[email protected]>
CC Paolo Bonzini <[email protected]>
CC Stefan Hajnoczi <[email protected]>
CC Fam Zheng <[email protected]>
CC Stefan Weil <[email protected]>
CC Ronnie Sahlberg <[email protected]>
CC Peter Lieven <[email protected]>
CC Eric Blake <[email protected]>
CC "Denis V. Lunev" <[email protected]>
CC Markus Armbruster <[email protected]>
CC Alberto Garcia <[email protected]>
CC Jason Dillaman <[email protected]>
CC Wen Congyang <[email protected]>
CC Xie Changlong <[email protected]>
CC Liu Yuan <[email protected]>
CC "Richard W.M. Jones" <[email protected]>
CC Jeff Cody <[email protected]>
CC "Marc-André Lureau" <[email protected]>
CC "Daniel P. Berrangé" <[email protected]>
CC Richard Henderson <[email protected]>
CC Greg Kurz <[email protected]>
CC "Michael S. Tsirkin" <[email protected]>
CC Marcel Apfelbaum <[email protected]>
CC Beniamino Galvani <[email protected]>
CC Peter Maydell <[email protected]>
CC "Cédric Le Goater" <[email protected]>
CC Andrew Jeffery <[email protected]>
CC Joel Stanley <[email protected]>
CC Andrew Baumann <[email protected]>
CC "Philippe Mathieu-Daudé" <[email protected]>
CC Antony Pavlov <[email protected]>
CC Jean-Christophe Dubois <[email protected]>
CC Peter Chubb <[email protected]>
CC Subbaraya Sundeep <[email protected]>
CC Eric Auger <[email protected]>
CC Alistair Francis <[email protected]>
CC "Edgar E. Iglesias" <[email protected]>
CC Stefano Stabellini <[email protected]>
CC Anthony Perard <[email protected]>
CC Paul Durrant <[email protected]>
CC Paul Burton <[email protected]>
CC Aleksandar Rikalo <[email protected]>
CC Chris Wulff <[email protected]>
CC Marek Vasut <[email protected]>
CC David Gibson <[email protected]>
CC Cornelia Huck <[email protected]>
CC Halil Pasic <[email protected]>
CC Christian Borntraeger <[email protected]>
CC "Hervé Poussineau" <[email protected]>
CC Xiao Guangrong <[email protected]>
CC Aurelien Jarno <[email protected]>
CC Aleksandar Markovic <[email protected]>
CC Mark Cave-Ayland <[email protected]>
CC Jason Wang <[email protected]>
CC Laszlo Ersek <[email protected]>
CC Yuval Shaia <[email protected]>
CC Palmer Dabbelt <[email protected]>
CC Sagar Karandikar <[email protected]>
CC Bastian Koppelmann <[email protected]>
CC David Hildenbrand <[email protected]>
CC Thomas Huth <[email protected]>
CC Eric Farman <[email protected]>
CC Matthew Rosato <[email protected]>
CC Hannes Reinecke <[email protected]>
CC Michael Walle <[email protected]>
CC Artyom Tarasenko <[email protected]>
CC Stefan Berger <[email protected]>
CC Samuel Thibault <[email protected]>
CC Alex Williamson <[email protected]>
CC Tony Krowiak <[email protected]>
CC Pierre Morel <[email protected]>
CC Michael Roth <[email protected]>
CC Hailiang Zhang <[email protected]>
CC Juan Quintela <[email protected]>
CC "Dr. David Alan Gilbert" <[email protected]>
CC Luigi Rizzo <[email protected]>
CC Giuseppe Lettieri <[email protected]>
CC Vincenzo Maffione <[email protected]>
CC Jan Kiszka <[email protected]>
CC Anthony Green <[email protected]>
CC Stafford Horne <[email protected]>
CC Guan Xuetao <[email protected]>
CC Max Filippov <[email protected]>
 python/commit-per-subsystem.py | 204 +++++++++++++++++++++++++++++++++
 1 file changed, 204 insertions(+)
 create mode 100755 python/commit-per-subsystem.py
python/commit-per-subsystem.py new file +204 -0
new file mode 100755
index 0000000000..2ccf84cb15
@@ -0,0 +1,204 @@
+#!/usr/bin/env python3
+#
+# Copyright (c) 2019 Virtuozzo International GmbH
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+
+import subprocess
+import sys
+import os
+import glob
+
+
+def git_add(pattern):
+    subprocess.run(['git', 'add', pattern])
+
+
+def git_commit(msg):
+    subprocess.run(['git', 'commit', '-m', msg], capture_output=True)
+
+
+def git_changed_files():
+    ret = subprocess.check_output(['git', 'diff', '--name-only'], encoding='utf-8').split('\n')
+    if ret[-1] == '':
+        del ret[-1]
+    return ret
+
+
+maintainers = sys.argv[1]
+message = sys.argv[2].strip()
+
+subsystem = None
+
+remap = {
+    'Block layer core': 'block',
+    'Block Jobs': 'block',
+    'Dirty Bitmaps': 'block',
+    'Block QAPI, monitor, command line': 'block',
+    'Block I/O path': 'block',
+    'Throttling infrastructure': 'block',
+    'Architecture support': 's390x',
+    'Guest CPU Cores (KVM)': 'kvm',
+    'Guest CPU Cores (Xen)': 'xen',
+    'Guest CPU cores (TCG)': 'tcg',
+    'Network Block Device (NBD)': 'nbd',
+    'Parallel NOR Flash devices': 'pflash',
+    'Firmware configuration (fw_cfg)': 'fw_cfg',
+    'Block SCSI subsystem': 'scsi',
+    'Network device backends': 'net',
+    'Netmap network backend': 'net',
+    'Host Memory Backends': 'hostmem',
+    'Cryptodev Backends': 'cryptodev',
+    'QEMU Guest Agent': 'qga',
+    'COLO Framework': 'colo',
+    'Command line option argument parsing': 'cmdline',
+    'Character device backends': 'chardev'
+}
+
+
+class Maintainers:
+    def add(self, subsystem, path, mapper, mapper_name, glob_count=1):
+        if subsystem in remap:
+            subsystem = remap[subsystem]
+        if subsystem not in self.subsystems:
+            self.subsystems.append(subsystem)
+
+        if path[-1] == '/':
+            path = path[:-1]
+
+        if path in mapper:
+            if mapper[path][1] == glob_count:
+                print('Warning: "{}" both in "{}" and "{}" in {} mapper with '
+                      'same glob-count={}. {} ignored for this path.'.format(
+                        path, mapper[path][0], subsystem, mapper_name, glob_count,
+                          subsystem))
+                return
+            if mapper[path][1] < glob_count:
+                # silently ignore worse match
+                return
+
+        mapper[path] = (subsystem, glob_count)
+
+    def __init__(self, file_name):
+        self.map_file = {}
+        self.map_glob_file = {}
+        self.map_dir = {}
+        self.map_glob_dir = {}
+        self.map_unmaintained_dir = {
+            'python': ('python', 1),
+            'hw/misc': ('misc', 1)
+        }
+        self.subsystems = ['python', 'misc']
+        subsystem = None
+
+        with open(file_name) as f:
+            mode2 = False
+            prevline = ''
+            for line in f:
+                line = line.rstrip()
+                if not line:
+                    continue
+                if len(line) >= 2 and line[1] == ':':
+                    if line[0] == 'F':
+                        fname = line[3:]
+                        if fname in ['*', '*/']:
+                            continue
+                        if os.path.isfile(fname):
+                            self.add(subsystem, fname, self.map_file, 'file')
+                        elif os.path.isdir(fname):
+                            self.add(subsystem, fname, self.map_dir, 'dir')
+                        else:
+                            paths = glob.glob(fname)
+                            if not paths:
+                                print('Warning: nothing corresponds to "{}"'.format(fname))
+                                continue
+
+                            n = len(paths)
+                            for f in paths:
+                                if os.path.isfile(f):
+                                    self.add(subsystem, f, self.map_glob_file, 'glob-file', n)
+                                else:
+                                    assert os.path.isdir(f)
+                                    self.add(subsystem, f, self.map_glob_dir, 'glob-dir', n)
+                elif line[:3] == '---':
+                    subsystem = prevline
+                    if subsystem == 'Devices':
+                        mode2 = True
+                elif mode2:
+                    subsystem = line
+                prevline = line
+
+    def find_in_map_dir(self, file_name, mapper):
+        while file_name != '' and file_name not in mapper:
+            file_name = os.path.dirname(file_name)
+
+        return None if file_name == '' else mapper[file_name][0]
+
+    def find_in_map_file(self, file_name, mapper):
+        if file_name in mapper:
+            return mapper[file_name][0]
+
+    def find_subsystem(self, file_name):
+        s = self.find_in_map_file(file_name, self.map_file)
+        if s is not None:
+            return s
+
+        s = self.find_in_map_file(file_name, self.map_glob_file)
+        if s is not None:
+            return s
+
+        s = self.find_in_map_dir(file_name, self.map_dir)
+        if s is not None:
+            return s
+
+        s = self.find_in_map_dir(file_name, self.map_glob_dir)
+        if s is not None:
+            return s
+
+        s = self.find_in_map_dir(file_name, self.map_unmaintained_dir)
+        if s is not None:
+            return s
+
+        self.subsystems.append(file_name)
+        return file_name
+
+
+def commit(subsystem):
+    msg = subsystem
+    if msg in remap:
+        msg = remap[msg]
+    msg += ': ' + message
+    git_commit(msg)
+
+mnt = Maintainers(maintainers)
+res = {}
+for f in git_changed_files():
+    s = mnt.find_subsystem(f)
+    if s in res:
+        res[s].append(f)
+    else:
+        res[s] = [f]
+
+for s in mnt.subsystems:
+    if s in res:
+        print(s)
+        for f in res[s]:
+            print('  ', f)
+
+for s in mnt.subsystems:
+    if s in res:
+        for f in res[s]:
+            git_add(f)
+        commit(s)
Signature · 1 line
2.21.0
#62 lore raw

Re: [RFC v5 026/126] python: add commit-per-subsystem.py

Hi

Quoted 2 lines · Vladimir Sementsov-Ogievskiy

Add script to automatically commit tree-wide changes per-subsystem.

Oh interesting! I guess it could use a --help or a larger commit message to explain a bit what it does (I imagine from the rest of the series, but someone looking at the script without context may wonder;)

You could also fix some pep8/pylint/pycodestyle

Quoted 324 lines

---

CC Gerd Hoffmann <[email protected]>
CC "Gonglei (Arei)" <[email protected]>
CC Eduardo Habkost <[email protected]>
CC Igor Mammedov <[email protected]>
CC Laurent Vivier <[email protected]>
CC Amit Shah <[email protected]>
CC Kevin Wolf <[email protected]>
CC Max Reitz <[email protected]>
CC John Snow <[email protected]>
CC Ari Sundholm <[email protected]>
CC Pavel Dovgalyuk <[email protected]>
CC Paolo Bonzini <[email protected]>
CC Stefan Hajnoczi <[email protected]>
CC Fam Zheng <[email protected]>
CC Stefan Weil <[email protected]>
CC Ronnie Sahlberg <[email protected]>
CC Peter Lieven <[email protected]>
CC Eric Blake <[email protected]>
CC "Denis V. Lunev" <[email protected]>
CC Markus Armbruster <[email protected]>
CC Alberto Garcia <[email protected]>
CC Jason Dillaman <[email protected]>
CC Wen Congyang <[email protected]>
CC Xie Changlong <[email protected]>
CC Liu Yuan <[email protected]>
CC "Richard W.M. Jones" <[email protected]>
CC Jeff Cody <[email protected]>
CC "Marc-André Lureau" <[email protected]>
CC "Daniel P. Berrangé" <[email protected]>
CC Richard Henderson <[email protected]>
CC Greg Kurz <[email protected]>
CC "Michael S. Tsirkin" <[email protected]>
CC Marcel Apfelbaum <[email protected]>
CC Beniamino Galvani <[email protected]>
CC Peter Maydell <[email protected]>
CC "Cédric Le Goater" <[email protected]>
CC Andrew Jeffery <[email protected]>
CC Joel Stanley <[email protected]>
CC Andrew Baumann <[email protected]>
CC "Philippe Mathieu-Daudé" <[email protected]>
CC Antony Pavlov <[email protected]>
CC Jean-Christophe Dubois <[email protected]>
CC Peter Chubb <[email protected]>
CC Subbaraya Sundeep <[email protected]>
CC Eric Auger <[email protected]>
CC Alistair Francis <[email protected]>
CC "Edgar E. Iglesias" <[email protected]>
CC Stefano Stabellini <[email protected]>
CC Anthony Perard <[email protected]>
CC Paul Durrant <[email protected]>
CC Paul Burton <[email protected]>
CC Aleksandar Rikalo <[email protected]>
CC Chris Wulff <[email protected]>
CC Marek Vasut <[email protected]>
CC David Gibson <[email protected]>
CC Cornelia Huck <[email protected]>
CC Halil Pasic <[email protected]>
CC Christian Borntraeger <[email protected]>
CC "Hervé Poussineau" <[email protected]>
CC Xiao Guangrong <[email protected]>
CC Aurelien Jarno <[email protected]>
CC Aleksandar Markovic <[email protected]>
CC Mark Cave-Ayland <[email protected]>
CC Jason Wang <[email protected]>
CC Laszlo Ersek <[email protected]>
CC Yuval Shaia <[email protected]>
CC Palmer Dabbelt <[email protected]>
CC Sagar Karandikar <[email protected]>
CC Bastian Koppelmann <[email protected]>
CC David Hildenbrand <[email protected]>
CC Thomas Huth <[email protected]>
CC Eric Farman <[email protected]>
CC Matthew Rosato <[email protected]>
CC Hannes Reinecke <[email protected]>
CC Michael Walle <[email protected]>
CC Artyom Tarasenko <[email protected]>
CC Stefan Berger <[email protected]>
CC Samuel Thibault <[email protected]>
CC Alex Williamson <[email protected]>
CC Tony Krowiak <[email protected]>
CC Pierre Morel <[email protected]>
CC Michael Roth <[email protected]>
CC Hailiang Zhang <[email protected]>
CC Juan Quintela <[email protected]>
CC "Dr. David Alan Gilbert" <[email protected]>
CC Luigi Rizzo <[email protected]>
CC Giuseppe Lettieri <[email protected]>
CC Vincenzo Maffione <[email protected]>
CC Jan Kiszka <[email protected]>
CC Anthony Green <[email protected]>
CC Stafford Horne <[email protected]>
CC Guan Xuetao <[email protected]>
CC Max Filippov <[email protected]>
 python/commit-per-subsystem.py | 204 +++++++++++++++++++++++++++++++++
 1 file changed, 204 insertions(+)
 create mode 100755 python/commit-per-subsystem.py
python/commit-per-subsystem.py new file +204 -1
new file mode 100755
index 0000000000..2ccf84cb15
@@ -0,0 +1,204 @@
+#!/usr/bin/env python3
+#
+# Copyright (c) 2019 Virtuozzo International GmbH
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+
+import subprocess
+import sys
+import os
+import glob
+
+
+def git_add(pattern):
+    subprocess.run(['git', 'add', pattern])
+
+
+def git_commit(msg):
+    subprocess.run(['git', 'commit', '-m', msg], capture_output=True)
+
+
+def git_changed_files():
+    ret = subprocess.check_output(['git', 'diff', '--name-only'], encoding='utf-8').split('\n')
+    if ret[-1] == '':
+        del ret[-1]
+    return ret
+
+
+maintainers = sys.argv[1]
+message = sys.argv[2].strip()
+
+subsystem = None
+
+remap = {
+    'Block layer core': 'block',
+    'Block Jobs': 'block',
+    'Dirty Bitmaps': 'block',
+    'Block QAPI, monitor, command line': 'block',
+    'Block I/O path': 'block',
+    'Throttling infrastructure': 'block',
+    'Architecture support': 's390x',
+    'Guest CPU Cores (KVM)': 'kvm',
+    'Guest CPU Cores (Xen)': 'xen',
+    'Guest CPU cores (TCG)': 'tcg',
+    'Network Block Device (NBD)': 'nbd',
+    'Parallel NOR Flash devices': 'pflash',
+    'Firmware configuration (fw_cfg)': 'fw_cfg',
+    'Block SCSI subsystem': 'scsi',
+    'Network device backends': 'net',
+    'Netmap network backend': 'net',
+    'Host Memory Backends': 'hostmem',
+    'Cryptodev Backends': 'cryptodev',
+    'QEMU Guest Agent': 'qga',
+    'COLO Framework': 'colo',
+    'Command line option argument parsing': 'cmdline',
+    'Character device backends': 'chardev'
+}
+
+
+class Maintainers:
+    def add(self, subsystem, path, mapper, mapper_name, glob_count=1):
+        if subsystem in remap:
+            subsystem = remap[subsystem]
+        if subsystem not in self.subsystems:
+            self.subsystems.append(subsystem)
+
+        if path[-1] == '/':
+            path = path[:-1]
+
+        if path in mapper:
+            if mapper[path][1] == glob_count:
+                print('Warning: "{}" both in "{}" and "{}" in {} mapper with '
+                      'same glob-count={}. {} ignored for this path.'.format(
+                        path, mapper[path][0], subsystem, mapper_name, glob_count,
+                          subsystem))
+                return
+            if mapper[path][1] < glob_count:
+                # silently ignore worse match
+                return
+
+        mapper[path] = (subsystem, glob_count)
+
+    def __init__(self, file_name):
+        self.map_file = {}
+        self.map_glob_file = {}
+        self.map_dir = {}
+        self.map_glob_dir = {}
+        self.map_unmaintained_dir = {
+            'python': ('python', 1),
+            'hw/misc': ('misc', 1)
+        }
+        self.subsystems = ['python', 'misc']
+        subsystem = None
+
+        with open(file_name) as f:
+            mode2 = False
+            prevline = ''
+            for line in f:
+                line = line.rstrip()
+                if not line:
+                    continue
+                if len(line) >= 2 and line[1] == ':':
+                    if line[0] == 'F':
+                        fname = line[3:]
+                        if fname in ['*', '*/']:
+                            continue
+                        if os.path.isfile(fname):
+                            self.add(subsystem, fname, self.map_file, 'file')
+                        elif os.path.isdir(fname):
+                            self.add(subsystem, fname, self.map_dir, 'dir')
+                        else:
+                            paths = glob.glob(fname)
+                            if not paths:
+                                print('Warning: nothing corresponds to "{}"'.format(fname))
+                                continue
+
+                            n = len(paths)
+                            for f in paths:
+                                if os.path.isfile(f):
+                                    self.add(subsystem, f, self.map_glob_file, 'glob-file', n)
+                                else:
+                                    assert os.path.isdir(f)
+                                    self.add(subsystem, f, self.map_glob_dir, 'glob-dir', n)
+                elif line[:3] == '---':
+                    subsystem = prevline
+                    if subsystem == 'Devices':
+                        mode2 = True
+                elif mode2:
+                    subsystem = line
+                prevline = line
+
+    def find_in_map_dir(self, file_name, mapper):
+        while file_name != '' and file_name not in mapper:
+            file_name = os.path.dirname(file_name)
+
+        return None if file_name == '' else mapper[file_name][0]
+
+    def find_in_map_file(self, file_name, mapper):
+        if file_name in mapper:
+            return mapper[file_name][0]
+
+    def find_subsystem(self, file_name):
+        s = self.find_in_map_file(file_name, self.map_file)
+        if s is not None:
+            return s
+
+        s = self.find_in_map_file(file_name, self.map_glob_file)
+        if s is not None:
+            return s
+
+        s = self.find_in_map_dir(file_name, self.map_dir)
+        if s is not None:
+            return s
+
+        s = self.find_in_map_dir(file_name, self.map_glob_dir)
+        if s is not None:
+            return s
+
+        s = self.find_in_map_dir(file_name, self.map_unmaintained_dir)
+        if s is not None:
+            return s
+
+        self.subsystems.append(file_name)
+        return file_name
+
+
+def commit(subsystem):
+    msg = subsystem
+    if msg in remap:
+        msg = remap[msg]
+    msg += ': ' + message
+    git_commit(msg)
+
+mnt = Maintainers(maintainers)
+res = {}
+for f in git_changed_files():
+    s = mnt.find_subsystem(f)
+    if s in res:
+        res[s].append(f)
+    else:
+        res[s] = [f]
+
+for s in mnt.subsystems:
+    if s in res:
+        print(s)
+        for f in res[s]:
+            print('  ', f)
+
+for s in mnt.subsystems:
+    if s in res:
+        for f in res[s]:
+            git_add(f)
+        commit(s)
--

2.21.0

Signature · 1 line
Marc-André Lureau
Reviewed-by on v5 26/126
#63 lore raw

Re: [RFC v5 026/126] python: add commit-per-subsystem.py

In reply to Vladimir Sementsov-Ogievskiy
Quoted 4 lines · Vladimir Sementsov-Ogievskiy

Add script to automatically commit tree-wide changes per-subsystem.

---

Great idea!

Can you just add a comment somewhere close to the top of the file on script usage? Or "--help" option? If you would like to be the script maintainer, please change the MAINTAINERS too.

Quoted 332 lines
CC Gerd Hoffmann <[email protected]>
CC "Gonglei (Arei)" <[email protected]>
CC Eduardo Habkost <[email protected]>
CC Igor Mammedov <[email protected]>
CC Laurent Vivier <[email protected]>
CC Amit Shah <[email protected]>
CC Kevin Wolf <[email protected]>
CC Max Reitz <[email protected]>
CC John Snow <[email protected]>
CC Ari Sundholm <[email protected]>
CC Pavel Dovgalyuk <[email protected]>
CC Paolo Bonzini <[email protected]>
CC Stefan Hajnoczi <[email protected]>
CC Fam Zheng <[email protected]>
CC Stefan Weil <[email protected]>
CC Ronnie Sahlberg <[email protected]>
CC Peter Lieven <[email protected]>
CC Eric Blake <[email protected]>
CC "Denis V. Lunev" <[email protected]>
CC Markus Armbruster <[email protected]>
CC Alberto Garcia <[email protected]>
CC Jason Dillaman <[email protected]>
CC Wen Congyang <[email protected]>
CC Xie Changlong <[email protected]>
CC Liu Yuan <[email protected]>
CC "Richard W.M. Jones" <[email protected]>
CC Jeff Cody <[email protected]>
CC "Marc-André Lureau" <[email protected]>
CC "Daniel P. Berrangé" <[email protected]>
CC Richard Henderson <[email protected]>
CC Greg Kurz <[email protected]>
CC "Michael S. Tsirkin" <[email protected]>
CC Marcel Apfelbaum <[email protected]>
CC Beniamino Galvani <[email protected]>
CC Peter Maydell <[email protected]>
CC "Cédric Le Goater" <[email protected]>
CC Andrew Jeffery <[email protected]>
CC Joel Stanley <[email protected]>
CC Andrew Baumann <[email protected]>
CC "Philippe Mathieu-Daudé" <[email protected]>
CC Antony Pavlov <[email protected]>
CC Jean-Christophe Dubois <[email protected]>
CC Peter Chubb <[email protected]>
CC Subbaraya Sundeep <[email protected]>
CC Eric Auger <[email protected]>
CC Alistair Francis <[email protected]>
CC "Edgar E. Iglesias" <[email protected]>
CC Stefano Stabellini <[email protected]>
CC Anthony Perard <[email protected]>
CC Paul Durrant <[email protected]>
CC Paul Burton <[email protected]>
CC Aleksandar Rikalo <[email protected]>
CC Chris Wulff <[email protected]>
CC Marek Vasut <[email protected]>
CC David Gibson <[email protected]>
CC Cornelia Huck <[email protected]>
CC Halil Pasic <[email protected]>
CC Christian Borntraeger <[email protected]>
CC "Hervé Poussineau" <[email protected]>
CC Xiao Guangrong <[email protected]>
CC Aurelien Jarno <[email protected]>
CC Aleksandar Markovic <[email protected]>
CC Mark Cave-Ayland <[email protected]>
CC Jason Wang <[email protected]>
CC Laszlo Ersek <[email protected]>
CC Yuval Shaia <[email protected]>
CC Palmer Dabbelt <[email protected]>
CC Sagar Karandikar <[email protected]>
CC Bastian Koppelmann <[email protected]>
CC David Hildenbrand <[email protected]>
CC Thomas Huth <[email protected]>
CC Eric Farman <[email protected]>
CC Matthew Rosato <[email protected]>
CC Hannes Reinecke <[email protected]>
CC Michael Walle <[email protected]>
CC Artyom Tarasenko <[email protected]>
CC Stefan Berger <[email protected]>
CC Samuel Thibault <[email protected]>
CC Alex Williamson <[email protected]>
CC Tony Krowiak <[email protected]>
CC Pierre Morel <[email protected]>
CC Michael Roth <[email protected]>
CC Hailiang Zhang <[email protected]>
CC Juan Quintela <[email protected]>
CC "Dr. David Alan Gilbert" <[email protected]>
CC Luigi Rizzo <[email protected]>
CC Giuseppe Lettieri <[email protected]>
CC Vincenzo Maffione <[email protected]>
CC Jan Kiszka <[email protected]>
CC Anthony Green <[email protected]>
CC Stafford Horne <[email protected]>
CC Guan Xuetao <[email protected]>
CC Max Filippov <[email protected]>
 python/commit-per-subsystem.py | 204 +++++++++++++++++++++++++++++++++
 1 file changed, 204 insertions(+)
 create mode 100755 python/commit-per-subsystem.py
python/commit-per-subsystem. renamed from python/commit-per-subsystem.py +0 -0

py
new file mode 100755
index 0000000000..2ccf84cb15

python/commit-per-subsystem.py new file +34 -0
@@ -0,0 +1,204 @@
+#!/usr/bin/env python3
+#
+# Copyright (c) 2019 Virtuozzo International GmbH
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+
+import subprocess
+import sys
+import os
+import glob
+
+
+def git_add(pattern):
+    subprocess.run(['git', 'add', pattern])
+
+
+def git_commit(msg):
+    subprocess.run(['git', 'commit', '-m', msg], capture_output=True)
+
+
+def git_changed_files():
+    ret = subprocess.check_output(['git', 'diff', '--name-only'],

encoding='utf-8').split('\n')

python/commit-per-subsystem.py new file +49 -0
+    if ret[-1] == '':
+        del ret[-1]
+    return ret
+
+
+maintainers = sys.argv[1]
+message = sys.argv[2].strip()
+
+subsystem = None
+
+remap = {
+    'Block layer core': 'block',
+    'Block Jobs': 'block',
+    'Dirty Bitmaps': 'block',
+    'Block QAPI, monitor, command line': 'block',
+    'Block I/O path': 'block',
+    'Throttling infrastructure': 'block',
+    'Architecture support': 's390x',
+    'Guest CPU Cores (KVM)': 'kvm',
+    'Guest CPU Cores (Xen)': 'xen',
+    'Guest CPU cores (TCG)': 'tcg',
+    'Network Block Device (NBD)': 'nbd',
+    'Parallel NOR Flash devices': 'pflash',
+    'Firmware configuration (fw_cfg)': 'fw_cfg',
+    'Block SCSI subsystem': 'scsi',
+    'Network device backends': 'net',
+    'Netmap network backend': 'net',
+    'Host Memory Backends': 'hostmem',
+    'Cryptodev Backends': 'cryptodev',
+    'QEMU Guest Agent': 'qga',
+    'COLO Framework': 'colo',
+    'Command line option argument parsing': 'cmdline',
+    'Character device backends': 'chardev'
+}
+
+
+class Maintainers:
+    def add(self, subsystem, path, mapper, mapper_name, glob_count=1):
+        if subsystem in remap:
+            subsystem = remap[subsystem]
+        if subsystem not in self.subsystems:
+            self.subsystems.append(subsystem)
+
+        if path[-1] == '/':
+            path = path[:-1]
+
+        if path in mapper:
+            if mapper[path][1] == glob_count:
+                print('Warning: "{}" both in "{}" and "{}" in {} mapper

with '
+ 'same glob-count={}. {} ignored for this
path.'.format(
+ path, mapper[path][0], subsystem, mapper_name,
glob_count,

python/commit-per-subsystem.py new file +34 -0
+                          subsystem))
+                return
+            if mapper[path][1] < glob_count:
+                # silently ignore worse match
+                return
+
+        mapper[path] = (subsystem, glob_count)
+
+    def __init__(self, file_name):
+        self.map_file = {}
+        self.map_glob_file = {}
+        self.map_dir = {}
+        self.map_glob_dir = {}
+        self.map_unmaintained_dir = {
+            'python': ('python', 1),
+            'hw/misc': ('misc', 1)
+        }
+        self.subsystems = ['python', 'misc']
+        subsystem = None
+
+        with open(file_name) as f:
+            mode2 = False
+            prevline = ''
+            for line in f:
+                line = line.rstrip()
+                if not line:
+                    continue
+                if len(line) >= 2 and line[1] == ':':
+                    if line[0] == 'F':
+                        fname = line[3:]
+                        if fname in ['*', '*/']:
+                            continue
+                        if os.path.isfile(fname):
+                            self.add(subsystem, fname, self.map_file,

'file')

python/commit-per-subsystem.py new file +2 -0
+                        elif os.path.isdir(fname):
+                            self.add(subsystem, fname, self.map_dir,

'dir')

python/commit-per-subsystem.py new file +4 -0
+                        else:
+                            paths = glob.glob(fname)
+                            if not paths:
+                                print('Warning: nothing corresponds to

"{}"'.format(fname))

python/commit-per-subsystem.py new file +6 -0
+                                continue
+
+                            n = len(paths)
+                            for f in paths:
+                                if os.path.isfile(f):
+                                    self.add(subsystem, f,

self.map_glob_file, 'glob-file', n)

python/commit-per-subsystem.py new file +3 -0
+                                else:
+                                    assert os.path.isdir(f)
+                                    self.add(subsystem, f,

self.map_glob_dir, 'glob-dir', n)

python/commit-per-subsystem.py new file +70 -1
+                elif line[:3] == '---':
+                    subsystem = prevline
+                    if subsystem == 'Devices':
+                        mode2 = True
+                elif mode2:
+                    subsystem = line
+                prevline = line
+
+    def find_in_map_dir(self, file_name, mapper):
+        while file_name != '' and file_name not in mapper:
+            file_name = os.path.dirname(file_name)
+
+        return None if file_name == '' else mapper[file_name][0]
+
+    def find_in_map_file(self, file_name, mapper):
+        if file_name in mapper:
+            return mapper[file_name][0]
+
+    def find_subsystem(self, file_name):
+        s = self.find_in_map_file(file_name, self.map_file)
+        if s is not None:
+            return s
+
+        s = self.find_in_map_file(file_name, self.map_glob_file)
+        if s is not None:
+            return s
+
+        s = self.find_in_map_dir(file_name, self.map_dir)
+        if s is not None:
+            return s
+
+        s = self.find_in_map_dir(file_name, self.map_glob_dir)
+        if s is not None:
+            return s
+
+        s = self.find_in_map_dir(file_name, self.map_unmaintained_dir)
+        if s is not None:
+            return s
+
+        self.subsystems.append(file_name)
+        return file_name
+
+
+def commit(subsystem):
+    msg = subsystem
+    if msg in remap:
+        msg = remap[msg]
+    msg += ': ' + message
+    git_commit(msg)
+
+mnt = Maintainers(maintainers)
+res = {}
+for f in git_changed_files():
+    s = mnt.find_subsystem(f)
+    if s in res:
+        res[s].append(f)
+    else:
+        res[s] = [f]
+
+for s in mnt.subsystems:
+    if s in res:
+        print(s)
+        for f in res[s]:
+            print('  ', f)
+
+for s in mnt.subsystems:
+    if s in res:
+        for f in res[s]:
+            git_add(f)
+        commit(s)
--

2.21.0

#65 lore raw

RFC v5 27/126 misc: introduce ERRP_AUTO_PROPAGATE

In reply to Vladimir Sementsov-Ogievskiy

If we want to add some info to errp (by error_prepend() or error_append_hint()), we must use the ERRP_AUTO_PROPAGATE macro. Otherwise, this info will not be added when errp == &fatal_err (the program will exit prior to the error_append_hint() or error_prepend() call). Fix such cases.

If we want to check error after errp-function call, we need to introduce local_err and than propagate it to errp. Instead, use ERRP_AUTO_PROPAGATE macro, benefits are:
1. No need of explicit error_propagate call
2. No need of explicit local_err variable: use errp directly
3. ERRP_AUTO_PROPAGATE leaves errp as is if it's not NULL or &error_fatel, this means that we don't break error_abort (we'll abort on error_set, not on error_propagate)

This commit (together with its neighbors) was generated by

for f in $(git grep -l errp \*.[ch]); do \

    spatch --sp-file scripts/coccinelle/auto-propagated-errp.cocci \
    --macro-file scripts/cocci-macro-file.h --in-place --no-show-diff $f; \

done;

then fix a bit of compilation problems: coccinelle for some reason leaves several

f() {
    ...
    goto out;
    ...
    out:
}

patterns, with "out:" at function end.

then
./python/commit-per-subsystem.py MAINTAINERS "$(< auto-msg)"

(auto-msg was a file with this commit message)

Still, for backporting it may be more comfortable to use only the first command and then do one huge commit.

---
 hw/misc/ivshmem.c | 37 ++++++++++++++++---------------------
 hw/misc/tmp105.c  |  7 +++----
 hw/misc/tmp421.c  |  7 +++----
 3 files changed, 22 insertions(+), 29 deletions(-)
hw/misc/ivshmem.c +16 -21
index 5e3b05eae0..31292c3f43 100644
@@ -474,11 +474,11 @@ static void ivshmem_add_kvm_msi_virq(IVShmemState *s, int vector,
 
 static void setup_interrupt(IVShmemState *s, int vector, Error **errp)
 {
+    ERRP_AUTO_PROPAGATE();
     EventNotifier *n = &s->peers[s->vm_id].eventfds[vector];
     bool with_irqfd = kvm_msi_via_irqfd_enabled() &&
         ivshmem_has_feature(s, IVSHMEM_MSI);
     PCIDevice *pdev = PCI_DEVICE(s);
-    Error *err = NULL;
 
     IVSHMEM_DPRINTF("setting up interrupt for vector: %d\n", vector);
 
@@ -487,9 +487,8 @@ static void setup_interrupt(IVShmemState *s, int vector, Error **errp)
         watch_vector_notifier(s, n, vector);
     } else if (msix_enabled(pdev)) {
         IVSHMEM_DPRINTF("with irqfd\n");
-        ivshmem_add_kvm_msi_virq(s, vector, &err);
-        if (err) {
-            error_propagate(errp, err);
+        ivshmem_add_kvm_msi_virq(s, vector, errp);
+        if (*errp) {
             return;
         }
 
@@ -506,7 +505,7 @@ static void setup_interrupt(IVShmemState *s, int vector, Error **errp)
 
 static void process_msg_shmem(IVShmemState *s, int fd, Error **errp)
 {
-    Error *local_err = NULL;
+    ERRP_AUTO_PROPAGATE();
     struct stat buf;
     size_t size;
 
@@ -527,9 +526,8 @@ static void process_msg_shmem(IVShmemState *s, int fd, Error **errp)
 
     /* mmap the region and map into the BAR2 */
     memory_region_init_ram_from_fd(&s->server_bar2, OBJECT(s),
-                                   "ivshmem.bar2", size, true, fd, &local_err);
-    if (local_err) {
-        error_propagate(errp, local_err);
+                                   "ivshmem.bar2", size, true, fd, errp);
+    if (*errp) {
         return;
     }
 
@@ -662,13 +660,12 @@ static int64_t ivshmem_recv_msg(IVShmemState *s, int *pfd, Error **errp)
 
 static void ivshmem_recv_setup(IVShmemState *s, Error **errp)
 {
-    Error *err = NULL;
+    ERRP_AUTO_PROPAGATE();
     int64_t msg;
     int fd;
 
-    msg = ivshmem_recv_msg(s, &fd, &err);
-    if (err) {
-        error_propagate(errp, err);
+    msg = ivshmem_recv_msg(s, &fd, errp);
+    if (*errp) {
         return;
     }
     if (msg != IVSHMEM_PROTOCOL_VERSION) {
@@ -694,9 +691,8 @@ static void ivshmem_recv_setup(IVShmemState *s, Error **errp)
      * older versions of the device accepted it out of order, but
      * broke when an interrupt setup message arrived before it.
      */
-    msg = ivshmem_recv_msg(s, &fd, &err);
-    if (err) {
-        error_propagate(errp, err);
+    msg = ivshmem_recv_msg(s, &fd, errp);
+    if (*errp) {
         return;
     }
     if (fd != -1 || msg < 0 || msg > IVSHMEM_MAX_PEERS) {
@@ -709,14 +705,12 @@ static void ivshmem_recv_setup(IVShmemState *s, Error **errp)
      * Receive more messages until we got shared memory.
      */
     do {
-        msg = ivshmem_recv_msg(s, &fd, &err);
-        if (err) {
-            error_propagate(errp, err);
+        msg = ivshmem_recv_msg(s, &fd, errp);
+        if (*errp) {
             return;
         }
-        process_msg(s, msg, fd, &err);
-        if (err) {
-            error_propagate(errp, err);
+        process_msg(s, msg, fd, errp);
+        if (*errp) {
             return;
         }
     } while (msg != -1);
@@ -864,6 +858,7 @@ static void ivshmem_write_config(PCIDevice *pdev, uint32_t address,
 
 static void ivshmem_common_realize(PCIDevice *dev, Error **errp)
 {
+    ERRP_AUTO_PROPAGATE();
     IVShmemState *s = IVSHMEM_COMMON(dev);
     Error *err = NULL;
     uint8_t *pci_conf;
hw/misc/tmp105.c +3 -4
index 75ddad3a12..c603f7024d 100644
@@ -71,13 +71,12 @@ static void tmp105_get_temperature(Object *obj, Visitor *v, const char *name,
 static void tmp105_set_temperature(Object *obj, Visitor *v, const char *name,
                                    void *opaque, Error **errp)
 {
+    ERRP_AUTO_PROPAGATE();
     TMP105State *s = TMP105(obj);
-    Error *local_err = NULL;
     int64_t temp;
 
-    visit_type_int(v, name, &temp, &local_err);
-    if (local_err) {
-        error_propagate(errp, local_err);
+    visit_type_int(v, name, &temp, errp);
+    if (*errp) {
         return;
     }
     if (temp >= 128000 || temp < -128000) {
hw/misc/tmp421.c +3 -4
index 9f044705fa..20f069513c 100644
@@ -140,16 +140,15 @@ static void tmp421_get_temperature(Object *obj, Visitor *v, const char *name,
 static void tmp421_set_temperature(Object *obj, Visitor *v, const char *name,
                                    void *opaque, Error **errp)
 {
+    ERRP_AUTO_PROPAGATE();
     TMP421State *s = TMP421(obj);
-    Error *local_err = NULL;
     int64_t temp;
     bool ext_range = (s->config[0] & TMP421_CONFIG_RANGE);
     int offset = ext_range * 64 * 256;
     int tempid;
 
-    visit_type_int(v, name, &temp, &local_err);
-    if (local_err) {
-        error_propagate(errp, local_err);
+    visit_type_int(v, name, &temp, errp);
+    if (*errp) {
         return;
     }
 
Signature · 1 line
2.21.0
#66 lore raw

Re: [RFC v5 027/126] misc: introduce ERRP_AUTO_PROPAGATE

Quoted 24 lines · Vladimir Sementsov-Ogievskiy

If we want to add some info to errp (by error_prepend() or error_append_hint()), we must use the ERRP_AUTO_PROPAGATE macro. Otherwise, this info will not be added when errp == &fatal_err (the program will exit prior to the error_append_hint() or error_prepend() call). Fix such cases.

If we want to check error after errp-function call, we need to introduce local_err and than propagate it to errp. Instead, use ERRP_AUTO_PROPAGATE macro, benefits are:
1. No need of explicit error_propagate call
2. No need of explicit local_err variable: use errp directly
3. ERRP_AUTO_PROPAGATE leaves errp as is if it's not NULL or &error_fatel, this means that we don't break error_abort (we'll abort on error_set, not on error_propagate)

This commit (together with its neighbors) was generated by

for f in $(git grep -l errp \*.[ch]); do \

     spatch --sp-file scripts/coccinelle/auto-propagated-errp.cocci \
     --macro-file scripts/cocci-macro-file.h --in-place --no-show-diff $f; \

done;

then fix a bit of compilation problems: coccinelle for some reason leaves several

Quoted 7 lines
f() {
     ...
     goto out;
     ...
     out:
}

patterns, with "out:" at function end.

Was that still happening even after your tweaks to the .cocci script? But manual touch-up after cocci is not unheard of, so it is not a showstopper to the series. Still, it might be nicer if this disclaimer only appears on the patches within the series where it actually matters, rather than on every message in the series even when no tweaks were needed (as this patch is an example where the touchup was not needed).

Quoted 4 lines

then
./python/commit-per-subsystem.py MAINTAINERS "$(< auto-msg)"

If we don't check the python script into git, then changing this to a URL to one of the threads where you posted the script in an earlier version of the patch is also acceptable.

Quoted 16 lines

(auto-msg was a file with this commit message)

Still, for backporting it may be more comfortable to use only the first command and then do one huge commit.

---
  hw/misc/ivshmem.c | 37 ++++++++++++++++---------------------
  hw/misc/tmp105.c  |  7 +++----
  hw/misc/tmp421.c  |  7 +++----
  3 files changed, 22 insertions(+), 29 deletions(-)

hw/misc/ivshmem.c static void ivshmem_write_config(PCIDevice *pdev, uint32_t address, · line 863

Quoted 6 lines
hw/misc/ivshmem.c +1 -0
@@ -864,6 +858,7 @@ static void ivshmem_write_config(PCIDevice *pdev, uint32_t address,
 
  static void ivshmem_common_realize(PCIDevice *dev, Error **errp)
  {
+    ERRP_AUTO_PROPAGATE();
      IVShmemState *s = IVSHMEM_COMMON(dev);
      Error *err = NULL;

Umm, so why did Coccinelle not remove this line, or retouch lower down at:

    if (!ivshmem_is_master(s)) {
        error_setg(&s->migration_blocker,
                   "Migration is disabled when using feature 'peer 
mode' in devi
ce 'ivshmem'");
        migrate_add_blocker(s->migration_blocker, &local_err);
        if (local_err) {
            error_propagate(errp, local_err);
            error_free(s->migration_blocker);
            return;
        }
    }

But the conversions that Coccinelle made look correct.

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org
#67 lore raw

Re: [RFC v5 027/126] misc: introduce ERRP_AUTO_PROPAGATE

Quoted 33 lines · Eric Blake
Quoted 22 lines · Vladimir Sementsov-Ogievskiy

If we want to add some info to errp (by error_prepend() or error_append_hint()), we must use the ERRP_AUTO_PROPAGATE macro. Otherwise, this info will not be added when errp == &fatal_err (the program will exit prior to the error_append_hint() or error_prepend() call).  Fix such cases.

If we want to check error after errp-function call, we need to introduce local_err and than propagate it to errp. Instead, use ERRP_AUTO_PROPAGATE macro, benefits are:
1. No need of explicit error_propagate call
2. No need of explicit local_err variable: use errp directly
3. ERRP_AUTO_PROPAGATE leaves errp as is if it's not NULL or &error_fatel, this means that we don't break error_abort (we'll abort on error_set, not on error_propagate)

This commit (together with its neighbors) was generated by

for f in $(git grep -l errp \*.[ch]); do \
     spatch --sp-file scripts/coccinelle/auto-propagated-errp.cocci \
     --macro-file scripts/cocci-macro-file.h --in-place --no-show-diff $f; \
done;

Quoted 9 lines

then fix a bit of compilation problems: coccinelle for some reason leaves several
f() {
     ...
     goto out;
     ...
     out:
}
patterns, with "out:" at function end.

Quoted 1 line

Was that still happening even after your tweaks to the .cocci script?

Yes, seem coccinella succesfully removes

out:
error_prapagate

pattern in general, but fails to work if there is additional "return;" :

return;
out:
error_proapagate

Quoted 1 line

But manual touch-up after cocci is not unheard of, so it is not a showstopper to the series.  Still, it might be nicer if this disclaimer only appears on the patches within the series where it actually matters, rather than on every message in the series even when no tweaks were needed (as this patch is an example where the touchup was not needed).

Hmm.. Not sure. I think it's good to have in each commit an instruction how to generate the whole sequence. Still, what you want is not difficult: just instead of fixing all compilation errors at once, commit the changes and than play with git rebase -x 'make -j9'.

Quoted 45 lines
Quoted 5 lines

then
./python/commit-per-subsystem.py MAINTAINERS "$(< auto-msg)"

If we don't check the python script into git, then changing this to a URL to one of the threads where you posted the script in an earlier version of the patch is also acceptable.

Quoted 16 lines

(auto-msg was a file with this commit message)

Still, for backporting it may be more comfortable to use only the first command and then do one huge commit.

---
  hw/misc/ivshmem.c | 37 ++++++++++++++++--------------------- hw/misc/tmp105.c  |  7 +++----
  hw/misc/tmp421.c  |  7 +++----

  3 files changed, 22 insertions(+), 29 deletions(-)

hw/misc/ivshmem.c static void ivshmem_write_config(PCIDevice *pdev, uint32_t address, · line 862

Quoted 5 lines
hw/misc/ivshmem.c +1 -0
@@ -864,6 +858,7 @@ static void ivshmem_write_config(PCIDevice *pdev, uint32_t address,
   static void ivshmem_common_realize(PCIDevice *dev, Error **errp)
   {
+    ERRP_AUTO_PROPAGATE();
       IVShmemState *s = IVSHMEM_COMMON(dev);
       Error *err = NULL;

Umm, so why did Coccinelle not remove this line, or retouch lower down at:

    if (!ivshmem_is_master(s)) {
        error_setg(&s->migration_blocker,
                   "Migration is disabled when using feature 'peer mode' in devi
ce 'ivshmem'");
        migrate_add_blocker(s->migration_blocker, &local_err);
        if (local_err) {
            error_propagate(errp, local_err); error_free(s->migration_blocker);
            return;
        }
    }

Quoted 2 lines

But the conversions that Coccinelle made look correct.

Hmmm. strange. So it does nothing, except add a macro invocation?

Intersting: if I comment definition for local_err, it correctly updates code around err, if I comment definition for err, it correctly updates code around local_err.

So, rule0 works, but rule1 don't know what to do with two Error * variables.

Seems, simplest thing is to pre-refactor it, to drop local_err variable.

Signature · 2 lines
Best regards,
Vladimir
#68 lore raw

RFC v5 28/126 s390x: introduce ERRP_AUTO_PROPAGATE

In reply to Vladimir Sementsov-Ogievskiy

If we want to add some info to errp (by error_prepend() or error_append_hint()), we must use the ERRP_AUTO_PROPAGATE macro. Otherwise, this info will not be added when errp == &fatal_err (the program will exit prior to the error_append_hint() or error_prepend() call). Fix such cases.

If we want to check error after errp-function call, we need to introduce local_err and than propagate it to errp. Instead, use ERRP_AUTO_PROPAGATE macro, benefits are:
1. No need of explicit error_propagate call
2. No need of explicit local_err variable: use errp directly
3. ERRP_AUTO_PROPAGATE leaves errp as is if it's not NULL or &error_fatel, this means that we don't break error_abort (we'll abort on error_set, not on error_propagate)

This commit (together with its neighbors) was generated by

for f in $(git grep -l errp \*.[ch]); do \

    spatch --sp-file scripts/coccinelle/auto-propagated-errp.cocci \
    --macro-file scripts/cocci-macro-file.h --in-place --no-show-diff $f; \

done;

then fix a bit of compilation problems: coccinelle for some reason leaves several

f() {
    ...
    goto out;
    ...
    out:
}

patterns, with "out:" at function end.

then
./python/commit-per-subsystem.py MAINTAINERS "$(< auto-msg)"

(auto-msg was a file with this commit message)

Still, for backporting it may be more comfortable to use only the first command and then do one huge commit.

---
 hw/intc/s390_flic_kvm.c    |  9 ++++-----
 hw/s390x/3270-ccw.c        | 13 ++++++-------
 hw/s390x/css-bridge.c      |  7 +++----
 hw/s390x/css.c             |  7 +++----
 hw/s390x/s390-skeys.c      |  7 +++----
 hw/s390x/s390-virtio-ccw.c | 11 +++++------
 hw/s390x/sclp.c            | 15 ++++++---------
 hw/s390x/tod-kvm.c         | 14 ++++++--------
 hw/vfio/ccw.c              | 24 +++++++++++-------------
 target/s390x/cpu.c         | 26 ++++++++++++--------------
 10 files changed, 59 insertions(+), 74 deletions(-)
hw/intc/s390_flic_kvm.c +4 -5
index cedccba8a9..5550cecef8 100644
@@ -578,14 +578,14 @@ typedef struct KVMS390FLICStateClass {
 
 static void kvm_s390_flic_realize(DeviceState *dev, Error **errp)
 {
+    ERRP_AUTO_PROPAGATE();
     KVMS390FLICState *flic_state = KVM_S390_FLIC(dev);
     struct kvm_create_device cd = {0};
     struct kvm_device_attr test_attr = {0};
     int ret;
-    Error *errp_local = NULL;
 
-    KVM_S390_FLIC_GET_CLASS(dev)->parent_realize(dev, &errp_local);
-    if (errp_local) {
+    KVM_S390_FLIC_GET_CLASS(dev)->parent_realize(dev, errp);
+    if (*errp) {
         goto fail;
     }
     flic_state->fd = -1;
@@ -593,7 +593,7 @@ static void kvm_s390_flic_realize(DeviceState *dev, Error **errp)
     cd.type = KVM_DEV_TYPE_FLIC;
     ret = kvm_vm_ioctl(kvm_state, KVM_CREATE_DEVICE, &cd);
     if (ret < 0) {
-        error_setg_errno(&errp_local, errno, "Creating the KVM device failed");
+        error_setg_errno(errp, errno, "Creating the KVM device failed");
         trace_flic_create_device(errno);
         goto fail;
     }
@@ -605,7 +605,6 @@ static void kvm_s390_flic_realize(DeviceState *dev, Error **errp)
                                             KVM_HAS_DEVICE_ATTR, test_attr);
     return;
 fail:
-    error_propagate(errp, errp_local);
 }
 
 static void kvm_s390_flic_reset(DeviceState *dev)
hw/s390x/3270-ccw.c +6 -7
index c19a75b9b7..830d7f385e 100644
@@ -95,13 +95,13 @@ static int emulated_ccw_3270_cb(SubchDev *sch, CCW1 ccw)
 
 static void emulated_ccw_3270_realize(DeviceState *ds, Error **errp)
 {
+    ERRP_AUTO_PROPAGATE();
     uint16_t chpid;
     EmulatedCcw3270Device *dev = EMULATED_CCW_3270(ds);
     EmulatedCcw3270Class *ck = EMULATED_CCW_3270_GET_CLASS(dev);
     CcwDevice *cdev = CCW_DEVICE(ds);
     CCWDeviceClass *cdk = CCW_DEVICE_GET_CLASS(cdev);
     SubchDev *sch;
-    Error *err = NULL;
 
     sch = css_create_sch(cdev->devno, errp);
     if (!sch) {
@@ -117,7 +117,7 @@ static void emulated_ccw_3270_realize(DeviceState *ds, Error **errp)
     chpid = css_find_free_chpid(sch->cssid);
 
     if (chpid > MAX_CHPID) {
-        error_setg(&err, "No available chpid to use.");
+        error_setg(errp, "No available chpid to use.");
         goto out_err;
     }
 
@@ -128,20 +128,19 @@ static void emulated_ccw_3270_realize(DeviceState *ds, Error **errp)
     sch->do_subchannel_work = do_subchannel_work_virtual;
     sch->ccw_cb = emulated_ccw_3270_cb;
 
-    ck->init(dev, &err);
-    if (err) {
+    ck->init(dev, errp);
+    if (*errp) {
         goto out_err;
     }
 
-    cdk->realize(cdev, &err);
-    if (err) {
+    cdk->realize(cdev, errp);
+    if (*errp) {
         goto out_err;
     }
 
     return;
 
 out_err:
-    error_propagate(errp, err);
     css_subch_assign(sch->cssid, sch->ssid, sch->schid, sch->devno, NULL);
     cdev->sch = NULL;
     g_free(sch);
hw/s390x/css-bridge.c +3 -4
index 15a8ed96de..93dca01b0f 100644
@@ -30,15 +30,14 @@
 static void ccw_device_unplug(HotplugHandler *hotplug_dev,
                               DeviceState *dev, Error **errp)
 {
+    ERRP_AUTO_PROPAGATE();
     CcwDevice *ccw_dev = CCW_DEVICE(dev);
     CCWDeviceClass *k = CCW_DEVICE_GET_CLASS(ccw_dev);
     SubchDev *sch = ccw_dev->sch;
-    Error *err = NULL;
 
     if (k->unplug) {
-        k->unplug(hotplug_dev, dev, &err);
-        if (err) {
-            error_propagate(errp, err);
+        k->unplug(hotplug_dev, dev, errp);
+        if (*errp) {
             return;
         }
     }
hw/s390x/css.c +3 -4
index 844caab408..e911d2fbd2 100644
@@ -2351,10 +2351,10 @@ static void get_css_devid(Object *obj, Visitor *v, const char *name,
 static void set_css_devid(Object *obj, Visitor *v, const char *name,
                           void *opaque, Error **errp)
 {
+    ERRP_AUTO_PROPAGATE();
     DeviceState *dev = DEVICE(obj);
     Property *prop = opaque;
     CssDevId *dev_id = qdev_get_prop_ptr(dev, prop);
-    Error *local_err = NULL;
     char *str;
     int num, n1, n2;
     unsigned int cssid, ssid, devid;
@@ -2364,9 +2364,8 @@ static void set_css_devid(Object *obj, Visitor *v, const char *name,
         return;
     }
 
-    visit_type_str(v, name, &str, &local_err);
-    if (local_err) {
-        error_propagate(errp, local_err);
+    visit_type_str(v, name, &str, errp);
+    if (*errp) {
         return;
     }
 
hw/s390x/s390-skeys.c +3 -4
index bd37f39120..f176db09c9 100644
@@ -107,11 +107,11 @@ void hmp_dump_skeys(Monitor *mon, const QDict *qdict)
 
 void qmp_dump_skeys(const char *filename, Error **errp)
 {
+    ERRP_AUTO_PROPAGATE();
     S390SKeysState *ss = s390_get_skeys_device();
     S390SKeysClass *skeyclass = S390_SKEYS_GET_CLASS(ss);
     const uint64_t total_count = ram_size / TARGET_PAGE_SIZE;
     uint64_t handled_count = 0, cur_count;
-    Error *lerr = NULL;
     vaddr cur_gfn = 0;
     uint8_t *buf;
     int ret;
@@ -155,8 +155,8 @@ void qmp_dump_skeys(const char *filename, Error **errp)
         }
 
         /* write keys to stream */
-        write_keys(f, buf, cur_gfn, cur_count, &lerr);
-        if (lerr) {
+        write_keys(f, buf, cur_gfn, cur_count, errp);
+        if (*errp) {
             goto out_free;
         }
 
@@ -165,7 +165,6 @@ void qmp_dump_skeys(const char *filename, Error **errp)
     }
 
 out_free:
-    error_propagate(errp, lerr);
     g_free(buf);
 out:
     fclose(f);
hw/s390x/s390-virtio-ccw.c +5 -6
index 18ad279a00..3c5e4c9804 100644
@@ -61,19 +61,18 @@ S390CPU *s390_cpu_addr2state(uint16_t cpu_addr)
 static S390CPU *s390x_new_cpu(const char *typename, uint32_t core_id,
                               Error **errp)
 {
+    ERRP_AUTO_PROPAGATE();
     S390CPU *cpu = S390_CPU(object_new(typename));
-    Error *err = NULL;
 
-    object_property_set_int(OBJECT(cpu), core_id, "core-id", &err);
-    if (err != NULL) {
+    object_property_set_int(OBJECT(cpu), core_id, "core-id", errp);
+    if (*errp) {
         goto out;
     }
-    object_property_set_bool(OBJECT(cpu), true, "realized", &err);
+    object_property_set_bool(OBJECT(cpu), true, "realized", errp);
 
 out:
     object_unref(OBJECT(cpu));
-    if (err) {
-        error_propagate(errp, err);
+    if (*errp) {
         cpu = NULL;
     }
     return cpu;
hw/s390x/sclp.c +6 -9
index f57ce7b739..4cacd7b3a8 100644
@@ -300,16 +300,16 @@ void s390_sclp_init(void)
 
 static void sclp_realize(DeviceState *dev, Error **errp)
 {
+    ERRP_AUTO_PROPAGATE();
     MachineState *machine = MACHINE(qdev_get_machine());
     SCLPDevice *sclp = SCLP(dev);
-    Error *err = NULL;
     uint64_t hw_limit;
     int ret;
 
     object_property_set_bool(OBJECT(sclp->event_facility), true, "realized",
-                             &err);
-    if (err) {
-        goto out;
+                             errp);
+    if (*errp) {
+        return;
     }
     /*
      * qdev_device_add searches the sysbus for TYPE_SCLP_EVENTS_BUS. As long
@@ -320,14 +320,11 @@ static void sclp_realize(DeviceState *dev, Error **errp)
 
     ret = s390_set_memory_limit(machine->maxram_size, &hw_limit);
     if (ret == -E2BIG) {
-        error_setg(&err, "host supports a maximum of %" PRIu64 " GB",
+        error_setg(errp, "host supports a maximum of %" PRIu64 " GB",
                    hw_limit / GiB);
     } else if (ret) {
-        error_setg(&err, "setting the guest size failed");
+        error_setg(errp, "setting the guest size failed");
     }
-
-out:
-    error_propagate(errp, err);
 }
 
 static void sclp_memory_init(SCLPDevice *sclp)
hw/s390x/tod-kvm.c +6 -8
index 6e21d83181..f59d07b375 100644
@@ -55,7 +55,7 @@ static void kvm_s390_set_tod_raw(const S390TOD *tod, Error **errp)
 
 static void kvm_s390_tod_set(S390TODState *td, const S390TOD *tod, Error **errp)
 {
-    Error *local_err = NULL;
+    ERRP_AUTO_PROPAGATE();
 
     /*
      * Somebody (e.g. migration) set the TOD. We'll store it into KVM to
@@ -64,9 +64,8 @@ static void kvm_s390_tod_set(S390TODState *td, const S390TOD *tod, Error **errp)
      * is the point where we want to stop the initially running TOD to fire
      * it back up when actually starting the migrated guest.
      */
-    kvm_s390_set_tod_raw(tod, &local_err);
-    if (local_err) {
-        error_propagate(errp, local_err);
+    kvm_s390_set_tod_raw(tod, errp);
+    if (*errp) {
         return;
     }
 
@@ -106,13 +105,12 @@ static void kvm_s390_tod_vm_state_change(void *opaque, int running,
 
 static void kvm_s390_tod_realize(DeviceState *dev, Error **errp)
 {
+    ERRP_AUTO_PROPAGATE();
     S390TODState *td = S390_TOD(dev);
     S390TODClass *tdc = S390_TOD_GET_CLASS(td);
-    Error *local_err = NULL;
 
-    tdc->parent_realize(dev, &local_err);
-    if (local_err) {
-        error_propagate(errp, local_err);
+    tdc->parent_realize(dev, errp);
+    if (*errp) {
         return;
     }
 
hw/vfio/ccw.c +11 -13
index 6863f6c69f..057c2e4f09 100644
@@ -476,38 +476,38 @@ static VFIOGroup *vfio_ccw_get_group(S390CCWDevice *cdev, Error **errp)
 
 static void vfio_ccw_realize(DeviceState *dev, Error **errp)
 {
+    ERRP_AUTO_PROPAGATE();
     VFIOGroup *group;
     CcwDevice *ccw_dev = DO_UPCAST(CcwDevice, parent_obj, dev);
     S390CCWDevice *cdev = DO_UPCAST(S390CCWDevice, parent_obj, ccw_dev);
     VFIOCCWDevice *vcdev = DO_UPCAST(VFIOCCWDevice, cdev, cdev);
     S390CCWDeviceClass *cdc = S390_CCW_DEVICE_GET_CLASS(cdev);
-    Error *err = NULL;
 
     /* Call the class init function for subchannel. */
     if (cdc->realize) {
-        cdc->realize(cdev, vcdev->vdev.sysfsdev, &err);
-        if (err) {
-            goto out_err_propagate;
+        cdc->realize(cdev, vcdev->vdev.sysfsdev, errp);
+        if (*errp) {
+            return;
         }
     }
 
-    group = vfio_ccw_get_group(cdev, &err);
+    group = vfio_ccw_get_group(cdev, errp);
     if (!group) {
         goto out_group_err;
     }
 
-    vfio_ccw_get_device(group, vcdev, &err);
-    if (err) {
+    vfio_ccw_get_device(group, vcdev, errp);
+    if (*errp) {
         goto out_device_err;
     }
 
-    vfio_ccw_get_region(vcdev, &err);
-    if (err) {
+    vfio_ccw_get_region(vcdev, errp);
+    if (*errp) {
         goto out_region_err;
     }
 
-    vfio_ccw_register_io_notifier(vcdev, &err);
-    if (err) {
+    vfio_ccw_register_io_notifier(vcdev, errp);
+    if (*errp) {
         goto out_notifier_err;
     }
 
@@ -523,8 +523,6 @@ out_group_err:
     if (cdc->unrealize) {
         cdc->unrealize(cdev, NULL);
     }
-out_err_propagate:
-    error_propagate(errp, err);
 }
 
 static void vfio_ccw_unrealize(DeviceState *dev, Error **errp)
target/s390x/cpu.c +12 -14
index 3abe7e80fd..5569b48934 100644
@@ -184,42 +184,42 @@ static void s390_cpu_disas_set_info(CPUState *cpu, disassemble_info *info)
 
 static void s390_cpu_realizefn(DeviceState *dev, Error **errp)
 {
+    ERRP_AUTO_PROPAGATE();
     CPUState *cs = CPU(dev);
     S390CPUClass *scc = S390_CPU_GET_CLASS(dev);
 #if !defined(CONFIG_USER_ONLY)
     S390CPU *cpu = S390_CPU(dev);
 #endif
-    Error *err = NULL;
 
     /* the model has to be realized before qemu_init_vcpu() due to kvm */
-    s390_realize_cpu_model(cs, &err);
-    if (err) {
-        goto out;
+    s390_realize_cpu_model(cs, errp);
+    if (*errp) {
+        return;
     }
 
 #if !defined(CONFIG_USER_ONLY)
     MachineState *ms = MACHINE(qdev_get_machine());
     unsigned int max_cpus = ms->smp.max_cpus;
     if (cpu->env.core_id >= max_cpus) {
-        error_setg(&err, "Unable to add CPU with core-id: %" PRIu32
+        error_setg(errp, "Unable to add CPU with core-id: %" PRIu32
                    ", maximum core-id: %d", cpu->env.core_id,
                    max_cpus - 1);
-        goto out;
+        return;
     }
 
     if (cpu_exists(cpu->env.core_id)) {
-        error_setg(&err, "Unable to add CPU with core-id: %" PRIu32
+        error_setg(errp, "Unable to add CPU with core-id: %" PRIu32
                    ", it already exists", cpu->env.core_id);
-        goto out;
+        return;
     }
 
     /* sync cs->cpu_index and env->core_id. The latter is needed for TCG. */
     cs->cpu_index = cpu->env.core_id;
 #endif
 
-    cpu_exec_realizefn(cs, &err);
-    if (err != NULL) {
-        goto out;
+    cpu_exec_realizefn(cs, errp);
+    if (*errp) {
+        return;
     }
 
 #if !defined(CONFIG_USER_ONLY)
@@ -240,9 +240,7 @@ static void s390_cpu_realizefn(DeviceState *dev, Error **errp)
         cpu_reset(cs);
     }
 
-    scc->parent_realize(dev, &err);
-out:
-    error_propagate(errp, err);
+    scc->parent_realize(dev, errp);
 }
 
 static GuestPanicInformation *s390_cpu_get_crash_info(CPUState *cs)
Signature · 1 line
2.21.0
#69 lore raw

Re: [RFC v5 028/126] s390x: introduce ERRP_AUTO_PROPAGATE

Quoted 6 lines · On Fri, 11 Oct 2019 19:04:14 +0300 Vladimir Sementsov-Ogievskiy…

If we want to add some info to errp (by error_prepend() or error_append_hint()), we must use the ERRP_AUTO_PROPAGATE macro. Otherwise, this info will not be added when errp == &fatal_err (the program will exit prior to the error_append_hint() or error_prepend() call). Fix such cases.

Quoted 7 lines

If we want to check error after errp-function call, we need to introduce local_err and than propagate it to errp. Instead, use ERRP_AUTO_PROPAGATE macro, benefits are:
1. No need of explicit error_propagate call
2. No need of explicit local_err variable: use errp directly
3. ERRP_AUTO_PROPAGATE leaves errp as is if it's not NULL or &error_fatel, this means that we don't break error_abort

s/fatel/fatal/ :)

Quoted 11 lines

(we'll abort on error_set, not on error_propagate)

This commit (together with its neighbors) was generated by

for f in $(git grep -l errp \*.[ch]); do \

    spatch --sp-file scripts/coccinelle/auto-propagated-errp.cocci \
    --macro-file scripts/cocci-macro-file.h --in-place --no-show-diff $f; \

done;

then fix a bit of compilation problems: coccinelle for some reason leaves several

Quoted 7 lines
f() {
    ...
    goto out;
    ...
    out:
}

patterns, with "out:" at function end.

I think you missed one of those...

Quoted 57 lines

then
./python/commit-per-subsystem.py MAINTAINERS "$(< auto-msg)"

(auto-msg was a file with this commit message)

Still, for backporting it may be more comfortable to use only the first command and then do one huge commit.

---
 hw/intc/s390_flic_kvm.c    |  9 ++++-----
 hw/s390x/3270-ccw.c        | 13 ++++++-------
 hw/s390x/css-bridge.c      |  7 +++----
 hw/s390x/css.c             |  7 +++----
 hw/s390x/s390-skeys.c      |  7 +++----
 hw/s390x/s390-virtio-ccw.c | 11 +++++------
 hw/s390x/sclp.c            | 15 ++++++---------
 hw/s390x/tod-kvm.c         | 14 ++++++--------
 hw/vfio/ccw.c              | 24 +++++++++++-------------
 target/s390x/cpu.c         | 26 ++++++++++++--------------
 10 files changed, 59 insertions(+), 74 deletions(-)
hw/intc/s390_flic_kvm.c +4 -4
index cedccba8a9..5550cecef8 100644
@@ -578,14 +578,14 @@ typedef struct KVMS390FLICStateClass {
 
 static void kvm_s390_flic_realize(DeviceState *dev, Error **errp)
 {
+    ERRP_AUTO_PROPAGATE();
     KVMS390FLICState *flic_state = KVM_S390_FLIC(dev);
     struct kvm_create_device cd = {0};
     struct kvm_device_attr test_attr = {0};
     int ret;
-    Error *errp_local = NULL;
 
-    KVM_S390_FLIC_GET_CLASS(dev)->parent_realize(dev, &errp_local);
-    if (errp_local) {
+    KVM_S390_FLIC_GET_CLASS(dev)->parent_realize(dev, errp);
+    if (*errp) {
         goto fail;
     }
     flic_state->fd = -1;
@@ -593,7 +593,7 @@ static void kvm_s390_flic_realize(DeviceState *dev, Error **errp)
     cd.type = KVM_DEV_TYPE_FLIC;
     ret = kvm_vm_ioctl(kvm_state, KVM_CREATE_DEVICE, &cd);
     if (ret < 0) {
-        error_setg_errno(&errp_local, errno, "Creating the KVM device failed");
+        error_setg_errno(errp, errno, "Creating the KVM device failed");
         trace_flic_create_device(errno);
         goto fail;
     }

hw/intc/s390_flic_kvm.c static void kvm_s390_flic_realize(DeviceState *dev, Error **errp) · line 608

Quoted 4 lines
hw/intc/s390_flic_kvm.c +0 -1
@@ -605,7 +605,6 @@ static void kvm_s390_flic_realize(DeviceState *dev, Error **errp)
                                             KVM_HAS_DEVICE_ATTR, test_attr);
     return;
 fail:
-    error_propagate(errp, errp_local);

...namely, here. (You probably did not compile on a s390x, so this file was not built.)

hw/intc/s390_flic_kvm.c static void kvm_s390_flic_realize(DeviceState *dev, Error **errp) · line 610

Quoted 3 lines
hw/intc/s390_flic_kvm.c +0 -0
 }
 
 static void kvm_s390_flic_reset(DeviceState *dev)

The rest of the transformations look sane.

#70 lore raw

RFC v5 29/126 tcg: introduce ERRP_AUTO_PROPAGATE

In reply to Vladimir Sementsov-Ogievskiy

If we want to add some info to errp (by error_prepend() or error_append_hint()), we must use the ERRP_AUTO_PROPAGATE macro. Otherwise, this info will not be added when errp == &fatal_err (the program will exit prior to the error_append_hint() or error_prepend() call). Fix such cases.

If we want to check error after errp-function call, we need to introduce local_err and than propagate it to errp. Instead, use ERRP_AUTO_PROPAGATE macro, benefits are:
1. No need of explicit error_propagate call
2. No need of explicit local_err variable: use errp directly
3. ERRP_AUTO_PROPAGATE leaves errp as is if it's not NULL or &error_fatel, this means that we don't break error_abort (we'll abort on error_set, not on error_propagate)

This commit (together with its neighbors) was generated by

for f in $(git grep -l errp \*.[ch]); do \

    spatch --sp-file scripts/coccinelle/auto-propagated-errp.cocci \
    --macro-file scripts/cocci-macro-file.h --in-place --no-show-diff $f; \

done;

then fix a bit of compilation problems: coccinelle for some reason leaves several

f() {
    ...
    goto out;
    ...
    out:
}

patterns, with "out:" at function end.

then
./python/commit-per-subsystem.py MAINTAINERS "$(< auto-msg)"

(auto-msg was a file with this commit message)

Still, for backporting it may be more comfortable to use only the first command and then do one huge commit.

---
 exec.c                          |  21 +++---
 hw/arm/armv7m.c                 |  52 ++++++--------
 hw/arm/smmu-common.c            |   7 +-
 hw/arm/smmuv3.c                 |   7 +-
 hw/cpu/a15mpcore.c              |   7 +-
 hw/cpu/a9mpcore.c               |  27 +++----
 hw/cpu/arm11mpcore.c            |  22 +++---
 hw/i386/pc.c                    | 120 +++++++++++++-------------------
 hw/intc/nios2_iic.c             |   6 +-
 hw/mips/cps.c                   |  46 ++++++------
 hw/riscv/riscv_hart.c           |   7 +-
 hw/riscv/sifive_e.c             |   7 +-
 hw/riscv/sifive_u.c             |  11 ++-
 hw/sd/milkymist-memcard.c       |  11 +--
 target/alpha/cpu.c              |   7 +-
 target/arm/cpu.c                |   7 +-
 target/arm/cpu64.c              |  11 ++-
 target/cris/cpu.c               |   7 +-
 target/hppa/cpu.c               |   7 +-
 target/i386/cpu.c               | 117 ++++++++++++++-----------------
 target/lm32/cpu.c               |   7 +-
 target/m68k/cpu.c               |   7 +-
 target/microblaze/cpu.c         |   7 +-
 target/mips/cpu.c               |   7 +-
 target/moxie/cpu.c              |   7 +-
 target/nios2/cpu.c              |   7 +-
 target/openrisc/cpu.c           |   7 +-
 target/ppc/compat.c             |  20 +++---
 target/ppc/translate_init.inc.c |  26 +++----
 target/riscv/cpu.c              |   7 +-
 target/sh4/cpu.c                |   7 +-
 target/sparc/cpu.c              |  14 ++--
 target/tricore/cpu.c            |   7 +-
 target/unicore32/cpu.c          |   7 +-
 target/xtensa/cpu.c             |   7 +-
 35 files changed, 280 insertions(+), 371 deletions(-)
exec.c +9 -12
index bdcfcdff3f..2dc17769f7 100644
@@ -2239,10 +2239,10 @@ static void dirty_memory_extend(ram_addr_t old_ram_size,
 
 static void ram_block_add(RAMBlock *new_block, Error **errp, bool shared)
 {
+    ERRP_AUTO_PROPAGATE();
     RAMBlock *block;
     RAMBlock *last_block = NULL;
     ram_addr_t old_ram_size, new_ram_size;
-    Error *err = NULL;
 
     old_ram_size = last_ram_page();
 
@@ -2252,9 +2252,8 @@ static void ram_block_add(RAMBlock *new_block, Error **errp, bool shared)
     if (!new_block->host) {
         if (xen_enabled()) {
             xen_ram_alloc(new_block->offset, new_block->max_length,
-                          new_block->mr, &err);
-            if (err) {
-                error_propagate(errp, err);
+                          new_block->mr, errp);
+            if (*errp) {
                 qemu_mutex_unlock_ramlist();
                 return;
             }
@@ -2319,8 +2318,8 @@ RAMBlock *qemu_ram_alloc_from_fd(ram_addr_t size, MemoryRegion *mr,
                                  uint32_t ram_flags, int fd,
                                  Error **errp)
 {
+    ERRP_AUTO_PROPAGATE();
     RAMBlock *new_block;
-    Error *local_err = NULL;
     int64_t file_size;
 
     /* Just support these ram flags by now. */
@@ -2368,10 +2367,9 @@ RAMBlock *qemu_ram_alloc_from_fd(ram_addr_t size, MemoryRegion *mr,
         return NULL;
     }
 
-    ram_block_add(new_block, &local_err, ram_flags & RAM_SHARED);
-    if (local_err) {
+    ram_block_add(new_block, errp, ram_flags & RAM_SHARED);
+    if (*errp) {
         g_free(new_block);
-        error_propagate(errp, local_err);
         return NULL;
     }
     return new_block;
@@ -2413,8 +2411,8 @@ RAMBlock *qemu_ram_alloc_internal(ram_addr_t size, ram_addr_t max_size,
                                   void *host, bool resizeable, bool share,
                                   MemoryRegion *mr, Error **errp)
 {
+    ERRP_AUTO_PROPAGATE();
     RAMBlock *new_block;
-    Error *local_err = NULL;
 
     size = HOST_PAGE_ALIGN(size);
     max_size = HOST_PAGE_ALIGN(max_size);
@@ -2433,10 +2431,9 @@ RAMBlock *qemu_ram_alloc_internal(ram_addr_t size, ram_addr_t max_size,
     if (resizeable) {
         new_block->flags |= RAM_RESIZEABLE;
     }
-    ram_block_add(new_block, &local_err, share);
-    if (local_err) {
+    ram_block_add(new_block, errp, share);
+    if (*errp) {
         g_free(new_block);
-        error_propagate(errp, local_err);
         return NULL;
     }
     return new_block;
hw/arm/armv7m.c +21 -31

112 lines not on this page · raw message

hw/arm/smmu-common.c +3 -4
index 245817d23e..b89d72db08 100644
@@ -421,13 +421,12 @@ void smmu_inv_notifiers_all(SMMUState *s)
 
 static void smmu_base_realize(DeviceState *dev, Error **errp)
 {
+    ERRP_AUTO_PROPAGATE();
     SMMUState *s = ARM_SMMU(dev);
     SMMUBaseClass *sbc = ARM_SMMU_GET_CLASS(dev);
-    Error *local_err = NULL;
 
-    sbc->parent_realize(dev, &local_err);
-    if (local_err) {
-        error_propagate(errp, local_err);
+    sbc->parent_realize(dev, errp);
+    if (*errp) {
         return;
     }
     s->configs = g_hash_table_new_full(NULL, NULL, NULL, g_free);
hw/arm/smmuv3.c +3 -4
index e2fbb8357e..d6ffd3a665 100644
@@ -1385,15 +1385,14 @@ static void smmu_reset(DeviceState *dev)
 
 static void smmu_realize(DeviceState *d, Error **errp)
 {
+    ERRP_AUTO_PROPAGATE();
     SMMUState *sys = ARM_SMMU(d);
     SMMUv3State *s = ARM_SMMUV3(sys);
     SMMUv3Class *c = ARM_SMMUV3_GET_CLASS(s);
     SysBusDevice *dev = SYS_BUS_DEVICE(d);
-    Error *local_err = NULL;
 
-    c->parent_realize(d, &local_err);
-    if (local_err) {
-        error_propagate(errp, local_err);
+    c->parent_realize(d, errp);
+    if (*errp) {
         return;
     }
 
hw/cpu/a15mpcore.c +3 -4
index 7e9983aa19..d010be7476 100644
@@ -49,12 +49,12 @@ static void a15mp_priv_initfn(Object *obj)
 
 static void a15mp_priv_realize(DeviceState *dev, Error **errp)
 {
+    ERRP_AUTO_PROPAGATE();
     SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
     A15MPPrivState *s = A15MPCORE_PRIV(dev);
     DeviceState *gicdev;
     SysBusDevice *busdev;
     int i;
-    Error *err = NULL;
     bool has_el3;
     bool has_el2 = false;
     Object *cpuobj;
@@ -77,9 +77,8 @@ static void a15mp_priv_realize(DeviceState *dev, Error **errp)
         qdev_prop_set_bit(gicdev, "has-virtualization-extensions", has_el2);
     }
 
-    object_property_set_bool(OBJECT(&s->gic), true, "realized", &err);
-    if (err != NULL) {
-        error_propagate(errp, err);
+    object_property_set_bool(OBJECT(&s->gic), true, "realized", errp);
+    if (*errp) {
         return;
     }
     busdev = SYS_BUS_DEVICE(&s->gic);
hw/cpu/a9mpcore.c +11 -16
index 6872a3a00a..9a66401cdd 100644
@@ -46,21 +46,20 @@ static void a9mp_priv_initfn(Object *obj)
 
 static void a9mp_priv_realize(DeviceState *dev, Error **errp)
 {
+    ERRP_AUTO_PROPAGATE();
     SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
     A9MPPrivState *s = A9MPCORE_PRIV(dev);
     DeviceState *scudev, *gicdev, *gtimerdev, *mptimerdev, *wdtdev;
     SysBusDevice *scubusdev, *gicbusdev, *gtimerbusdev, *mptimerbusdev,
                  *wdtbusdev;
-    Error *err = NULL;
     int i;
     bool has_el3;
     Object *cpuobj;
 
     scudev = DEVICE(&s->scu);
     qdev_prop_set_uint32(scudev, "num-cpu", s->num_cpu);
-    object_property_set_bool(OBJECT(&s->scu), true, "realized", &err);
-    if (err != NULL) {
-        error_propagate(errp, err);
+    object_property_set_bool(OBJECT(&s->scu), true, "realized", errp);
+    if (*errp) {
         return;
     }
     scubusdev = SYS_BUS_DEVICE(&s->scu);
@@ -77,9 +76,8 @@ static void a9mp_priv_realize(DeviceState *dev, Error **errp)
         object_property_get_bool(cpuobj, "has_el3", &error_abort);
     qdev_prop_set_bit(gicdev, "has-security-extensions", has_el3);
 
-    object_property_set_bool(OBJECT(&s->gic), true, "realized", &err);
-    if (err != NULL) {
-        error_propagate(errp, err);
+    object_property_set_bool(OBJECT(&s->gic), true, "realized", errp);
+    if (*errp) {
         return;
     }
     gicbusdev = SYS_BUS_DEVICE(&s->gic);
@@ -92,27 +90,24 @@ static void a9mp_priv_realize(DeviceState *dev, Error **errp)
 
     gtimerdev = DEVICE(&s->gtimer);
     qdev_prop_set_uint32(gtimerdev, "num-cpu", s->num_cpu);
-    object_property_set_bool(OBJECT(&s->gtimer), true, "realized", &err);
-    if (err != NULL) {
-        error_propagate(errp, err);
+    object_property_set_bool(OBJECT(&s->gtimer), true, "realized", errp);
+    if (*errp) {
         return;
     }
     gtimerbusdev = SYS_BUS_DEVICE(&s->gtimer);
 
     mptimerdev = DEVICE(&s->mptimer);
     qdev_prop_set_uint32(mptimerdev, "num-cpu", s->num_cpu);
-    object_property_set_bool(OBJECT(&s->mptimer), true, "realized", &err);
-    if (err != NULL) {
-        error_propagate(errp, err);
+    object_property_set_bool(OBJECT(&s->mptimer), true, "realized", errp);
+    if (*errp) {
         return;
     }
     mptimerbusdev = SYS_BUS_DEVICE(&s->mptimer);
 
     wdtdev = DEVICE(&s->wdt);
     qdev_prop_set_uint32(wdtdev, "num-cpu", s->num_cpu);
-    object_property_set_bool(OBJECT(&s->wdt), true, "realized", &err);
-    if (err != NULL) {
-        error_propagate(errp, err);
+    object_property_set_bool(OBJECT(&s->wdt), true, "realized", errp);
+    if (*errp) {
         return;
     }
     wdtbusdev = SYS_BUS_DEVICE(&s->wdt);
hw/cpu/arm11mpcore.c +9 -13
index e78f5d080c..21c2fa6289 100644
@@ -69,26 +69,24 @@ static void mpcore_priv_map_setup(ARM11MPCorePriveState *s)
 
 static void mpcore_priv_realize(DeviceState *dev, Error **errp)
 {
+    ERRP_AUTO_PROPAGATE();
     SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
     ARM11MPCorePriveState *s = ARM11MPCORE_PRIV(dev);
     DeviceState *scudev = DEVICE(&s->scu);
     DeviceState *gicdev = DEVICE(&s->gic);
     DeviceState *mptimerdev = DEVICE(&s->mptimer);
     DeviceState *wdtimerdev = DEVICE(&s->wdtimer);
-    Error *err = NULL;
 
     qdev_prop_set_uint32(scudev, "num-cpu", s->num_cpu);
-    object_property_set_bool(OBJECT(&s->scu), true, "realized", &err);
-    if (err != NULL) {
-        error_propagate(errp, err);
+    object_property_set_bool(OBJECT(&s->scu), true, "realized", errp);
+    if (*errp) {
         return;
     }
 
     qdev_prop_set_uint32(gicdev, "num-cpu", s->num_cpu);
     qdev_prop_set_uint32(gicdev, "num-irq", s->num_irq);
-    object_property_set_bool(OBJECT(&s->gic), true, "realized", &err);
-    if (err != NULL) {
-        error_propagate(errp, err);
+    object_property_set_bool(OBJECT(&s->gic), true, "realized", errp);
+    if (*errp) {
         return;
     }
 
@@ -99,16 +97,14 @@ static void mpcore_priv_realize(DeviceState *dev, Error **errp)
     qdev_init_gpio_in(dev, mpcore_priv_set_irq, s->num_irq - 32);
 
     qdev_prop_set_uint32(mptimerdev, "num-cpu", s->num_cpu);
-    object_property_set_bool(OBJECT(&s->mptimer), true, "realized", &err);
-    if (err != NULL) {
-        error_propagate(errp, err);
+    object_property_set_bool(OBJECT(&s->mptimer), true, "realized", errp);
+    if (*errp) {
         return;
     }
 
     qdev_prop_set_uint32(wdtimerdev, "num-cpu", s->num_cpu);
-    object_property_set_bool(OBJECT(&s->wdtimer), true, "realized", &err);
-    if (err != NULL) {
-        error_propagate(errp, err);
+    object_property_set_bool(OBJECT(&s->wdtimer), true, "realized", errp);
+    if (*errp) {
         return;
     }
 
hw/i386/pc.c +50 -70

305 lines not on this page · raw message

hw/intc/nios2_iic.c +3 -3
index 3a5d86c2a4..a291536bbe 100644
@@ -65,13 +65,13 @@ static void altera_iic_init(Object *obj)
 
 static void altera_iic_realize(DeviceState *dev, Error **errp)
 {
+    ERRP_AUTO_PROPAGATE();
     struct AlteraIIC *pv = ALTERA_IIC(dev);
-    Error *err = NULL;
 
-    pv->cpu = object_property_get_link(OBJECT(dev), "cpu", &err);
+    pv->cpu = object_property_get_link(OBJECT(dev), "cpu", errp);
     if (!pv->cpu) {
         error_setg(errp, "altera,iic: CPU link not found: %s",
-                   error_get_pretty(err));
+                   error_get_pretty(*errp));
         return;
     }
 }
hw/mips/cps.c +21 -25

84 lines not on this page · raw message

hw/riscv/riscv_hart.c +3 -4
index 5b98227db6..4c83693e48 100644
@@ -43,7 +43,7 @@ static void riscv_harts_cpu_reset(void *opaque)
 static void riscv_hart_realize(RISCVHartArrayState *s, int idx,
                                char *cpu_type, Error **errp)
 {
-    Error *err = NULL;
+    ERRP_AUTO_PROPAGATE();
 
     object_initialize_child(OBJECT(s), "harts[*]", &s->harts[idx],
                             sizeof(RISCVCPU), cpu_type,
@@ -51,9 +51,8 @@ static void riscv_hart_realize(RISCVHartArrayState *s, int idx,
     s->harts[idx].env.mhartid = s->hartid_base + idx;
     qemu_register_reset(riscv_harts_cpu_reset, &s->harts[idx]);
     object_property_set_bool(OBJECT(&s->harts[idx]), true,
-                             "realized", &err);
-    if (err) {
-        error_propagate(errp, err);
+                             "realized", errp);
+    if (*errp) {
         return;
     }
 }
hw/riscv/sifive_e.c +3 -4
index 0f9d641a0e..fbac83c684 100644
@@ -134,9 +134,9 @@ static void riscv_sifive_e_soc_init(Object *obj)
 
 static void riscv_sifive_e_soc_realize(DeviceState *dev, Error **errp)
 {
+    ERRP_AUTO_PROPAGATE();
     MachineState *ms = MACHINE(qdev_get_machine());
     const struct MemmapEntry *memmap = sifive_e_memmap;
-    Error *err = NULL;
 
     SiFiveESoCState *s = RISCV_E_SOC(dev);
     MemoryRegion *sys_mem = get_system_memory();
@@ -171,9 +171,8 @@ static void riscv_sifive_e_soc_realize(DeviceState *dev, Error **errp)
 
     /* GPIO */
 
-    object_property_set_bool(OBJECT(&s->gpio), true, "realized", &err);
-    if (err) {
-        error_propagate(errp, err);
+    object_property_set_bool(OBJECT(&s->gpio), true, "realized", errp);
+    if (*errp) {
         return;
     }
 
hw/riscv/sifive_u.c +5 -6
index 9f8e84bf2e..ab30e78969 100644
@@ -426,6 +426,7 @@ static void riscv_sifive_u_soc_init(Object *obj)
 
 static void riscv_sifive_u_soc_realize(DeviceState *dev, Error **errp)
 {
+    ERRP_AUTO_PROPAGATE();
     MachineState *ms = MACHINE(qdev_get_machine());
     SiFiveUSoCState *s = RISCV_U_SOC(dev);
     const struct MemmapEntry *memmap = sifive_u_memmap;
@@ -435,7 +436,6 @@ static void riscv_sifive_u_soc_realize(DeviceState *dev, Error **errp)
     char *plic_hart_config;
     size_t plic_hart_config_len;
     int i;
-    Error *err = NULL;
     NICInfo *nd = &nd_table[0];
 
     object_property_set_bool(OBJECT(&s->e_cpus), true, "realized",
@@ -493,10 +493,10 @@ static void riscv_sifive_u_soc_realize(DeviceState *dev, Error **errp)
         memmap[SIFIVE_U_CLINT].size, ms->smp.cpus,
         SIFIVE_SIP_BASE, SIFIVE_TIMECMP_BASE, SIFIVE_TIME_BASE);
 
-    object_property_set_bool(OBJECT(&s->prci), true, "realized", &err);
+    object_property_set_bool(OBJECT(&s->prci), true, "realized", errp);
     sysbus_mmio_map(SYS_BUS_DEVICE(&s->prci), 0, memmap[SIFIVE_U_PRCI].base);
 
-    object_property_set_bool(OBJECT(&s->otp), true, "realized", &err);
+    object_property_set_bool(OBJECT(&s->otp), true, "realized", errp);
     sysbus_mmio_map(SYS_BUS_DEVICE(&s->otp), 0, memmap[SIFIVE_U_OTP].base);
 
     for (i = 0; i < SIFIVE_U_PLIC_NUM_SOURCES; i++) {
@@ -509,9 +509,8 @@ static void riscv_sifive_u_soc_realize(DeviceState *dev, Error **errp)
     }
     object_property_set_int(OBJECT(&s->gem), GEM_REVISION, "revision",
                             &error_abort);
-    object_property_set_bool(OBJECT(&s->gem), true, "realized", &err);
-    if (err) {
-        error_propagate(errp, err);
+    object_property_set_bool(OBJECT(&s->gem), true, "realized", errp);
+    if (*errp) {
         return;
     }
     sysbus_mmio_map(SYS_BUS_DEVICE(&s->gem), 0, memmap[SIFIVE_U_GEM].base);
hw/sd/milkymist-memcard.c +6 -5
index 926e1af475..0aee7abc69 100644
@@ -265,11 +265,11 @@ static void milkymist_memcard_init(Object *obj)
 
 static void milkymist_memcard_realize(DeviceState *dev, Error **errp)
 {
+    ERRP_AUTO_PROPAGATE();
     MilkymistMemcardState *s = MILKYMIST_MEMCARD(dev);
     DeviceState *carddev;
     BlockBackend *blk;
     DriveInfo *dinfo;
-    Error *err = NULL;
 
     qbus_create_inplace(&s->sdbus, sizeof(s->sdbus), TYPE_SD_BUS,
                         dev, "sd-bus");
@@ -279,10 +279,11 @@ static void milkymist_memcard_realize(DeviceState *dev, Error **errp)
     dinfo = drive_get_next(IF_SD);
     blk = dinfo ? blk_by_legacy_dinfo(dinfo) : NULL;
     carddev = qdev_create(BUS(&s->sdbus), TYPE_SD_CARD);
-    qdev_prop_set_drive(carddev, "drive", blk, &err);
-    object_property_set_bool(OBJECT(carddev), true, "realized", &err);
-    if (err) {
-        error_setg(errp, "failed to init SD card: %s", error_get_pretty(err));
+    qdev_prop_set_drive(carddev, "drive", blk, errp);
+    object_property_set_bool(OBJECT(carddev), true, "realized", errp);
+    if (*errp) {
+        error_setg(errp, "failed to init SD card: %s",
+                   error_get_pretty(*errp));
         return;
     }
     s->enabled = blk && blk_is_inserted(blk);
target/alpha/cpu.c +3 -4
index b3fd6643e8..f093783c34 100644
@@ -56,13 +56,12 @@ static void alpha_cpu_disas_set_info(CPUState *cpu, disassemble_info *info)
 
 static void alpha_cpu_realizefn(DeviceState *dev, Error **errp)
 {
+    ERRP_AUTO_PROPAGATE();
     CPUState *cs = CPU(dev);
     AlphaCPUClass *acc = ALPHA_CPU_GET_CLASS(dev);
-    Error *local_err = NULL;
 
-    cpu_exec_realizefn(cs, &local_err);
-    if (local_err != NULL) {
-        error_propagate(errp, local_err);
+    cpu_exec_realizefn(cs, errp);
+    if (*errp) {
         return;
     }
 
target/arm/cpu.c +3 -4
index 2399c14471..07b4bbe82b 100644
@@ -1200,12 +1200,12 @@ static void arm_cpu_finalizefn(Object *obj)
 
 static void arm_cpu_realizefn(DeviceState *dev, Error **errp)
 {
+    ERRP_AUTO_PROPAGATE();
     CPUState *cs = CPU(dev);
     ARMCPU *cpu = ARM_CPU(dev);
     ARMCPUClass *acc = ARM_CPU_GET_CLASS(dev);
     CPUARMState *env = &cpu->env;
     int pagebits;
-    Error *local_err = NULL;
     bool no_aa32 = false;
 
     /* If we needed to query the host kernel for the CPU features
@@ -1248,9 +1248,8 @@ static void arm_cpu_realizefn(DeviceState *dev, Error **errp)
                                           arm_gt_stimer_cb, cpu);
 #endif
 
-    cpu_exec_realizefn(cs, &local_err);
-    if (local_err != NULL) {
-        error_propagate(errp, local_err);
+    cpu_exec_realizefn(cs, errp);
+    if (*errp) {
         return;
     }
 
target/arm/cpu64.c +5 -6
index d7f5bf610a..15a96e68be 100644
@@ -266,17 +266,16 @@ static void cpu_max_get_sve_vq(Object *obj, Visitor *v, const char *name,
 static void cpu_max_set_sve_vq(Object *obj, Visitor *v, const char *name,
                                void *opaque, Error **errp)
 {
+    ERRP_AUTO_PROPAGATE();
     ARMCPU *cpu = ARM_CPU(obj);
-    Error *err = NULL;
 
-    visit_type_uint32(v, name, &cpu->sve_max_vq, &err);
+    visit_type_uint32(v, name, &cpu->sve_max_vq, errp);
 
-    if (!err && (cpu->sve_max_vq == 0 || cpu->sve_max_vq > ARM_MAX_VQ)) {
-        error_setg(&err, "unsupported SVE vector length");
-        error_append_hint(&err, "Valid sve-max-vq in range [1-%d]\n",
+    if (!*errp && (cpu->sve_max_vq == 0 || cpu->sve_max_vq > ARM_MAX_VQ)) {
+        error_setg(errp, "unsupported SVE vector length");
+        error_append_hint(errp, "Valid sve-max-vq in range [1-%d]\n",
                           ARM_MAX_VQ);
     }
-    error_propagate(errp, err);
 }
 
 /* -cpu max: if KVM is enabled, like -cpu host (best possible with this host);
target/cris/cpu.c +3 -4
index 7adfd6caf4..296b68dff6 100644
@@ -124,13 +124,12 @@ void cris_cpu_list(void)
 
 static void cris_cpu_realizefn(DeviceState *dev, Error **errp)
 {
+    ERRP_AUTO_PROPAGATE();
     CPUState *cs = CPU(dev);
     CRISCPUClass *ccc = CRIS_CPU_GET_CLASS(dev);
-    Error *local_err = NULL;
 
-    cpu_exec_realizefn(cs, &local_err);
-    if (local_err != NULL) {
-        error_propagate(errp, local_err);
+    cpu_exec_realizefn(cs, errp);
+    if (*errp) {
         return;
     }
 
target/hppa/cpu.c +3 -4
index 71b6aca45d..f6f2e3980c 100644
@@ -89,13 +89,12 @@ static void hppa_cpu_do_unaligned_access(CPUState *cs, vaddr addr,
 
 static void hppa_cpu_realizefn(DeviceState *dev, Error **errp)
 {
+    ERRP_AUTO_PROPAGATE();
     CPUState *cs = CPU(dev);
     HPPACPUClass *acc = HPPA_CPU_GET_CLASS(dev);
-    Error *local_err = NULL;
 
-    cpu_exec_realizefn(cs, &local_err);
-    if (local_err != NULL) {
-        error_propagate(errp, local_err);
+    cpu_exec_realizefn(cs, errp);
+    if (*errp) {
         return;
     }
 
target/i386/cpu.c +52 -65

330 lines not on this page · raw message

target/lm32/cpu.c +3 -4
index b35537de62..c876c8d7d4 100644
@@ -122,13 +122,12 @@ static void lm32_cpu_disas_set_info(CPUState *cpu, disassemble_info *info)
 
 static void lm32_cpu_realizefn(DeviceState *dev, Error **errp)
 {
+    ERRP_AUTO_PROPAGATE();
     CPUState *cs = CPU(dev);
     LM32CPUClass *lcc = LM32_CPU_GET_CLASS(dev);
-    Error *local_err = NULL;
 
-    cpu_exec_realizefn(cs, &local_err);
-    if (local_err != NULL) {
-        error_propagate(errp, local_err);
+    cpu_exec_realizefn(cs, errp);
+    if (*errp) {
         return;
     }
 
target/m68k/cpu.c +3 -4
index e6596de29c..b83eca5cfa 100644
@@ -216,16 +216,15 @@ static void any_cpu_initfn(Object *obj)
 
 static void m68k_cpu_realizefn(DeviceState *dev, Error **errp)
 {
+    ERRP_AUTO_PROPAGATE();
     CPUState *cs = CPU(dev);
     M68kCPU *cpu = M68K_CPU(dev);
     M68kCPUClass *mcc = M68K_CPU_GET_CLASS(dev);
-    Error *local_err = NULL;
 
     register_m68k_insns(&cpu->env);
 
-    cpu_exec_realizefn(cs, &local_err);
-    if (local_err != NULL) {
-        error_propagate(errp, local_err);
+    cpu_exec_realizefn(cs, errp);
+    if (*errp) {
         return;
     }
 
target/microblaze/cpu.c +3 -4
index 9cfd7445e7..d1591cc23a 100644
@@ -140,6 +140,7 @@ static void mb_disas_set_info(CPUState *cpu, disassemble_info *info)
 
 static void mb_cpu_realizefn(DeviceState *dev, Error **errp)
 {
+    ERRP_AUTO_PROPAGATE();
     CPUState *cs = CPU(dev);
     MicroBlazeCPUClass *mcc = MICROBLAZE_CPU_GET_CLASS(dev);
     MicroBlazeCPU *cpu = MICROBLAZE_CPU(cs);
@@ -147,11 +148,9 @@ static void mb_cpu_realizefn(DeviceState *dev, Error **errp)
     uint8_t version_code = 0;
     const char *version;
     int i = 0;
-    Error *local_err = NULL;
 
-    cpu_exec_realizefn(cs, &local_err);
-    if (local_err != NULL) {
-        error_propagate(errp, local_err);
+    cpu_exec_realizefn(cs, errp);
+    if (*errp) {
         return;
     }
 
target/mips/cpu.c +3 -4
index bbcf7ca463..89b661e7ff 100644
@@ -136,14 +136,13 @@ static void mips_cpu_disas_set_info(CPUState *s, disassemble_info *info)
 
 static void mips_cpu_realizefn(DeviceState *dev, Error **errp)
 {
+    ERRP_AUTO_PROPAGATE();
     CPUState *cs = CPU(dev);
     MIPSCPU *cpu = MIPS_CPU(dev);
     MIPSCPUClass *mcc = MIPS_CPU_GET_CLASS(dev);
-    Error *local_err = NULL;
 
-    cpu_exec_realizefn(cs, &local_err);
-    if (local_err != NULL) {
-        error_propagate(errp, local_err);
+    cpu_exec_realizefn(cs, errp);
+    if (*errp) {
         return;
     }
 
target/moxie/cpu.c +3 -4
index 48996d0554..19fe37284c 100644
@@ -55,13 +55,12 @@ static void moxie_cpu_disas_set_info(CPUState *cpu, disassemble_info *info)
 
 static void moxie_cpu_realizefn(DeviceState *dev, Error **errp)
 {
+    ERRP_AUTO_PROPAGATE();
     CPUState *cs = CPU(dev);
     MoxieCPUClass *mcc = MOXIE_CPU_GET_CLASS(dev);
-    Error *local_err = NULL;
 
-    cpu_exec_realizefn(cs, &local_err);
-    if (local_err != NULL) {
-        error_propagate(errp, local_err);
+    cpu_exec_realizefn(cs, errp);
+    if (*errp) {
         return;
     }
 
target/nios2/cpu.c +3 -4
index ca9c7a6df5..3cdaa0010b 100644
@@ -82,13 +82,12 @@ static ObjectClass *nios2_cpu_class_by_name(const char *cpu_model)
 
 static void nios2_cpu_realizefn(DeviceState *dev, Error **errp)
 {
+    ERRP_AUTO_PROPAGATE();
     CPUState *cs = CPU(dev);
     Nios2CPUClass *ncc = NIOS2_CPU_GET_CLASS(dev);
-    Error *local_err = NULL;
 
-    cpu_exec_realizefn(cs, &local_err);
-    if (local_err != NULL) {
-        error_propagate(errp, local_err);
+    cpu_exec_realizefn(cs, errp);
+    if (*errp) {
         return;
     }
 
target/openrisc/cpu.c +3 -4
index 506aec6bfb..f297a2f96d 100644
@@ -67,13 +67,12 @@ static void openrisc_cpu_reset(CPUState *s)
 
 static void openrisc_cpu_realizefn(DeviceState *dev, Error **errp)
 {
+    ERRP_AUTO_PROPAGATE();
     CPUState *cs = CPU(dev);
     OpenRISCCPUClass *occ = OPENRISC_CPU_GET_CLASS(dev);
-    Error *local_err = NULL;
 
-    cpu_exec_realizefn(cs, &local_err);
-    if (local_err != NULL) {
-        error_propagate(errp, local_err);
+    cpu_exec_realizefn(cs, errp);
+    if (*errp) {
         return;
     }
 
target/ppc/compat.c +8 -12
index 7de4bf3122..610de2fb07 100644
@@ -251,13 +251,12 @@ static void ppc_compat_prop_get(Object *obj, Visitor *v, const char *name,
 static void ppc_compat_prop_set(Object *obj, Visitor *v, const char *name,
                                 void *opaque, Error **errp)
 {
-    Error *local_err = NULL;
+    ERRP_AUTO_PROPAGATE();
     char *value;
     uint32_t compat_pvr;
 
-    visit_type_str(v, name, &value, &local_err);
-    if (local_err) {
-        error_propagate(errp, local_err);
+    visit_type_str(v, name, &value, errp);
+    if (*errp) {
         return;
     }
 
@@ -292,16 +291,16 @@ void ppc_compat_add_property(Object *obj, const char *name,
                              uint32_t *compat_pvr, const char *basedesc,
                              Error **errp)
 {
-    Error *local_err = NULL;
+    ERRP_AUTO_PROPAGATE();
     gchar *namesv[ARRAY_SIZE(compat_table) + 1];
     gchar *names, *desc;
     int i;
 
     object_property_add(obj, name, "string",
                         ppc_compat_prop_get, ppc_compat_prop_set, NULL,
-                        compat_pvr, &local_err);
-    if (local_err) {
-        goto out;
+                        compat_pvr, errp);
+    if (*errp) {
+        return;
     }
 
     for (i = 0; i < ARRAY_SIZE(compat_table); i++) {
@@ -315,11 +314,8 @@ void ppc_compat_add_property(Object *obj, const char *name,
 
     names = g_strjoinv(", ", namesv);
     desc = g_strdup_printf("%s. Valid values are %s.", basedesc, names);
-    object_property_set_description(obj, name, desc, &local_err);
+    object_property_set_description(obj, name, desc, errp);
 
     g_free(names);
     g_free(desc);
-
-out:
-    error_propagate(errp, local_err);
 }
target/ppc/translate_init.inc.c +11 -15
index ba726dec4d..1f4c2d4b94 100644
@@ -9807,14 +9807,13 @@ static int ppc_fixup_cpu(PowerPCCPU *cpu)
 
 static void ppc_cpu_realize(DeviceState *dev, Error **errp)
 {
+    ERRP_AUTO_PROPAGATE();
     CPUState *cs = CPU(dev);
     PowerPCCPU *cpu = POWERPC_CPU(dev);
     PowerPCCPUClass *pcc = POWERPC_CPU_GET_CLASS(cpu);
-    Error *local_err = NULL;
 
-    cpu_exec_realizefn(cs, &local_err);
-    if (local_err != NULL) {
-        error_propagate(errp, local_err);
+    cpu_exec_realizefn(cs, errp);
+    if (*errp) {
         return;
     }
     if (cpu->vcpu_id == UNASSIGNED_CPU_INDEX) {
@@ -9828,9 +9827,8 @@ static void ppc_cpu_realize(DeviceState *dev, Error **errp)
         }
     }
 
-    create_ppc_opcodes(cpu, &local_err);
-    if (local_err != NULL) {
-        error_propagate(errp, local_err);
+    create_ppc_opcodes(cpu, errp);
+    if (*errp) {
         goto unrealize;
     }
     init_ppc_proc(cpu);
@@ -10033,15 +10031,14 @@ unrealize:
 
 static void ppc_cpu_unrealize(DeviceState *dev, Error **errp)
 {
+    ERRP_AUTO_PROPAGATE();
     PowerPCCPU *cpu = POWERPC_CPU(dev);
     PowerPCCPUClass *pcc = POWERPC_CPU_GET_CLASS(cpu);
-    Error *local_err = NULL;
     opc_handler_t **table, **table_2;
     int i, j, k;
 
-    pcc->parent_unrealize(dev, &local_err);
-    if (local_err != NULL) {
-        error_propagate(errp, local_err);
+    pcc->parent_unrealize(dev, errp);
+    if (*errp) {
         return;
     }
 
@@ -10188,6 +10185,7 @@ static ObjectClass *ppc_cpu_class_by_name(const char *name)
 static void ppc_cpu_parse_featurestr(const char *type, char *features,
                                      Error **errp)
 {
+    ERRP_AUTO_PROPAGATE();
     Object *machine = qdev_get_machine();
     const PowerPCCPUClass *pcc = POWERPC_CPU_CLASS(object_class_by_name(type));
 
@@ -10199,7 +10197,6 @@ static void ppc_cpu_parse_featurestr(const char *type, char *features,
         int i;
         char **inpieces;
         char *s = features;
-        Error *local_err = NULL;
         char *compat_str = NULL;
 
         /*
@@ -10227,11 +10224,10 @@ static void ppc_cpu_parse_featurestr(const char *type, char *features,
 
         if (compat_str) {
             char *v = compat_str + strlen("compat=");
-            object_property_set_str(machine, v, "max-cpu-compat", &local_err);
+            object_property_set_str(machine, v, "max-cpu-compat", errp);
         }
         g_strfreev(inpieces);
-        if (local_err) {
-            error_propagate(errp, local_err);
+        if (*errp) {
             return;
         }
     }
target/riscv/cpu.c +3 -4
index f13e298a36..6f27404b89 100644
@@ -316,17 +316,16 @@ static void riscv_cpu_disas_set_info(CPUState *s, disassemble_info *info)
 
 static void riscv_cpu_realize(DeviceState *dev, Error **errp)
 {
+    ERRP_AUTO_PROPAGATE();
     CPUState *cs = CPU(dev);
     RISCVCPU *cpu = RISCV_CPU(dev);
     CPURISCVState *env = &cpu->env;
     RISCVCPUClass *mcc = RISCV_CPU_GET_CLASS(dev);
     int priv_version = PRIV_VERSION_1_11_0;
     target_ulong target_misa = 0;
-    Error *local_err = NULL;
 
-    cpu_exec_realizefn(cs, &local_err);
-    if (local_err != NULL) {
-        error_propagate(errp, local_err);
+    cpu_exec_realizefn(cs, errp);
+    if (*errp) {
         return;
     }
 
target/sh4/cpu.c +3 -4
index d0a7707991..d17d398a75 100644
@@ -174,13 +174,12 @@ static void sh7785_class_init(ObjectClass *oc, void *data)
 
 static void superh_cpu_realizefn(DeviceState *dev, Error **errp)
 {
+    ERRP_AUTO_PROPAGATE();
     CPUState *cs = CPU(dev);
     SuperHCPUClass *scc = SUPERH_CPU_GET_CLASS(dev);
-    Error *local_err = NULL;
 
-    cpu_exec_realizefn(cs, &local_err);
-    if (local_err != NULL) {
-        error_propagate(errp, local_err);
+    cpu_exec_realizefn(cs, errp);
+    if (*errp) {
         return;
     }
 
target/sparc/cpu.c +6 -8
index bc65929552..2f631ed63b 100644
@@ -736,9 +736,9 @@ static ObjectClass *sparc_cpu_class_by_name(const char *cpu_model)
 
 static void sparc_cpu_realizefn(DeviceState *dev, Error **errp)
 {
+    ERRP_AUTO_PROPAGATE();
     CPUState *cs = CPU(dev);
     SPARCCPUClass *scc = SPARC_CPU_GET_CLASS(dev);
-    Error *local_err = NULL;
     SPARCCPU *cpu = SPARC_CPU(dev);
     CPUSPARCState *env = &cpu->env;
 
@@ -762,9 +762,8 @@ static void sparc_cpu_realizefn(DeviceState *dev, Error **errp)
     env->version |= env->def.nwindows - 1;
 #endif
 
-    cpu_exec_realizefn(cs, &local_err);
-    if (local_err != NULL) {
-        error_propagate(errp, local_err);
+    cpu_exec_realizefn(cs, errp);
+    if (*errp) {
         return;
     }
 
@@ -798,15 +797,14 @@ static void sparc_get_nwindows(Object *obj, Visitor *v, const char *name,
 static void sparc_set_nwindows(Object *obj, Visitor *v, const char *name,
                                void *opaque, Error **errp)
 {
+    ERRP_AUTO_PROPAGATE();
     const int64_t min = MIN_NWINDOWS;
     const int64_t max = MAX_NWINDOWS;
     SPARCCPU *cpu = SPARC_CPU(obj);
-    Error *err = NULL;
     int64_t value;
 
-    visit_type_int(v, name, &value, &err);
-    if (err) {
-        error_propagate(errp, err);
+    visit_type_int(v, name, &value, errp);
+    if (*errp) {
         return;
     }
 
target/tricore/cpu.c +3 -4
index df807c1d74..becb4a1ae9 100644
@@ -71,15 +71,14 @@ static bool tricore_cpu_has_work(CPUState *cs)
 
 static void tricore_cpu_realizefn(DeviceState *dev, Error **errp)
 {
+    ERRP_AUTO_PROPAGATE();
     CPUState *cs = CPU(dev);
     TriCoreCPU *cpu = TRICORE_CPU(dev);
     TriCoreCPUClass *tcc = TRICORE_CPU_GET_CLASS(dev);
     CPUTriCoreState *env = &cpu->env;
-    Error *local_err = NULL;
 
-    cpu_exec_realizefn(cs, &local_err);
-    if (local_err != NULL) {
-        error_propagate(errp, local_err);
+    cpu_exec_realizefn(cs, errp);
+    if (*errp) {
         return;
     }
 
target/unicore32/cpu.c +3 -4
index b27fb9689f..1f3fbe6c1a 100644
@@ -84,13 +84,12 @@ static void uc32_any_cpu_initfn(Object *obj)
 
 static void uc32_cpu_realizefn(DeviceState *dev, Error **errp)
 {
+    ERRP_AUTO_PROPAGATE();
     CPUState *cs = CPU(dev);
     UniCore32CPUClass *ucc = UNICORE32_CPU_GET_CLASS(dev);
-    Error *local_err = NULL;
 
-    cpu_exec_realizefn(cs, &local_err);
-    if (local_err != NULL) {
-        error_propagate(errp, local_err);
+    cpu_exec_realizefn(cs, errp);
+    if (*errp) {
         return;
     }
 
target/xtensa/cpu.c +3 -4
index c65dcf9dd7..0b2811f8e0 100644
@@ -131,17 +131,16 @@ static void xtensa_cpu_disas_set_info(CPUState *cs, disassemble_info *info)
 
 static void xtensa_cpu_realizefn(DeviceState *dev, Error **errp)
 {
+    ERRP_AUTO_PROPAGATE();
     CPUState *cs = CPU(dev);
     XtensaCPUClass *xcc = XTENSA_CPU_GET_CLASS(dev);
-    Error *local_err = NULL;
 
 #ifndef CONFIG_USER_ONLY
     xtensa_irq_init(&XTENSA_CPU(dev)->env);
 #endif
 
-    cpu_exec_realizefn(cs, &local_err);
-    if (local_err != NULL) {
-        error_propagate(errp, local_err);
+    cpu_exec_realizefn(cs, errp);
+    if (*errp) {
         return;
     }
 
Signature · 1 line
2.21.0
#71 lore raw

RFC v5 30/126 kvm: introduce ERRP_AUTO_PROPAGATE

In reply to Vladimir Sementsov-Ogievskiy

If we want to add some info to errp (by error_prepend() or error_append_hint()), we must use the ERRP_AUTO_PROPAGATE macro. Otherwise, this info will not be added when errp == &fatal_err (the program will exit prior to the error_append_hint() or error_prepend() call). Fix such cases.

If we want to check error after errp-function call, we need to introduce local_err and than propagate it to errp. Instead, use ERRP_AUTO_PROPAGATE macro, benefits are:
1. No need of explicit error_propagate call
2. No need of explicit local_err variable: use errp directly
3. ERRP_AUTO_PROPAGATE leaves errp as is if it's not NULL or &error_fatel, this means that we don't break error_abort (we'll abort on error_set, not on error_propagate)

This commit (together with its neighbors) was generated by

for f in $(git grep -l errp \*.[ch]); do \

    spatch --sp-file scripts/coccinelle/auto-propagated-errp.cocci \
    --macro-file scripts/cocci-macro-file.h --in-place --no-show-diff $f; \

done;

then fix a bit of compilation problems: coccinelle for some reason leaves several

f() {
    ...
    goto out;
    ...
    out:
}

patterns, with "out:" at function end.

then
./python/commit-per-subsystem.py MAINTAINERS "$(< auto-msg)"

(auto-msg was a file with this commit message)

Still, for backporting it may be more comfortable to use only the first command and then do one huge commit.

---
 target/ppc/kvm.c          | 8 ++++----
 target/s390x/cpu_models.c | 2 ++
 2 files changed, 6 insertions(+), 4 deletions(-)
target/ppc/kvm.c +4 -4
index af6e667bf8..d58a3f5bf5 100644
@@ -237,6 +237,7 @@ static int kvm_booke206_tlb_init(PowerPCCPU *cpu)
 #if defined(TARGET_PPC64)
 static void kvm_get_smmu_info(struct kvm_ppc_smmu_info *info, Error **errp)
 {
+    ERRP_AUTO_PROPAGATE();
     int ret;
 
     assert(kvm_state != NULL);
@@ -325,18 +326,17 @@ bool kvmppc_hpt_needs_host_contiguous_pages(void)
 
 void kvm_check_mmu(PowerPCCPU *cpu, Error **errp)
 {
+    ERRP_AUTO_PROPAGATE();
     struct kvm_ppc_smmu_info smmu_info;
     int iq, ik, jq, jk;
-    Error *local_err = NULL;
 
     /* For now, we only have anything to check on hash64 MMUs */
     if (!cpu->hash64_opts || !kvm_enabled()) {
         return;
     }
 
-    kvm_get_smmu_info(&smmu_info, &local_err);
-    if (local_err) {
-        error_propagate(errp, local_err);
+    kvm_get_smmu_info(&smmu_info, errp);
+    if (*errp) {
         return;
     }
 
target/s390x/cpu_models.c +2 -0
index 009afc38b9..32f2e5e822 100644
@@ -840,6 +840,7 @@ static void error_prepend_missing_feat(const char *name, void *opaque)
 static void check_compatibility(const S390CPUModel *max_model,
                                 const S390CPUModel *model, Error **errp)
 {
+    ERRP_AUTO_PROPAGATE();
     S390FeatBitmap missing;
 
     if (model->def->gen > max_model->def->gen) {
@@ -922,6 +923,7 @@ static inline void apply_cpu_model(const S390CPUModel *model, Error **errp)
 
 void s390_realize_cpu_model(CPUState *cs, Error **errp)
 {
+    ERRP_AUTO_PROPAGATE();
     S390CPUClass *xcc = S390_CPU_GET_CLASS(cs);
     S390CPU *cpu = S390_CPU(cs);
     const S390CPUModel *max_model;
Signature · 1 line
2.21.0
Reviewed-by on v5 30/126
#72 lore raw

Re: [RFC v5 030/126] kvm: introduce ERRP_AUTO_PROPAGATE

Quoted 40 lines · On Fri, 11 Oct 2019 19:04:16 +0300 Vladimir Sementsov-Ogievskiy…

If we want to add some info to errp (by error_prepend() or error_append_hint()), we must use the ERRP_AUTO_PROPAGATE macro. Otherwise, this info will not be added when errp == &fatal_err (the program will exit prior to the error_append_hint() or error_prepend() call). Fix such cases.

If we want to check error after errp-function call, we need to introduce local_err and than propagate it to errp. Instead, use ERRP_AUTO_PROPAGATE macro, benefits are:
1. No need of explicit error_propagate call
2. No need of explicit local_err variable: use errp directly
3. ERRP_AUTO_PROPAGATE leaves errp as is if it's not NULL or &error_fatel, this means that we don't break error_abort (we'll abort on error_set, not on error_propagate)

This commit (together with its neighbors) was generated by

for f in $(git grep -l errp \*.[ch]); do \

    spatch --sp-file scripts/coccinelle/auto-propagated-errp.cocci \
    --macro-file scripts/cocci-macro-file.h --in-place --no-show-diff $f; \

done;

then fix a bit of compilation problems: coccinelle for some reason leaves several

f() {
    ...
    goto out;
    ...
    out:
}

patterns, with "out:" at function end.

then
./python/commit-per-subsystem.py MAINTAINERS "$(< auto-msg)"

(auto-msg was a file with this commit message)

Still, for backporting it may be more comfortable to use only the first command and then do one huge commit.

Quoted 6 lines
---
 target/ppc/kvm.c          | 8 ++++----
 target/s390x/cpu_models.c | 2 ++

This grouping seems a bit unintuitive :)

Quoted 2 lines
 2 files changed, 6 insertions(+), 4 deletions(-)

s390x part:

#73 lore raw

RFC v5 31/126 xen: introduce ERRP_AUTO_PROPAGATE

In reply to Vladimir Sementsov-Ogievskiy

If we want to add some info to errp (by error_prepend() or error_append_hint()), we must use the ERRP_AUTO_PROPAGATE macro. Otherwise, this info will not be added when errp == &fatal_err (the program will exit prior to the error_append_hint() or error_prepend() call). Fix such cases.

If we want to check error after errp-function call, we need to introduce local_err and than propagate it to errp. Instead, use ERRP_AUTO_PROPAGATE macro, benefits are:
1. No need of explicit error_propagate call
2. No need of explicit local_err variable: use errp directly
3. ERRP_AUTO_PROPAGATE leaves errp as is if it's not NULL or &error_fatel, this means that we don't break error_abort (we'll abort on error_set, not on error_propagate)

This commit (together with its neighbors) was generated by

for f in $(git grep -l errp \*.[ch]); do \

    spatch --sp-file scripts/coccinelle/auto-propagated-errp.cocci \
    --macro-file scripts/cocci-macro-file.h --in-place --no-show-diff $f; \

done;

then fix a bit of compilation problems: coccinelle for some reason leaves several

f() {
    ...
    goto out;
    ...
    out:
}

patterns, with "out:" at function end.

then
./python/commit-per-subsystem.py MAINTAINERS "$(< auto-msg)"

(auto-msg was a file with this commit message)

Still, for backporting it may be more comfortable to use only the first command and then do one huge commit.

---
 hw/block/dataplane/xen-block.c |  17 ++---
 hw/block/xen-block.c           | 119 ++++++++++++++-------------------
 hw/xen/xen-backend.c           |   7 +-
 hw/xen/xen-bus.c               |  92 ++++++++++++-------------
 hw/xen/xen-host-pci-device.c   |  27 ++++----
 hw/xen/xen_pt.c                |  25 +++----
 hw/xen/xen_pt_config_init.c    |  20 +++---
 7 files changed, 139 insertions(+), 168 deletions(-)
hw/block/dataplane/xen-block.c +7 -10
index 3b9caeb2fa..c38e3c3d85 100644
@@ -727,8 +727,8 @@ void xen_block_dataplane_start(XenBlockDataPlane *dataplane,
                                unsigned int protocol,
                                Error **errp)
 {
+    ERRP_AUTO_PROPAGATE();
     XenDevice *xendev = dataplane->xendev;
-    Error *local_err = NULL;
     unsigned int ring_size;
     unsigned int i;
 
@@ -764,9 +764,8 @@ void xen_block_dataplane_start(XenBlockDataPlane *dataplane,
     }
 
     xen_device_set_max_grant_refs(xendev, dataplane->nr_ring_ref,
-                                  &local_err);
-    if (local_err) {
-        error_propagate(errp, local_err);
+                                  errp);
+    if (*errp) {
         goto stop;
     }
 
@@ -774,9 +773,8 @@ void xen_block_dataplane_start(XenBlockDataPlane *dataplane,
                                               dataplane->ring_ref,
                                               dataplane->nr_ring_ref,
                                               PROT_READ | PROT_WRITE,
-                                              &local_err);
-    if (local_err) {
-        error_propagate(errp, local_err);
+                                              errp);
+    if (*errp) {
         goto stop;
     }
 
@@ -809,9 +807,8 @@ void xen_block_dataplane_start(XenBlockDataPlane *dataplane,
     dataplane->event_channel =
         xen_device_bind_event_channel(xendev, dataplane->ctx, event_channel,
                                       xen_block_dataplane_event, dataplane,
-                                      &local_err);
-    if (local_err) {
-        error_propagate(errp, local_err);
+                                      errp);
+    if (*errp) {
         goto stop;
     }
 
hw/block/xen-block.c +52 -67

296 lines not on this page · raw message

hw/xen/xen-backend.c +3 -4
index da065f81b7..1cc0694053 100644
@@ -98,9 +98,9 @@ static void xen_backend_list_remove(XenBackendInstance *backend)
 void xen_backend_device_create(XenBus *xenbus, const char *type,
                                const char *name, QDict *opts, Error **errp)
 {
+    ERRP_AUTO_PROPAGATE();
     const XenBackendImpl *impl = xen_backend_table_lookup(type);
     XenBackendInstance *backend;
-    Error *local_error = NULL;
 
     if (!impl) {
         return;
@@ -110,9 +110,8 @@ void xen_backend_device_create(XenBus *xenbus, const char *type,
     backend->xenbus = xenbus;
     backend->name = g_strdup(name);
 
-    impl->create(backend, opts, &local_error);
-    if (local_error) {
-        error_propagate(errp, local_error);
+    impl->create(backend, opts, errp);
+    if (*errp) {
         g_free(backend->name);
         g_free(backend);
         return;
hw/xen/xen-bus.c +43 -49

234 lines not on this page · raw message

hw/xen/xen-host-pci-device.c +13 -14
index 1b44dcafaf..02379c341c 100644
@@ -333,8 +333,8 @@ void xen_host_pci_device_get(XenHostPCIDevice *d, uint16_t domain,
                              uint8_t bus, uint8_t dev, uint8_t func,
                              Error **errp)
 {
+    ERRP_AUTO_PROPAGATE();
     unsigned int v;
-    Error *err = NULL;
 
     d->config_fd = -1;
     d->domain = domain;
@@ -342,36 +342,36 @@ void xen_host_pci_device_get(XenHostPCIDevice *d, uint16_t domain,
     d->dev = dev;
     d->func = func;
 
-    xen_host_pci_config_open(d, &err);
-    if (err) {
+    xen_host_pci_config_open(d, errp);
+    if (*errp) {
         goto error;
     }
 
-    xen_host_pci_get_resource(d, &err);
-    if (err) {
+    xen_host_pci_get_resource(d, errp);
+    if (*errp) {
         goto error;
     }
 
-    xen_host_pci_get_hex_value(d, "vendor", &v, &err);
-    if (err) {
+    xen_host_pci_get_hex_value(d, "vendor", &v, errp);
+    if (*errp) {
         goto error;
     }
     d->vendor_id = v;
 
-    xen_host_pci_get_hex_value(d, "device", &v, &err);
-    if (err) {
+    xen_host_pci_get_hex_value(d, "device", &v, errp);
+    if (*errp) {
         goto error;
     }
     d->device_id = v;
 
-    xen_host_pci_get_dec_value(d, "irq", &v, &err);
-    if (err) {
+    xen_host_pci_get_dec_value(d, "irq", &v, errp);
+    if (*errp) {
         goto error;
     }
     d->irq = v;
 
-    xen_host_pci_get_hex_value(d, "class", &v, &err);
-    if (err) {
+    xen_host_pci_get_hex_value(d, "class", &v, errp);
+    if (*errp) {
         goto error;
     }
     d->class_code = v;
@@ -381,7 +381,6 @@ void xen_host_pci_device_get(XenHostPCIDevice *d, uint16_t domain,
     return;
 
 error:
-    error_propagate(errp, err);
 
     if (d->config_fd >= 0) {
         close(d->config_fd);
hw/xen/xen_pt.c +11 -14
index 8fbaf2eae9..4bf9353bcb 100644
@@ -765,12 +765,12 @@ static void xen_pt_destroy(PCIDevice *d) {
 
 static void xen_pt_realize(PCIDevice *d, Error **errp)
 {
+    ERRP_AUTO_PROPAGATE();
     XenPCIPassthroughState *s = XEN_PT_DEVICE(d);
     int i, rc = 0;
     uint8_t machine_irq = 0, scratch;
     uint16_t cmd = 0;
     int pirq = XEN_PT_UNASSIGNED_PIRQ;
-    Error *err = NULL;
 
     /* register real device */
     XEN_PT_LOG(d, "Assigning real physical device %02x:%02x.%d"
@@ -781,10 +781,9 @@ static void xen_pt_realize(PCIDevice *d, Error **errp)
     xen_host_pci_device_get(&s->real_device,
                             s->hostaddr.domain, s->hostaddr.bus,
                             s->hostaddr.slot, s->hostaddr.function,
-                            &err);
-    if (err) {
-        error_append_hint(&err, "Failed to \"open\" the real pci device");
-        error_propagate(errp, err);
+                            errp);
+    if (*errp) {
+        error_append_hint(errp, "Failed to \"open\" the real pci device");
         return;
     }
 
@@ -811,11 +810,10 @@ static void xen_pt_realize(PCIDevice *d, Error **errp)
             return;
         }
 
-        xen_pt_setup_vga(s, &s->real_device, &err);
-        if (err) {
-            error_append_hint(&err, "Setup VGA BIOS of passthrough"
-                    " GFX failed");
-            error_propagate(errp, err);
+        xen_pt_setup_vga(s, &s->real_device, errp);
+        if (*errp) {
+            error_append_hint(errp, "Setup VGA BIOS of passthrough"
+                              " GFX failed");
             xen_host_pci_device_put(&s->real_device);
             return;
         }
@@ -828,10 +826,9 @@ static void xen_pt_realize(PCIDevice *d, Error **errp)
     xen_pt_register_regions(s, &cmd);
 
     /* reinitialize each config register to be emulated */
-    xen_pt_config_init(s, &err);
-    if (err) {
-        error_append_hint(&err, "PCI Config space initialisation failed");
-        error_propagate(errp, err);
+    xen_pt_config_init(s, errp);
+    if (*errp) {
+        error_append_hint(errp, "PCI Config space initialisation failed");
         rc = -1;
         goto err_out;
     }
hw/xen/xen_pt_config_init.c +10 -10
index 31ec5add1d..af3fbd1bfb 100644
@@ -2008,8 +2008,8 @@ static void xen_pt_config_reg_init(XenPCIPassthroughState *s,
 
 void xen_pt_config_init(XenPCIPassthroughState *s, Error **errp)
 {
+    ERRP_AUTO_PROPAGATE();
     int i, rc;
-    Error *err = NULL;
 
     QLIST_INIT(&s->reg_grps);
 
@@ -2052,10 +2052,9 @@ void xen_pt_config_init(XenPCIPassthroughState *s, Error **errp)
                                                   reg_grp_offset,
                                                   &reg_grp_entry->size);
             if (rc < 0) {
-                error_setg(&err, "Failed to initialize %d/%zu, type = 0x%x,"
+                error_setg(errp, "Failed to initialize %d/%zu, type = 0x%x,"
                            " rc: %d", i, ARRAY_SIZE(xen_pt_emu_reg_grps),
                            xen_pt_emu_reg_grps[i].grp_type, rc);
-                error_propagate(errp, err);
                 xen_pt_config_delete(s);
                 return;
             }
@@ -2068,13 +2067,14 @@ void xen_pt_config_init(XenPCIPassthroughState *s, Error **errp)
 
                 /* initialize capability register */
                 for (j = 0; regs->size != 0; j++, regs++) {
-                    xen_pt_config_reg_init(s, reg_grp_entry, regs, &err);
-                    if (err) {
-                        error_append_hint(&err, "Failed to init register %d"
-                                " offsets 0x%x in grp_type = 0x%x (%d/%zu)", j,
-                                regs->offset, xen_pt_emu_reg_grps[i].grp_type,
-                                i, ARRAY_SIZE(xen_pt_emu_reg_grps));
-                        error_propagate(errp, err);
+                    xen_pt_config_reg_init(s, reg_grp_entry, regs, errp);
+                    if (*errp) {
+                        error_append_hint(errp, "Failed to init register %d"
+                                          " offsets 0x%x in grp_type = 0x%x (%d/%zu)",
+                                          j,
+                                          regs->offset,
+                                          xen_pt_emu_reg_grps[i].grp_type,
+                                          i, ARRAY_SIZE(xen_pt_emu_reg_grps));
                         xen_pt_config_delete(s);
                         return;
                     }
Signature · 7 lines
2.21.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Acked-by on v5 31/126
#74 lore raw

Re: [RFC v5 031/126] xen: introduce ERRP_AUTO_PROPAGATE

Quoted 12 lines · Vladimir Sementsov-Ogievskiy
hw/block/xen-block.c +2 -2
@@ -915,15 +903,15 @@ static void xen_block_device_create(XenBackendInstance *backend,
         goto fail;
     }
 
-    drive = xen_block_drive_create(vdev, device_type, opts, &local_err);
+    drive = xen_block_drive_create(vdev, device_type, opts, errp);
     if (!drive) {
-        error_propagate_prepend(errp, local_err, "failed to create drive: ");
+        error_prepend(errp, "failed to create drive: ");

hw/block/xen-block.c static void xen_block_device_create(XenBackendInstance *backend, · line 915

Quoted 10 lines
hw/block/xen-block.c +3 -3
         goto fail;
     }
 
-    iothread = xen_block_iothread_create(vdev, &local_err);
-    if (local_err) {
-        error_propagate_prepend(errp, local_err,
+    iothread = xen_block_iothread_create(vdev, errp);
+    if (*errp) {
+        error_prepend(errp,
                                 "failed to create iothread: ");

These two line could be joined now.

hw/block/xen-block.c static void xen_block_device_create(XenBackendInstance *backend, · line 917

Quoted 2 lines
hw/block/xen-block.c +0 -0
         goto fail;
     }

And there are more indentation issues like that in the patch. It would be nice to fix, but otherwise the patch looks fine:

Thanks,

Signature · 6 lines
Anthony PERARD

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#75 lore raw

RFC v5 32/126 Hosts: introduce ERRP_AUTO_PROPAGATE

In reply to Vladimir Sementsov-Ogievskiy

If we want to add some info to errp (by error_prepend() or error_append_hint()), we must use the ERRP_AUTO_PROPAGATE macro. Otherwise, this info will not be added when errp == &fatal_err (the program will exit prior to the error_append_hint() or error_prepend() call). Fix such cases.

If we want to check error after errp-function call, we need to introduce local_err and than propagate it to errp. Instead, use ERRP_AUTO_PROPAGATE macro, benefits are:
1. No need of explicit error_propagate call
2. No need of explicit local_err variable: use errp directly
3. ERRP_AUTO_PROPAGATE leaves errp as is if it's not NULL or &error_fatel, this means that we don't break error_abort (we'll abort on error_set, not on error_propagate)

This commit (together with its neighbors) was generated by

for f in $(git grep -l errp \*.[ch]); do \

    spatch --sp-file scripts/coccinelle/auto-propagated-errp.cocci \
    --macro-file scripts/cocci-macro-file.h --in-place --no-show-diff $f; \

done;

then fix a bit of compilation problems: coccinelle for some reason leaves several

f() {
    ...
    goto out;
    ...
    out:
}

patterns, with "out:" at function end.

then
./python/commit-per-subsystem.py MAINTAINERS "$(< auto-msg)"

(auto-msg was a file with this commit message)

Still, for backporting it may be more comfortable to use only the first command and then do one huge commit.

---
 qga/commands-win32.c | 139 +++++++++++++++++++------------------------
 util/oslib-posix.c   |   6 +-
 2 files changed, 64 insertions(+), 81 deletions(-)
qga/commands-win32.c +61 -78
index 9789465b4a..70e4311a98 100644
@@ -240,15 +240,15 @@ void qmp_guest_file_close(int64_t handle, Error **errp)
 
 static void acquire_privilege(const char *name, Error **errp)
 {
+    ERRP_AUTO_PROPAGATE();
     HANDLE token = NULL;
     TOKEN_PRIVILEGES priv;
-    Error *local_err = NULL;
 
     if (OpenProcessToken(GetCurrentProcess(),
         TOKEN_ADJUST_PRIVILEGES|TOKEN_QUERY, &token))
     {
         if (!LookupPrivilegeValue(NULL, name, &priv.Privileges[0].Luid)) {
-            error_setg(&local_err, QERR_QGA_COMMAND_FAILED,
+            error_setg(errp, QERR_QGA_COMMAND_FAILED,
                        "no luid for requested privilege");
             goto out;
         }
@@ -257,13 +257,13 @@ static void acquire_privilege(const char *name, Error **errp)
         priv.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
 
         if (!AdjustTokenPrivileges(token, FALSE, &priv, 0, NULL, 0)) {
-            error_setg(&local_err, QERR_QGA_COMMAND_FAILED,
+            error_setg(errp, QERR_QGA_COMMAND_FAILED,
                        "unable to acquire requested privilege");
             goto out;
         }
 
     } else {
-        error_setg(&local_err, QERR_QGA_COMMAND_FAILED,
+        error_setg(errp, QERR_QGA_COMMAND_FAILED,
                    "failed to open privilege token");
     }
 
@@ -271,25 +271,23 @@ out:
     if (token) {
         CloseHandle(token);
     }
-    error_propagate(errp, local_err);
 }
 
 static void execute_async(DWORD WINAPI (*func)(LPVOID), LPVOID opaque,
                           Error **errp)
 {
-    Error *local_err = NULL;
+    ERRP_AUTO_PROPAGATE();
 
     HANDLE thread = CreateThread(NULL, 0, func, opaque, 0, NULL);
     if (!thread) {
-        error_setg(&local_err, QERR_QGA_COMMAND_FAILED,
+        error_setg(errp, QERR_QGA_COMMAND_FAILED,
                    "failed to dispatch asynchronous command");
-        error_propagate(errp, local_err);
     }
 }
 
 void qmp_guest_shutdown(bool has_mode, const char *mode, Error **errp)
 {
-    Error *local_err = NULL;
+    ERRP_AUTO_PROPAGATE();
     UINT shutdown_flag = EWX_FORCE;
 
     slog("guest-shutdown called, mode: %s", mode);
@@ -308,9 +306,8 @@ void qmp_guest_shutdown(bool has_mode, const char *mode, Error **errp)
 
     /* Request a shutdown privilege, but try to shut down the system
        anyway. */
-    acquire_privilege(SE_SHUTDOWN_NAME, &local_err);
-    if (local_err) {
-        error_propagate(errp, local_err);
+    acquire_privilege(SE_SHUTDOWN_NAME, errp);
+    if (*errp) {
         return;
     }
 
@@ -409,6 +406,7 @@ GuestFileSeek *qmp_guest_file_seek(int64_t handle, int64_t offset,
                                    GuestFileWhence *whence_code,
                                    Error **errp)
 {
+    ERRP_AUTO_PROPAGATE();
     GuestFileHandle *gfh;
     GuestFileSeek *seek_data;
     HANDLE fh;
@@ -416,7 +414,6 @@ GuestFileSeek *qmp_guest_file_seek(int64_t handle, int64_t offset,
     off_pos.QuadPart = offset;
     BOOL res;
     int whence;
-    Error *err = NULL;
 
     gfh = guest_file_handle_find(handle, errp);
     if (!gfh) {
@@ -424,9 +421,8 @@ GuestFileSeek *qmp_guest_file_seek(int64_t handle, int64_t offset,
     }
 
     /* We stupidly exposed 'whence':'int' in our qapi */
-    whence = ga_parse_whence(whence_code, &err);
-    if (err) {
-        error_propagate(errp, err);
+    whence = ga_parse_whence(whence_code, errp);
+    if (*errp) {
         return NULL;
     }
 
@@ -792,10 +788,10 @@ out_free:
 static void get_single_disk_info(int disk_number,
                                  GuestDiskAddress *disk, Error **errp)
 {
+    ERRP_AUTO_PROPAGATE();
     SCSI_ADDRESS addr, *scsi_ad;
     DWORD len;
     HANDLE disk_h;
-    Error *local_err = NULL;
 
     scsi_ad = &addr;
 
@@ -807,9 +803,8 @@ static void get_single_disk_info(int disk_number,
         return;
     }
 
-    get_disk_properties(disk_h, disk, &local_err);
-    if (local_err) {
-        error_propagate(errp, local_err);
+    get_disk_properties(disk_h, disk, errp);
+    if (*errp) {
         goto err_close;
     }
 
@@ -819,9 +814,8 @@ static void get_single_disk_info(int disk_number,
      * if that doesn't hold since that suggests some other unexpected
      * breakage
      */
-    disk->pci_controller = get_pci_info(disk_number, &local_err);
-    if (local_err) {
-        error_propagate(errp, local_err);
+    disk->pci_controller = get_pci_info(disk_number, errp);
+    if (*errp) {
         goto err_close;
     }
     if (disk->bus_type == GUEST_DISK_BUS_TYPE_SCSI
@@ -854,7 +848,7 @@ err_close:
  * volume is returned for the spanned disk group (LVM) */
 static GuestDiskAddressList *build_guest_disk_info(char *guid, Error **errp)
 {
-    Error *local_err = NULL;
+    ERRP_AUTO_PROPAGATE();
     GuestDiskAddressList *list = NULL, *cur_item = NULL;
     GuestDiskAddress *disk = NULL;
     int i;
@@ -900,11 +894,11 @@ static GuestDiskAddressList *build_guest_disk_info(char *guid, Error **errp)
             disk = g_malloc0(sizeof(GuestDiskAddress));
             disk->has_dev = true;
             disk->dev = g_strdup(name);
-            get_single_disk_info(0xffffffff, disk, &local_err);
-            if (local_err) {
+            get_single_disk_info(0xffffffff, disk, errp);
+            if (*errp) {
                 g_debug("failed to get disk info, ignoring error: %s",
-                    error_get_pretty(local_err));
-                error_free(local_err);
+                    error_get_pretty(*errp));
+                error_free_errp(errp);
                 goto out;
             }
             list = g_malloc0(sizeof(*list));
@@ -936,9 +930,8 @@ static GuestDiskAddressList *build_guest_disk_info(char *guid, Error **errp)
         disk->dev = g_strdup_printf("\\\\.\\PhysicalDrive%lu",
                                     extents->Extents[i].DiskNumber);
 
-        get_single_disk_info(extents->Extents[i].DiskNumber, disk, &local_err);
-        if (local_err) {
-            error_propagate(errp, local_err);
+        get_single_disk_info(extents->Extents[i].DiskNumber, disk, errp);
+        if (*errp) {
             goto out;
         }
         cur_item = g_malloc0(sizeof(*list));
@@ -1090,8 +1083,8 @@ int64_t qmp_guest_fsfreeze_freeze_list(bool has_mountpoints,
                                        strList *mountpoints,
                                        Error **errp)
 {
+    ERRP_AUTO_PROPAGATE();
     int i;
-    Error *local_err = NULL;
 
     if (!vss_initialized()) {
         error_setg(errp, QERR_UNSUPPORTED);
@@ -1103,20 +1096,19 @@ int64_t qmp_guest_fsfreeze_freeze_list(bool has_mountpoints,
     /* cannot risk guest agent blocking itself on a write in this state */
     ga_set_frozen(ga_state);
 
-    qga_vss_fsfreeze(&i, true, mountpoints, &local_err);
-    if (local_err) {
-        error_propagate(errp, local_err);
+    qga_vss_fsfreeze(&i, true, mountpoints, errp);
+    if (*errp) {
         goto error;
     }
 
     return i;
 
 error:
-    local_err = NULL;
-    qmp_guest_fsfreeze_thaw(&local_err);
-    if (local_err) {
-        g_debug("cleanup thaw: %s", error_get_pretty(local_err));
-        error_free(local_err);
+    *errp = NULL;
+    qmp_guest_fsfreeze_thaw(errp);
+    if (*errp) {
+        g_debug("cleanup thaw: %s", error_get_pretty(*errp));
+        error_free_errp(errp);
     }
     return 0;
 }
@@ -1281,36 +1273,33 @@ typedef enum {
 
 static void check_suspend_mode(GuestSuspendMode mode, Error **errp)
 {
+    ERRP_AUTO_PROPAGATE();
     SYSTEM_POWER_CAPABILITIES sys_pwr_caps;
-    Error *local_err = NULL;
 
     ZeroMemory(&sys_pwr_caps, sizeof(sys_pwr_caps));
     if (!GetPwrCapabilities(&sys_pwr_caps)) {
-        error_setg(&local_err, QERR_QGA_COMMAND_FAILED,
+        error_setg(errp, QERR_QGA_COMMAND_FAILED,
                    "failed to determine guest suspend capabilities");
-        goto out;
+        return;
     }
 
     switch (mode) {
     case GUEST_SUSPEND_MODE_DISK:
         if (!sys_pwr_caps.SystemS4) {
-            error_setg(&local_err, QERR_QGA_COMMAND_FAILED,
+            error_setg(errp, QERR_QGA_COMMAND_FAILED,
                        "suspend-to-disk not supported by OS");
         }
         break;
     case GUEST_SUSPEND_MODE_RAM:
         if (!sys_pwr_caps.SystemS3) {
-            error_setg(&local_err, QERR_QGA_COMMAND_FAILED,
+            error_setg(errp, QERR_QGA_COMMAND_FAILED,
                        "suspend-to-ram not supported by OS");
         }
         break;
     default:
-        error_setg(&local_err, QERR_INVALID_PARAMETER_VALUE, "mode",
+        error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "mode",
                    "GuestSuspendMode");
     }
-
-out:
-    error_propagate(errp, local_err);
 }
 
 static DWORD WINAPI do_suspend(LPVOID opaque)
@@ -1328,32 +1317,30 @@ static DWORD WINAPI do_suspend(LPVOID opaque)
 
 void qmp_guest_suspend_disk(Error **errp)
 {
-    Error *local_err = NULL;
+    ERRP_AUTO_PROPAGATE();
     GuestSuspendMode *mode = g_new(GuestSuspendMode, 1);
 
     *mode = GUEST_SUSPEND_MODE_DISK;
-    check_suspend_mode(*mode, &local_err);
-    acquire_privilege(SE_SHUTDOWN_NAME, &local_err);
-    execute_async(do_suspend, mode, &local_err);
+    check_suspend_mode(*mode, errp);
+    acquire_privilege(SE_SHUTDOWN_NAME, errp);
+    execute_async(do_suspend, mode, errp);
 
-    if (local_err) {
-        error_propagate(errp, local_err);
+    if (*errp) {
         g_free(mode);
     }
 }
 
 void qmp_guest_suspend_ram(Error **errp)
 {
-    Error *local_err = NULL;
+    ERRP_AUTO_PROPAGATE();
     GuestSuspendMode *mode = g_new(GuestSuspendMode, 1);
 
     *mode = GUEST_SUSPEND_MODE_RAM;
-    check_suspend_mode(*mode, &local_err);
-    acquire_privilege(SE_SHUTDOWN_NAME, &local_err);
-    execute_async(do_suspend, mode, &local_err);
+    check_suspend_mode(*mode, errp);
+    acquire_privilege(SE_SHUTDOWN_NAME, errp);
+    execute_async(do_suspend, mode, errp);
 
-    if (local_err) {
-        error_propagate(errp, local_err);
+    if (*errp) {
         g_free(mode);
     }
 }
@@ -1616,7 +1603,7 @@ int64_t qmp_guest_get_time(Error **errp)
 
 void qmp_guest_set_time(bool has_time, int64_t time_ns, Error **errp)
 {
-    Error *local_err = NULL;
+    ERRP_AUTO_PROPAGATE();
     SYSTEMTIME ts;
     FILETIME tf;
     LONGLONG time;
@@ -1681,9 +1668,8 @@ void qmp_guest_set_time(bool has_time, int64_t time_ns, Error **errp)
         return;
     }
 
-    acquire_privilege(SE_SYSTEMTIME_NAME, &local_err);
-    if (local_err) {
-        error_propagate(errp, local_err);
+    acquire_privilege(SE_SYSTEMTIME_NAME, errp);
+    if (*errp) {
         return;
     }
 
@@ -1695,10 +1681,10 @@ void qmp_guest_set_time(bool has_time, int64_t time_ns, Error **errp)
 
 GuestLogicalProcessorList *qmp_guest_get_vcpus(Error **errp)
 {
+    ERRP_AUTO_PROPAGATE();
     PSYSTEM_LOGICAL_PROCESSOR_INFORMATION pslpi, ptr;
     DWORD length;
     GuestLogicalProcessorList *head, **link;
-    Error *local_err = NULL;
     int64_t current;
 
     ptr = pslpi = NULL;
@@ -1712,16 +1698,16 @@ GuestLogicalProcessorList *qmp_guest_get_vcpus(Error **errp)
         (length > sizeof(SYSTEM_LOGICAL_PROCESSOR_INFORMATION))) {
         ptr = pslpi = g_malloc0(length);
         if (GetLogicalProcessorInformation(pslpi, &length) == FALSE) {
-            error_setg(&local_err, "Failed to get processor information: %d",
+            error_setg(errp, "Failed to get processor information: %d",
                        (int)GetLastError());
         }
     } else {
-        error_setg(&local_err,
+        error_setg(errp,
                    "Failed to get processor information buffer length: %d",
                    (int)GetLastError());
     }
 
-    while ((local_err == NULL) && (length > 0)) {
+    while ((*errp == NULL) && (length > 0)) {
         if (pslpi->Relationship == RelationProcessorCore) {
             ULONG_PTR cpu_bits = pslpi->ProcessorMask;
 
@@ -1750,16 +1736,15 @@ GuestLogicalProcessorList *qmp_guest_get_vcpus(Error **errp)
 
     g_free(ptr);
 
-    if (local_err == NULL) {
+    if (*errp == NULL) {
         if (head != NULL) {
             return head;
         }
         /* there's no guest with zero VCPUs */
-        error_setg(&local_err, "Guest reported zero VCPUs");
+        error_setg(errp, "Guest reported zero VCPUs");
     }
 
     qapi_free_GuestLogicalProcessorList(head);
-    error_propagate(errp, local_err);
     return NULL;
 }
 
@@ -2186,22 +2171,20 @@ static char *ga_get_current_arch(void)
 
 GuestOSInfo *qmp_guest_get_osinfo(Error **errp)
 {
-    Error *local_err = NULL;
+    ERRP_AUTO_PROPAGATE();
     OSVERSIONINFOEXW os_version = {0};
     bool server;
     char *product_name;
     GuestOSInfo *info;
 
-    ga_get_win_version(&os_version, &local_err);
-    if (local_err) {
-        error_propagate(errp, local_err);
+    ga_get_win_version(&os_version, errp);
+    if (*errp) {
         return NULL;
     }
 
     server = os_version.wProductType != VER_NT_WORKSTATION;
-    product_name = ga_get_win_product_name(&local_err);
+    product_name = ga_get_win_product_name(errp);
     if (product_name == NULL) {
-        error_propagate(errp, local_err);
         return NULL;
     }
 
util/oslib-posix.c +3 -3
index f8693384fc..ad4cbe9c16 100644
@@ -542,6 +542,7 @@ char *qemu_get_pid_name(pid_t pid)
 
 pid_t qemu_fork(Error **errp)
 {
+    ERRP_AUTO_PROPAGATE();
     sigset_t oldmask, newmask;
     struct sigaction sig_action;
     int saved_errno;
@@ -600,10 +601,9 @@ pid_t qemu_fork(Error **errp)
          * propagate that to children */
         sigemptyset(&newmask);
         if (pthread_sigmask(SIG_SETMASK, &newmask, NULL) != 0) {
-            Error *local_err = NULL;
-            error_setg_errno(&local_err, errno,
+            error_setg_errno(errp, errno,
                              "cannot unblock signals");
-            error_report_err(local_err);
+            error_report_errp(errp);
             _exit(1);
         }
     }
Signature · 1 line
2.21.0
#76 lore raw

RFC v5 33/126 ARM Machines: introduce ERRP_AUTO_PROPAGATE

In reply to Vladimir Sementsov-Ogievskiy

If we want to add some info to errp (by error_prepend() or error_append_hint()), we must use the ERRP_AUTO_PROPAGATE macro. Otherwise, this info will not be added when errp == &fatal_err (the program will exit prior to the error_append_hint() or error_prepend() call). Fix such cases.

If we want to check error after errp-function call, we need to introduce local_err and than propagate it to errp. Instead, use ERRP_AUTO_PROPAGATE macro, benefits are:
1. No need of explicit error_propagate call
2. No need of explicit local_err variable: use errp directly
3. ERRP_AUTO_PROPAGATE leaves errp as is if it's not NULL or &error_fatel, this means that we don't break error_abort (we'll abort on error_set, not on error_propagate)

This commit (together with its neighbors) was generated by

for f in $(git grep -l errp \*.[ch]); do \

    spatch --sp-file scripts/coccinelle/auto-propagated-errp.cocci \
    --macro-file scripts/cocci-macro-file.h --in-place --no-show-diff $f; \

done;

then fix a bit of compilation problems: coccinelle for some reason leaves several

f() {
    ...
    goto out;
    ...
    out:
}

patterns, with "out:" at function end.

then
./python/commit-per-subsystem.py MAINTAINERS "$(< auto-msg)"

(auto-msg was a file with this commit message)

Still, for backporting it may be more comfortable to use only the first command and then do one huge commit.

---
 hw/arm/allwinner-a10.c          | 27 +++++------
 hw/arm/aspeed_soc.c             |  1 +
 hw/arm/bcm2835_peripherals.c    | 85 ++++++++++++++------------------
 hw/arm/bcm2836.c                | 41 +++++++---------
 hw/arm/digic.c                  | 22 ++++-----
 hw/arm/fsl-imx25.c              | 62 ++++++++++--------------
 hw/arm/fsl-imx31.c              | 57 +++++++++-------------
 hw/arm/fsl-imx6.c               | 81 +++++++++++++------------------
 hw/arm/integratorcp.c           |  7 ++-
 hw/arm/msf2-soc.c               | 22 ++++-----
 hw/arm/nrf51_soc.c              | 47 ++++++++----------
 hw/arm/stm32f205_soc.c          | 39 ++++++---------
 hw/arm/virt.c                   |  2 +
 hw/arm/xlnx-versal-virt.c       |  7 ++-
 hw/arm/xlnx-zynqmp.c            | 86 ++++++++++++++-------------------
 hw/cpu/realview_mpcore.c        | 12 ++---
 hw/display/bcm2835_fb.c         |  6 +--
 hw/dma/bcm2835_dma.c            |  6 +--
 hw/dma/xilinx_axidma.c          | 22 ++++-----
 hw/gpio/aspeed_gpio.c           |  7 ++-
 hw/gpio/bcm2835_gpio.c          | 10 ++--
 hw/intc/arm_gic.c               |  7 ++-
 hw/intc/arm_gic_kvm.c           | 12 ++---
 hw/intc/arm_gicv3.c             | 12 ++---
 hw/intc/arm_gicv3_its_kvm.c     |  7 ++-
 hw/intc/arm_gicv3_kvm.c         | 17 +++----
 hw/intc/armv7m_nvic.c           | 12 ++---
 hw/intc/realview_gic.c          |  7 ++-
 hw/microblaze/xlnx-zynqmp-pmu.c | 12 ++---
 hw/misc/bcm2835_mbox.c          |  6 +--
 hw/misc/bcm2835_property.c      | 10 ++--
 hw/misc/msf2-sysreg.c           |  1 +
 hw/net/xilinx_axienet.c         | 22 ++++-----
 hw/nvram/nrf51_nvm.c            |  7 ++-
 hw/timer/aspeed_timer.c         |  6 +--
 hw/watchdog/wdt_aspeed.c        |  5 +-
 36 files changed, 332 insertions(+), 460 deletions(-)
hw/arm/allwinner-a10.c +11 -16
index 118032c8c7..d33af2939c 100644
@@ -47,23 +47,21 @@ static void aw_a10_init(Object *obj)
 
 static void aw_a10_realize(DeviceState *dev, Error **errp)
 {
+    ERRP_AUTO_PROPAGATE();
     AwA10State *s = AW_A10(dev);
     SysBusDevice *sysbusdev;
     uint8_t i;
     qemu_irq fiq, irq;
-    Error *err = NULL;
 
-    object_property_set_bool(OBJECT(&s->cpu), true, "realized", &err);
-    if (err != NULL) {
-        error_propagate(errp, err);
+    object_property_set_bool(OBJECT(&s->cpu), true, "realized", errp);
+    if (*errp) {
         return;
     }
     irq = qdev_get_gpio_in(DEVICE(&s->cpu), ARM_CPU_IRQ);
     fiq = qdev_get_gpio_in(DEVICE(&s->cpu), ARM_CPU_FIQ);
 
-    object_property_set_bool(OBJECT(&s->intc), true, "realized", &err);
-    if (err != NULL) {
-        error_propagate(errp, err);
+    object_property_set_bool(OBJECT(&s->intc), true, "realized", errp);
+    if (*errp) {
         return;
     }
     sysbusdev = SYS_BUS_DEVICE(&s->intc);
@@ -74,9 +72,8 @@ static void aw_a10_realize(DeviceState *dev, Error **errp)
         s->irq[i] = qdev_get_gpio_in(DEVICE(&s->intc), i);
     }
 
-    object_property_set_bool(OBJECT(&s->timer), true, "realized", &err);
-    if (err != NULL) {
-        error_propagate(errp, err);
+    object_property_set_bool(OBJECT(&s->timer), true, "realized", errp);
+    if (*errp) {
         return;
     }
     sysbusdev = SYS_BUS_DEVICE(&s->timer);
@@ -98,18 +95,16 @@ static void aw_a10_realize(DeviceState *dev, Error **errp)
         qemu_check_nic_model(&nd_table[0], TYPE_AW_EMAC);
         qdev_set_nic_properties(DEVICE(&s->emac), &nd_table[0]);
     }
-    object_property_set_bool(OBJECT(&s->emac), true, "realized", &err);
-    if (err != NULL) {
-        error_propagate(errp, err);
+    object_property_set_bool(OBJECT(&s->emac), true, "realized", errp);
+    if (*errp) {
         return;
     }
     sysbusdev = SYS_BUS_DEVICE(&s->emac);
     sysbus_mmio_map(sysbusdev, 0, AW_A10_EMAC_BASE);
     sysbus_connect_irq(sysbusdev, 0, s->irq[55]);
 
-    object_property_set_bool(OBJECT(&s->sata), true, "realized", &err);
-    if (err) {
-        error_propagate(errp, err);
+    object_property_set_bool(OBJECT(&s->sata), true, "realized", errp);
+    if (*errp) {
         return;
     }
     sysbus_mmio_map(SYS_BUS_DEVICE(&s->sata), 0, AW_A10_SATA_BASE);
hw/arm/aspeed_soc.c +1 -0
index cf1d0cf921..929ed713ac 100644
@@ -234,6 +234,7 @@ static void aspeed_soc_init(Object *obj)
 
 static void aspeed_soc_realize(DeviceState *dev, Error **errp)
 {
+    ERRP_AUTO_PROPAGATE();
     int i;
     AspeedSoCState *s = ASPEED_SOC(dev);
     AspeedSoCClass *sc = ASPEED_SOC_GET_CLASS(s);
hw/arm/bcm2835_peripherals.c +35 -50

183 lines not on this page · raw message

hw/arm/bcm2836.c +17 -24

87 lines not on this page · raw message

hw/arm/digic.c +9 -13
index 22434a65a2..25e872305d 100644
@@ -55,27 +55,24 @@ static void digic_init(Object *obj)
 
 static void digic_realize(DeviceState *dev, Error **errp)
 {
+    ERRP_AUTO_PROPAGATE();
     DigicState *s = DIGIC(dev);
-    Error *err = NULL;
     SysBusDevice *sbd;
     int i;
 
-    object_property_set_bool(OBJECT(&s->cpu), true, "reset-hivecs", &err);
-    if (err != NULL) {
-        error_propagate(errp, err);
+    object_property_set_bool(OBJECT(&s->cpu), true, "reset-hivecs", errp);
+    if (*errp) {
         return;
     }
 
-    object_property_set_bool(OBJECT(&s->cpu), true, "realized", &err);
-    if (err != NULL) {
-        error_propagate(errp, err);
+    object_property_set_bool(OBJECT(&s->cpu), true, "realized", errp);
+    if (*errp) {
         return;
     }
 
     for (i = 0; i < DIGIC4_NB_TIMERS; i++) {
-        object_property_set_bool(OBJECT(&s->timer[i]), true, "realized", &err);
-        if (err != NULL) {
-            error_propagate(errp, err);
+        object_property_set_bool(OBJECT(&s->timer[i]), true, "realized", errp);
+        if (*errp) {
             return;
         }
 
@@ -84,9 +81,8 @@ static void digic_realize(DeviceState *dev, Error **errp)
     }
 
     qdev_prop_set_chr(DEVICE(&s->uart), "chardev", serial_hd(0));
-    object_property_set_bool(OBJECT(&s->uart), true, "realized", &err);
-    if (err != NULL) {
-        error_propagate(errp, err);
+    object_property_set_bool(OBJECT(&s->uart), true, "realized", errp);
+    if (*errp) {
         return;
     }
 
hw/arm/fsl-imx25.c +25 -37

133 lines not on this page · raw message

hw/arm/fsl-imx31.c +23 -34

123 lines not on this page · raw message

hw/arm/fsl-imx6.c +33 -48

179 lines not on this page · raw message

hw/arm/integratorcp.c +3 -4
index 524970840d..5049a78fb9 100644
@@ -284,14 +284,13 @@ static void integratorcm_init(Object *obj)
 
 static void integratorcm_realize(DeviceState *d, Error **errp)
 {
+    ERRP_AUTO_PROPAGATE();
     IntegratorCMState *s = INTEGRATOR_CM(d);
     SysBusDevice *dev = SYS_BUS_DEVICE(d);
-    Error *local_err = NULL;
 
     memory_region_init_ram(&s->flash, OBJECT(d), "integrator.flash", 0x100000,
-                           &local_err);
-    if (local_err) {
-        error_propagate(errp, local_err);
+                           errp);
+    if (*errp) {
         return;
     }
 
hw/arm/msf2-soc.c +9 -13
index 008fd9327a..82808c4b15 100644
@@ -85,10 +85,10 @@ static void m2sxxx_soc_initfn(Object *obj)
 
 static void m2sxxx_soc_realize(DeviceState *dev_soc, Error **errp)
 {
+    ERRP_AUTO_PROPAGATE();
     MSF2State *s = MSF2_SOC(dev_soc);
     DeviceState *dev, *armv7m;
     SysBusDevice *busdev;
-    Error *err = NULL;
     int i;
 
     MemoryRegion *system_memory = get_system_memory();
@@ -120,9 +120,8 @@ static void m2sxxx_soc_realize(DeviceState *dev_soc, Error **errp)
     qdev_prop_set_bit(armv7m, "enable-bitband", true);
     object_property_set_link(OBJECT(&s->armv7m), OBJECT(get_system_memory()),
                                      "memory", &error_abort);
-    object_property_set_bool(OBJECT(&s->armv7m), true, "realized", &err);
-    if (err != NULL) {
-        error_propagate(errp, err);
+    object_property_set_bool(OBJECT(&s->armv7m), true, "realized", errp);
+    if (*errp) {
         return;
     }
 
@@ -148,9 +147,8 @@ static void m2sxxx_soc_realize(DeviceState *dev_soc, Error **errp)
     dev = DEVICE(&s->timer);
     /* APB0 clock is the timer input clock */
     qdev_prop_set_uint32(dev, "clock-frequency", s->m3clk / s->apb0div);
-    object_property_set_bool(OBJECT(&s->timer), true, "realized", &err);
-    if (err != NULL) {
-        error_propagate(errp, err);
+    object_property_set_bool(OBJECT(&s->timer), true, "realized", errp);
+    if (*errp) {
         return;
     }
     busdev = SYS_BUS_DEVICE(dev);
@@ -163,9 +161,8 @@ static void m2sxxx_soc_realize(DeviceState *dev_soc, Error **errp)
     dev = DEVICE(&s->sysreg);
     qdev_prop_set_uint32(dev, "apb0divisor", s->apb0div);
     qdev_prop_set_uint32(dev, "apb1divisor", s->apb1div);
-    object_property_set_bool(OBJECT(&s->sysreg), true, "realized", &err);
-    if (err != NULL) {
-        error_propagate(errp, err);
+    object_property_set_bool(OBJECT(&s->sysreg), true, "realized", errp);
+    if (*errp) {
         return;
     }
     busdev = SYS_BUS_DEVICE(dev);
@@ -174,9 +171,8 @@ static void m2sxxx_soc_realize(DeviceState *dev_soc, Error **errp)
     for (i = 0; i < MSF2_NUM_SPIS; i++) {
         gchar *bus_name;
 
-        object_property_set_bool(OBJECT(&s->spi[i]), true, "realized", &err);
-        if (err != NULL) {
-            error_propagate(errp, err);
+        object_property_set_bool(OBJECT(&s->spi[i]), true, "realized", errp);
+        if (*errp) {
             return;
         }
 
hw/arm/nrf51_soc.c +19 -28

101 lines not on this page · raw message

hw/arm/stm32f205_soc.c +16 -23
index f5a5c2d80c..f475ed0661 100644
@@ -82,10 +82,10 @@ static void stm32f205_soc_initfn(Object *obj)
 
 static void stm32f205_soc_realize(DeviceState *dev_soc, Error **errp)
 {
+    ERRP_AUTO_PROPAGATE();
     STM32F205State *s = STM32F205_SOC(dev_soc);
     DeviceState *dev, *armv7m;
     SysBusDevice *busdev;
-    Error *err = NULL;
     int i;
 
     MemoryRegion *system_memory = get_system_memory();
@@ -114,17 +114,15 @@ static void stm32f205_soc_realize(DeviceState *dev_soc, Error **errp)
     qdev_prop_set_bit(armv7m, "enable-bitband", true);
     object_property_set_link(OBJECT(&s->armv7m), OBJECT(get_system_memory()),
                                      "memory", &error_abort);
-    object_property_set_bool(OBJECT(&s->armv7m), true, "realized", &err);
-    if (err != NULL) {
-        error_propagate(errp, err);
+    object_property_set_bool(OBJECT(&s->armv7m), true, "realized", errp);
+    if (*errp) {
         return;
     }
 
     /* System configuration controller */
     dev = DEVICE(&s->syscfg);
-    object_property_set_bool(OBJECT(&s->syscfg), true, "realized", &err);
-    if (err != NULL) {
-        error_propagate(errp, err);
+    object_property_set_bool(OBJECT(&s->syscfg), true, "realized", errp);
+    if (*errp) {
         return;
     }
     busdev = SYS_BUS_DEVICE(dev);
@@ -135,9 +133,8 @@ static void stm32f205_soc_realize(DeviceState *dev_soc, Error **errp)
     for (i = 0; i < STM_NUM_USARTS; i++) {
         dev = DEVICE(&(s->usart[i]));
         qdev_prop_set_chr(dev, "chardev", serial_hd(i));
-        object_property_set_bool(OBJECT(&s->usart[i]), true, "realized", &err);
-        if (err != NULL) {
-            error_propagate(errp, err);
+        object_property_set_bool(OBJECT(&s->usart[i]), true, "realized", errp);
+        if (*errp) {
             return;
         }
         busdev = SYS_BUS_DEVICE(dev);
@@ -149,9 +146,8 @@ static void stm32f205_soc_realize(DeviceState *dev_soc, Error **errp)
     for (i = 0; i < STM_NUM_TIMERS; i++) {
         dev = DEVICE(&(s->timer[i]));
         qdev_prop_set_uint64(dev, "clock-frequency", 1000000000);
-        object_property_set_bool(OBJECT(&s->timer[i]), true, "realized", &err);
-        if (err != NULL) {
-            error_propagate(errp, err);
+        object_property_set_bool(OBJECT(&s->timer[i]), true, "realized", errp);
+        if (*errp) {
             return;
         }
         busdev = SYS_BUS_DEVICE(dev);
@@ -161,10 +157,9 @@ static void stm32f205_soc_realize(DeviceState *dev_soc, Error **errp)
 
     /* ADC 1 to 3 */
     object_property_set_int(OBJECT(s->adc_irqs), STM_NUM_ADCS,
-                            "num-lines", &err);
-    object_property_set_bool(OBJECT(s->adc_irqs), true, "realized", &err);
-    if (err != NULL) {
-        error_propagate(errp, err);
+                            "num-lines", errp);
+    object_property_set_bool(OBJECT(s->adc_irqs), true, "realized", errp);
+    if (*errp) {
         return;
     }
     qdev_connect_gpio_out(DEVICE(s->adc_irqs), 0,
@@ -172,9 +167,8 @@ static void stm32f205_soc_realize(DeviceState *dev_soc, Error **errp)
 
     for (i = 0; i < STM_NUM_ADCS; i++) {
         dev = DEVICE(&(s->adc[i]));
-        object_property_set_bool(OBJECT(&s->adc[i]), true, "realized", &err);
-        if (err != NULL) {
-            error_propagate(errp, err);
+        object_property_set_bool(OBJECT(&s->adc[i]), true, "realized", errp);
+        if (*errp) {
             return;
         }
         busdev = SYS_BUS_DEVICE(dev);
@@ -186,9 +180,8 @@ static void stm32f205_soc_realize(DeviceState *dev_soc, Error **errp)
     /* SPI 1 and 2 */
     for (i = 0; i < STM_NUM_SPIS; i++) {
         dev = DEVICE(&(s->spi[i]));
-        object_property_set_bool(OBJECT(&s->spi[i]), true, "realized", &err);
-        if (err != NULL) {
-            error_propagate(errp, err);
+        object_property_set_bool(OBJECT(&s->spi[i]), true, "realized", errp);
+        if (*errp) {
             return;
         }
         busdev = SYS_BUS_DEVICE(dev);
hw/arm/virt.c +2 -0
index d74538b021..ce2e57fd59 100644
@@ -1793,6 +1793,7 @@ static char *virt_get_gic_version(Object *obj, Error **errp)
 
 static void virt_set_gic_version(Object *obj, const char *value, Error **errp)
 {
+    ERRP_AUTO_PROPAGATE();
     VirtMachineState *vms = VIRT_MACHINE(obj);
 
     if (!strcmp(value, "3")) {
@@ -1825,6 +1826,7 @@ static char *virt_get_iommu(Object *obj, Error **errp)
 
 static void virt_set_iommu(Object *obj, const char *value, Error **errp)
 {
+    ERRP_AUTO_PROPAGATE();
     VirtMachineState *vms = VIRT_MACHINE(obj);
 
     if (!strcmp(value, "smmuv3")) {
hw/arm/xlnx-versal-virt.c +3 -4
index 462493c467..7f30e56dc7 100644
@@ -232,13 +232,12 @@ static void fdt_add_gem_nodes(VersalVirt *s)
 
 static void fdt_nop_memory_nodes(void *fdt, Error **errp)
 {
-    Error *err = NULL;
+    ERRP_AUTO_PROPAGATE();
     char **node_path;
     int n = 0;
 
-    node_path = qemu_fdt_node_unit_path(fdt, "memory", &err);
-    if (err) {
-        error_propagate(errp, err);
+    node_path = qemu_fdt_node_unit_path(fdt, "memory", errp);
+    if (*errp) {
         return;
     }
     while (node_path[n]) {
hw/arm/xlnx-zynqmp.c +36 -50

196 lines not on this page · raw message

hw/cpu/realview_mpcore.c +5 -7
index ae2c9913f6..c48a0140c6 100644
@@ -60,19 +60,18 @@ static void mpcore_rirq_set_irq(void *opaque, int irq, int level)
 
 static void realview_mpcore_realize(DeviceState *dev, Error **errp)
 {
+    ERRP_AUTO_PROPAGATE();
     SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
     mpcore_rirq_state *s = REALVIEW_MPCORE_RIRQ(dev);
     DeviceState *priv = DEVICE(&s->priv);
     DeviceState *gic;
     SysBusDevice *gicbusdev;
-    Error *err = NULL;
     int n;
     int i;
 
     qdev_prop_set_uint32(priv, "num-cpu", s->num_cpu);
-    object_property_set_bool(OBJECT(&s->priv), true, "realized", &err);
-    if (err != NULL) {
-        error_propagate(errp, err);
+    object_property_set_bool(OBJECT(&s->priv), true, "realized", errp);
+    if (*errp) {
         return;
     }
     sysbus_pass_irq(sbd, SYS_BUS_DEVICE(&s->priv));
@@ -81,9 +80,8 @@ static void realview_mpcore_realize(DeviceState *dev, Error **errp)
     }
     /* ??? IRQ routing is hardcoded to "normal" mode.  */
     for (n = 0; n < 4; n++) {
-        object_property_set_bool(OBJECT(&s->gic[n]), true, "realized", &err);
-        if (err != NULL) {
-            error_propagate(errp, err);
+        object_property_set_bool(OBJECT(&s->gic[n]), true, "realized", errp);
+        if (*errp) {
             return;
         }
         gic = DEVICE(&s->gic[n]);
hw/display/bcm2835_fb.c +3 -3
index 8f856878cd..fa2bca37c4 100644
@@ -401,8 +401,8 @@ static void bcm2835_fb_reset(DeviceState *dev)
 
 static void bcm2835_fb_realize(DeviceState *dev, Error **errp)
 {
+    ERRP_AUTO_PROPAGATE();
     BCM2835FBState *s = BCM2835_FB(dev);
-    Error *err = NULL;
     Object *obj;
 
     if (s->vcram_base == 0) {
@@ -410,10 +410,10 @@ static void bcm2835_fb_realize(DeviceState *dev, Error **errp)
         return;
     }
 
-    obj = object_property_get_link(OBJECT(dev), "dma-mr", &err);
+    obj = object_property_get_link(OBJECT(dev), "dma-mr", errp);
     if (obj == NULL) {
         error_setg(errp, "%s: required dma-mr link not found: %s",
-                   __func__, error_get_pretty(err));
+                   __func__, error_get_pretty(*errp));
         return;
     }
 
hw/dma/bcm2835_dma.c +3 -3
index 192bd377a0..a455f4dc57 100644
@@ -371,14 +371,14 @@ static void bcm2835_dma_reset(DeviceState *dev)
 
 static void bcm2835_dma_realize(DeviceState *dev, Error **errp)
 {
+    ERRP_AUTO_PROPAGATE();
     BCM2835DMAState *s = BCM2835_DMA(dev);
-    Error *err = NULL;
     Object *obj;
 
-    obj = object_property_get_link(OBJECT(dev), "dma-mr", &err);
+    obj = object_property_get_link(OBJECT(dev), "dma-mr", errp);
     if (obj == NULL) {
         error_setg(errp, "%s: required dma-mr link not found: %s",
-                   __func__, error_get_pretty(err));
+                   __func__, error_get_pretty(*errp));
         return;
     }
 
hw/dma/xilinx_axidma.c +9 -13
index a254275b64..872ef84635 100644
@@ -520,29 +520,29 @@ static const MemoryRegionOps axidma_ops = {
 
 static void xilinx_axidma_realize(DeviceState *dev, Error **errp)
 {
+    ERRP_AUTO_PROPAGATE();
     XilinxAXIDMA *s = XILINX_AXI_DMA(dev);
     XilinxAXIDMAStreamSlave *ds = XILINX_AXI_DMA_DATA_STREAM(&s->rx_data_dev);
     XilinxAXIDMAStreamSlave *cs = XILINX_AXI_DMA_CONTROL_STREAM(
                                                             &s->rx_control_dev);
-    Error *local_err = NULL;
 
     object_property_add_link(OBJECT(ds), "dma", TYPE_XILINX_AXI_DMA,
                              (Object **)&ds->dma,
                              object_property_allow_set_link,
                              OBJ_PROP_LINK_STRONG,
-                             &local_err);
+                             errp);
     object_property_add_link(OBJECT(cs), "dma", TYPE_XILINX_AXI_DMA,
                              (Object **)&cs->dma,
                              object_property_allow_set_link,
                              OBJ_PROP_LINK_STRONG,
-                             &local_err);
-    if (local_err) {
-        goto xilinx_axidma_realize_fail;
+                             errp);
+    if (*errp) {
+        return;
     }
-    object_property_set_link(OBJECT(ds), OBJECT(s), "dma", &local_err);
-    object_property_set_link(OBJECT(cs), OBJECT(s), "dma", &local_err);
-    if (local_err) {
-        goto xilinx_axidma_realize_fail;
+    object_property_set_link(OBJECT(ds), OBJECT(s), "dma", errp);
+    object_property_set_link(OBJECT(cs), OBJECT(s), "dma", errp);
+    if (*errp) {
+        return;
     }
 
     int i;
@@ -555,10 +555,6 @@ static void xilinx_axidma_realize(DeviceState *dev, Error **errp)
         st->ptimer = ptimer_init(st->bh, PTIMER_POLICY_DEFAULT);
         ptimer_set_freq(st->ptimer, s->freqhz);
     }
-    return;
-
-xilinx_axidma_realize_fail:
-    error_propagate(errp, local_err);
 }
 
 static void xilinx_axidma_init(Object *obj)
hw/gpio/aspeed_gpio.c +3 -4
index 25fbfec3b8..7683b16ea9 100644
@@ -679,16 +679,15 @@ static void aspeed_gpio_get_pin(Object *obj, Visitor *v, const char *name,
 static void aspeed_gpio_set_pin(Object *obj, Visitor *v, const char *name,
                                void *opaque, Error **errp)
 {
-    Error *local_err = NULL;
+    ERRP_AUTO_PROPAGATE();
     bool level;
     int pin = 0xfff;
     char group[3];
     AspeedGPIOState *s = ASPEED_GPIO(obj);
     int set_idx, group_idx = 0;
 
-    visit_type_bool(v, name, &level, &local_err);
-    if (local_err) {
-        error_propagate(errp, local_err);
+    visit_type_bool(v, name, &level, errp);
+    if (*errp) {
         return;
     }
     if (sscanf(name, "gpio%2[A-Z]%1d", group, &pin) != 2) {
hw/gpio/bcm2835_gpio.c +5 -5
index 91ce3d10cc..0d94f45635 100644
@@ -310,22 +310,22 @@ static void bcm2835_gpio_init(Object *obj)
 
 static void bcm2835_gpio_realize(DeviceState *dev, Error **errp)
 {
+    ERRP_AUTO_PROPAGATE();
     BCM2835GpioState *s = BCM2835_GPIO(dev);
     Object *obj;
-    Error *err = NULL;
 
-    obj = object_property_get_link(OBJECT(dev), "sdbus-sdhci", &err);
+    obj = object_property_get_link(OBJECT(dev), "sdbus-sdhci", errp);
     if (obj == NULL) {
         error_setg(errp, "%s: required sdhci link not found: %s",
-                __func__, error_get_pretty(err));
+                __func__, error_get_pretty(*errp));
         return;
     }
     s->sdbus_sdhci = SD_BUS(obj);
 
-    obj = object_property_get_link(OBJECT(dev), "sdbus-sdhost", &err);
+    obj = object_property_get_link(OBJECT(dev), "sdbus-sdhost", errp);
     if (obj == NULL) {
         error_setg(errp, "%s: required sdhost link not found: %s",
-                __func__, error_get_pretty(err));
+                __func__, error_get_pretty(*errp));
         return;
     }
     s->sdbus_sdhost = SD_BUS(obj);
hw/intc/arm_gic.c +3 -4
index 1d7da7baa2..5d100b03c7 100644
@@ -2036,16 +2036,15 @@ static const MemoryRegionOps gic_viface_ops = {
 
 static void arm_gic_realize(DeviceState *dev, Error **errp)
 {
+    ERRP_AUTO_PROPAGATE();
     /* Device instance realize function for the GIC sysbus device */
     int i;
     GICState *s = ARM_GIC(dev);
     SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
     ARMGICClass *agc = ARM_GIC_GET_CLASS(s);
-    Error *local_err = NULL;
 
-    agc->parent_realize(dev, &local_err);
-    if (local_err) {
-        error_propagate(errp, local_err);
+    agc->parent_realize(dev, errp);
+    if (*errp) {
         return;
     }
 
hw/intc/arm_gic_kvm.c +5 -7
index b56fda144f..25d87e489e 100644
@@ -493,15 +493,14 @@ static void kvm_arm_gic_reset(DeviceState *dev)
 
 static void kvm_arm_gic_realize(DeviceState *dev, Error **errp)
 {
+    ERRP_AUTO_PROPAGATE();
     int i;
     GICState *s = KVM_ARM_GIC(dev);
     KVMARMGICClass *kgc = KVM_ARM_GIC_GET_CLASS(s);
-    Error *local_err = NULL;
     int ret;
 
-    kgc->parent_realize(dev, &local_err);
-    if (local_err) {
-        error_propagate(errp, local_err);
+    kgc->parent_realize(dev, errp);
+    if (*errp) {
         return;
     }
 
@@ -520,9 +519,8 @@ static void kvm_arm_gic_realize(DeviceState *dev, Error **errp)
     if (!kvm_arm_gic_can_save_restore(s)) {
         error_setg(&s->migration_blocker, "This operating system kernel does "
                                           "not support vGICv2 migration");
-        migrate_add_blocker(s->migration_blocker, &local_err);
-        if (local_err) {
-            error_propagate(errp, local_err);
+        migrate_add_blocker(s->migration_blocker, errp);
+        if (*errp) {
             error_free(s->migration_blocker);
             return;
         }
hw/intc/arm_gicv3.c +5 -7
index 66eaa97198..ad8e7d92c0 100644
@@ -363,14 +363,13 @@ static const MemoryRegionOps gic_ops[] = {
 
 static void arm_gic_realize(DeviceState *dev, Error **errp)
 {
+    ERRP_AUTO_PROPAGATE();
     /* Device instance realize function for the GIC sysbus device */
     GICv3State *s = ARM_GICV3(dev);
     ARMGICv3Class *agc = ARM_GICV3_GET_CLASS(s);
-    Error *local_err = NULL;
 
-    agc->parent_realize(dev, &local_err);
-    if (local_err) {
-        error_propagate(errp, local_err);
+    agc->parent_realize(dev, errp);
+    if (*errp) {
         return;
     }
 
@@ -380,9 +379,8 @@ static void arm_gic_realize(DeviceState *dev, Error **errp)
         return;
     }
 
-    gicv3_init_irqs_and_mmio(s, gicv3_set_irq, gic_ops, &local_err);
-    if (local_err) {
-        error_propagate(errp, local_err);
+    gicv3_init_irqs_and_mmio(s, gicv3_set_irq, gic_ops, errp);
+    if (*errp) {
         return;
     }
 
hw/intc/arm_gicv3_its_kvm.c +3 -4
index d66f2431ee..e619bad96e 100644
@@ -90,8 +90,8 @@ static void vm_change_state_handler(void *opaque, int running,
 
 static void kvm_arm_its_realize(DeviceState *dev, Error **errp)
 {
+    ERRP_AUTO_PROPAGATE();
     GICv3ITSState *s = ARM_GICV3_ITS_COMMON(dev);
-    Error *local_err = NULL;
 
     s->dev_fd = kvm_create_device(kvm_state, KVM_DEV_TYPE_ARM_VGIC_ITS, false);
     if (s->dev_fd < 0) {
@@ -113,9 +113,8 @@ static void kvm_arm_its_realize(DeviceState *dev, Error **errp)
         GITS_CTLR)) {
         error_setg(&s->migration_blocker, "This operating system kernel "
                    "does not support vITS migration");
-        migrate_add_blocker(s->migration_blocker, &local_err);
-        if (local_err) {
-            error_propagate(errp, local_err);
+        migrate_add_blocker(s->migration_blocker, errp);
+        if (*errp) {
             error_free(s->migration_blocker);
             return;
         }
hw/intc/arm_gicv3_kvm.c +7 -10
index 9c7f4ab871..9b9a0931f0 100644
@@ -766,17 +766,16 @@ static void vm_change_state_handler(void *opaque, int running,
 
 static void kvm_arm_gicv3_realize(DeviceState *dev, Error **errp)
 {
+    ERRP_AUTO_PROPAGATE();
     GICv3State *s = KVM_ARM_GICV3(dev);
     KVMARMGICv3Class *kgc = KVM_ARM_GICV3_GET_CLASS(s);
     bool multiple_redist_region_allowed;
-    Error *local_err = NULL;
     int i;
 
     DPRINTF("kvm_arm_gicv3_realize\n");
 
-    kgc->parent_realize(dev, &local_err);
-    if (local_err) {
-        error_propagate(errp, local_err);
+    kgc->parent_realize(dev, errp);
+    if (*errp) {
         return;
     }
 
@@ -786,9 +785,8 @@ static void kvm_arm_gicv3_realize(DeviceState *dev, Error **errp)
         return;
     }
 
-    gicv3_init_irqs_and_mmio(s, kvm_arm_gicv3_set_irq, NULL, &local_err);
-    if (local_err) {
-        error_propagate(errp, local_err);
+    gicv3_init_irqs_and_mmio(s, kvm_arm_gicv3_set_irq, NULL, errp);
+    if (*errp) {
         return;
     }
 
@@ -863,9 +861,8 @@ static void kvm_arm_gicv3_realize(DeviceState *dev, Error **errp)
                                GICD_CTLR)) {
         error_setg(&s->migration_blocker, "This operating system kernel does "
                                           "not support vGICv3 migration");
-        migrate_add_blocker(s->migration_blocker, &local_err);
-        if (local_err) {
-            error_propagate(errp, local_err);
+        migrate_add_blocker(s->migration_blocker, errp);
+        if (*errp) {
             error_free(s->migration_blocker);
             return;
         }
hw/intc/armv7m_nvic.c +5 -7
index 8e93e51e81..7e111e34a7 100644
@@ -2608,8 +2608,8 @@ static void nvic_systick_trigger(void *opaque, int n, int level)
 
 static void armv7m_nvic_realize(DeviceState *dev, Error **errp)
 {
+    ERRP_AUTO_PROPAGATE();
     NVICState *s = NVIC(dev);
-    Error *err = NULL;
     int regionlen;
 
     /* The armv7m container object will have set our CPU pointer */
@@ -2631,9 +2631,8 @@ static void armv7m_nvic_realize(DeviceState *dev, Error **errp)
     s->num_prio_bits = arm_feature(&s->cpu->env, ARM_FEATURE_V7) ? 8 : 2;
 
     object_property_set_bool(OBJECT(&s->systick[M_REG_NS]), true,
-                             "realized", &err);
-    if (err != NULL) {
-        error_propagate(errp, err);
+                             "realized", errp);
+    if (*errp) {
         return;
     }
     sysbus_connect_irq(SYS_BUS_DEVICE(&s->systick[M_REG_NS]), 0,
@@ -2650,9 +2649,8 @@ static void armv7m_nvic_realize(DeviceState *dev, Error **errp)
                               sizeof(s->systick[M_REG_S]), TYPE_SYSTICK);
 
         object_property_set_bool(OBJECT(&s->systick[M_REG_S]), true,
-                                 "realized", &err);
-        if (err != NULL) {
-            error_propagate(errp, err);
+                                 "realized", errp);
+        if (*errp) {
             return;
         }
         sysbus_connect_irq(SYS_BUS_DEVICE(&s->systick[M_REG_S]), 0,
hw/intc/realview_gic.c +3 -4
index 73fe8cd815..1335a41f80 100644
@@ -23,10 +23,10 @@ static void realview_gic_set_irq(void *opaque, int irq, int level)
 
 static void realview_gic_realize(DeviceState *dev, Error **errp)
 {
+    ERRP_AUTO_PROPAGATE();
     SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
     RealViewGICState *s = REALVIEW_GIC(dev);
     SysBusDevice *busdev;
-    Error *err = NULL;
     /* The GICs on the RealView boards have a fixed nonconfigurable
      * number of interrupt lines, so we don't need to expose this as
      * a qdev property.
@@ -34,9 +34,8 @@ static void realview_gic_realize(DeviceState *dev, Error **errp)
     int numirq = 96;
 
     qdev_prop_set_uint32(DEVICE(&s->gic), "num-irq", numirq);
-    object_property_set_bool(OBJECT(&s->gic), true, "realized", &err);
-    if (err != NULL) {
-        error_propagate(errp, err);
+    object_property_set_bool(OBJECT(&s->gic), true, "realized", errp);
+    if (*errp) {
         return;
     }
     busdev = SYS_BUS_DEVICE(&s->gic);
hw/microblaze/xlnx-zynqmp-pmu.c +5 -7
index 028f31894d..5cc03eba45 100644
@@ -78,8 +78,8 @@ static void xlnx_zynqmp_pmu_soc_init(Object *obj)
 
 static void xlnx_zynqmp_pmu_soc_realize(DeviceState *dev, Error **errp)
 {
+    ERRP_AUTO_PROPAGATE();
     XlnxZynqMPPMUSoCState *s = XLNX_ZYNQMP_PMU_SOC(dev);
-    Error *err = NULL;
 
     object_property_set_uint(OBJECT(&s->cpu), XLNX_ZYNQMP_PMU_ROM_ADDR,
                              "base-vectors", &error_abort);
@@ -99,9 +99,8 @@ static void xlnx_zynqmp_pmu_soc_realize(DeviceState *dev, Error **errp)
     object_property_set_str(OBJECT(&s->cpu), "8.40.b", "version",
                             &error_abort);
     object_property_set_uint(OBJECT(&s->cpu), 0, "pvr", &error_abort);
-    object_property_set_bool(OBJECT(&s->cpu), true, "realized", &err);
-    if (err) {
-        error_propagate(errp, err);
+    object_property_set_bool(OBJECT(&s->cpu), true, "realized", errp);
+    if (*errp) {
         return;
     }
 
@@ -111,9 +110,8 @@ static void xlnx_zynqmp_pmu_soc_realize(DeviceState *dev, Error **errp)
                              &error_abort);
     object_property_set_uint(OBJECT(&s->intc), 0xffff, "intc-positive",
                              &error_abort);
-    object_property_set_bool(OBJECT(&s->intc), true, "realized", &err);
-    if (err) {
-        error_propagate(errp, err);
+    object_property_set_bool(OBJECT(&s->intc), true, "realized", errp);
+    if (*errp) {
         return;
     }
     sysbus_mmio_map(SYS_BUS_DEVICE(&s->intc), 0, XLNX_ZYNQMP_PMU_INTC_ADDR);
hw/misc/bcm2835_mbox.c +3 -3
index 79bad11631..d20343b846 100644
@@ -298,14 +298,14 @@ static void bcm2835_mbox_reset(DeviceState *dev)
 
 static void bcm2835_mbox_realize(DeviceState *dev, Error **errp)
 {
+    ERRP_AUTO_PROPAGATE();
     BCM2835MboxState *s = BCM2835_MBOX(dev);
     Object *obj;
-    Error *err = NULL;
 
-    obj = object_property_get_link(OBJECT(dev), "mbox-mr", &err);
+    obj = object_property_get_link(OBJECT(dev), "mbox-mr", errp);
     if (obj == NULL) {
         error_setg(errp, "%s: required mbox-mr link not found: %s",
-                   __func__, error_get_pretty(err));
+                   __func__, error_get_pretty(*errp));
         return;
     }
 
hw/misc/bcm2835_property.c +5 -5
index d86d510572..647c630eb9 100644
@@ -382,23 +382,23 @@ static void bcm2835_property_reset(DeviceState *dev)
 
 static void bcm2835_property_realize(DeviceState *dev, Error **errp)
 {
+    ERRP_AUTO_PROPAGATE();
     BCM2835PropertyState *s = BCM2835_PROPERTY(dev);
     Object *obj;
-    Error *err = NULL;
 
-    obj = object_property_get_link(OBJECT(dev), "fb", &err);
+    obj = object_property_get_link(OBJECT(dev), "fb", errp);
     if (obj == NULL) {
         error_setg(errp, "%s: required fb link not found: %s",
-                   __func__, error_get_pretty(err));
+                   __func__, error_get_pretty(*errp));
         return;
     }
 
     s->fbdev = BCM2835_FB(obj);
 
-    obj = object_property_get_link(OBJECT(dev), "dma-mr", &err);
+    obj = object_property_get_link(OBJECT(dev), "dma-mr", errp);
     if (obj == NULL) {
         error_setg(errp, "%s: required dma-mr link not found: %s",
-                   __func__, error_get_pretty(err));
+                   __func__, error_get_pretty(*errp));
         return;
     }
 
hw/misc/msf2-sysreg.c +1 -0
index ddc5a30c80..343351480d 100644
@@ -127,6 +127,7 @@ static Property msf2_sysreg_properties[] = {
 
 static void msf2_sysreg_realize(DeviceState *dev, Error **errp)
 {
+    ERRP_AUTO_PROPAGATE();
     MSF2SysregState *s = MSF2_SYSREG(dev);
 
     if ((s->apb0div > 32 || !is_power_of_2(s->apb0div))
hw/net/xilinx_axienet.c +9 -13
index 2c8c065401..7fd7fd06a8 100644
@@ -947,29 +947,29 @@ static NetClientInfo net_xilinx_enet_info = {
 
 static void xilinx_enet_realize(DeviceState *dev, Error **errp)
 {
+    ERRP_AUTO_PROPAGATE();
     XilinxAXIEnet *s = XILINX_AXI_ENET(dev);
     XilinxAXIEnetStreamSlave *ds = XILINX_AXI_ENET_DATA_STREAM(&s->rx_data_dev);
     XilinxAXIEnetStreamSlave *cs = XILINX_AXI_ENET_CONTROL_STREAM(
                                                             &s->rx_control_dev);
-    Error *local_err = NULL;
 
     object_property_add_link(OBJECT(ds), "enet", "xlnx.axi-ethernet",
                              (Object **) &ds->enet,
                              object_property_allow_set_link,
                              OBJ_PROP_LINK_STRONG,
-                             &local_err);
+                             errp);
     object_property_add_link(OBJECT(cs), "enet", "xlnx.axi-ethernet",
                              (Object **) &cs->enet,
                              object_property_allow_set_link,
                              OBJ_PROP_LINK_STRONG,
-                             &local_err);
-    if (local_err) {
-        goto xilinx_enet_realize_fail;
+                             errp);
+    if (*errp) {
+        return;
     }
-    object_property_set_link(OBJECT(ds), OBJECT(s), "enet", &local_err);
-    object_property_set_link(OBJECT(cs), OBJECT(s), "enet", &local_err);
-    if (local_err) {
-        goto xilinx_enet_realize_fail;
+    object_property_set_link(OBJECT(ds), OBJECT(s), "enet", errp);
+    object_property_set_link(OBJECT(cs), OBJECT(s), "enet", errp);
+    if (*errp) {
+        return;
     }
 
     qemu_macaddr_default_if_unset(&s->conf.macaddr);
@@ -983,10 +983,6 @@ static void xilinx_enet_realize(DeviceState *dev, Error **errp)
     s->TEMAC.parent = s;
 
     s->rxmem = g_malloc(s->c_rxmem);
-    return;
-
-xilinx_enet_realize_fail:
-    error_propagate(errp, local_err);
 }
 
 static void xilinx_enet_init(Object *obj)
hw/nvram/nrf51_nvm.c +3 -4
index 4d678f994e..be72841a5c 100644
@@ -326,13 +326,12 @@ static void nrf51_nvm_init(Object *obj)
 
 static void nrf51_nvm_realize(DeviceState *dev, Error **errp)
 {
+    ERRP_AUTO_PROPAGATE();
     NRF51NVMState *s = NRF51_NVM(dev);
-    Error *err = NULL;
 
     memory_region_init_rom_device(&s->flash, OBJECT(dev), &flash_ops, s,
-        "nrf51_soc.flash", s->flash_size, &err);
-    if (err) {
-        error_propagate(errp, err);
+        "nrf51_soc.flash", s->flash_size, errp);
+    if (*errp) {
         return;
     }
 
hw/timer/aspeed_timer.c +3 -3
index 2bda826882..27bd62fb29 100644
@@ -482,15 +482,15 @@ static void aspeed_init_one_timer(AspeedTimerCtrlState *s, uint8_t id)
 
 static void aspeed_timer_realize(DeviceState *dev, Error **errp)
 {
+    ERRP_AUTO_PROPAGATE();
     int i;
     SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
     AspeedTimerCtrlState *s = ASPEED_TIMER(dev);
     Object *obj;
-    Error *err = NULL;
 
-    obj = object_property_get_link(OBJECT(dev), "scu", &err);
+    obj = object_property_get_link(OBJECT(dev), "scu", errp);
     if (!obj) {
-        error_propagate_prepend(errp, err, "required link 'scu' not found: ");
+        error_prepend(errp, "required link 'scu' not found: ");
         return;
     }
     s->scu = ASPEED_SCU(obj);
hw/watchdog/wdt_aspeed.c +2 -3
index 9b93213417..80c797b0c5 100644
@@ -243,14 +243,13 @@ static void aspeed_wdt_timer_expired(void *dev)
 
 static void aspeed_wdt_realize(DeviceState *dev, Error **errp)
 {
+    ERRP_AUTO_PROPAGATE();
     SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
     AspeedWDTState *s = ASPEED_WDT(dev);
-    Error *err = NULL;
     Object *obj;
 
-    obj = object_property_get_link(OBJECT(dev), "scu", &err);
+    obj = object_property_get_link(OBJECT(dev), "scu", errp);
     if (!obj) {
-        error_propagate(errp, err);
         error_prepend(errp, "required link 'scu' not found: ");
         return;
     }
Signature · 1 line
2.21.0
#77 lore raw

RFC v5 34/126 MIPS Machines: introduce ERRP_AUTO_PROPAGATE

In reply to Vladimir Sementsov-Ogievskiy

If we want to add some info to errp (by error_prepend() or error_append_hint()), we must use the ERRP_AUTO_PROPAGATE macro. Otherwise, this info will not be added when errp == &fatal_err (the program will exit prior to the error_append_hint() or error_prepend() call). Fix such cases.

If we want to check error after errp-function call, we need to introduce local_err and than propagate it to errp. Instead, use ERRP_AUTO_PROPAGATE macro, benefits are:
1. No need of explicit error_propagate call
2. No need of explicit local_err variable: use errp directly
3. ERRP_AUTO_PROPAGATE leaves errp as is if it's not NULL or &error_fatel, this means that we don't break error_abort (we'll abort on error_set, not on error_propagate)

This commit (together with its neighbors) was generated by

for f in $(git grep -l errp \*.[ch]); do \

    spatch --sp-file scripts/coccinelle/auto-propagated-errp.cocci \
    --macro-file scripts/cocci-macro-file.h --in-place --no-show-diff $f; \

done;

then fix a bit of compilation problems: coccinelle for some reason leaves several

f() {
    ...
    goto out;
    ...
    out:
}

patterns, with "out:" at function end.

then
./python/commit-per-subsystem.py MAINTAINERS "$(< auto-msg)"

(auto-msg was a file with this commit message)

Still, for backporting it may be more comfortable to use only the first command and then do one huge commit.

---
 hw/core/loader-fit.c | 2 ++
 1 file changed, 2 insertions(+)
hw/core/loader-fit.c +2 -0
index 3ee9fb2f2e..84f35a1fe2 100644
@@ -120,6 +120,7 @@ static int fit_load_kernel(const struct fit_loader *ldr, const void *itb,
                            int cfg, void *opaque, hwaddr *pend,
                            Error **errp)
 {
+    ERRP_AUTO_PROPAGATE();
     const char *name;
     const void *data;
     const void *load_data;
@@ -178,6 +179,7 @@ static int fit_load_fdt(const struct fit_loader *ldr, const void *itb,
                         int cfg, void *opaque, const void *match_data,
                         hwaddr kernel_end, Error **errp)
 {
+    ERRP_AUTO_PROPAGATE();
     const char *name;
     const void *data;
     const void *load_data;
Signature · 1 line
2.21.0
Reviewed-by on v5 34/126
#78 lore raw

Re: [RFC v5 034/126] MIPS Machines: introduce ERRP_AUTO_PROPAGATE

Hi Vladimir,

Quoted 52 lines · Vladimir Sementsov-Ogievskiy

If we want to add some info to errp (by error_prepend() or error_append_hint()), we must use the ERRP_AUTO_PROPAGATE macro. Otherwise, this info will not be added when errp == &fatal_err (the program will exit prior to the error_append_hint() or error_prepend() call). Fix such cases.

If we want to check error after errp-function call, we need to introduce local_err and than propagate it to errp. Instead, use ERRP_AUTO_PROPAGATE macro, benefits are:
1. No need of explicit error_propagate call
2. No need of explicit local_err variable: use errp directly
3. ERRP_AUTO_PROPAGATE leaves errp as is if it's not NULL or &error_fatel, this means that we don't break error_abort (we'll abort on error_set, not on error_propagate)

This commit (together with its neighbors) was generated by

for f in $(git grep -l errp \*.[ch]); do \

     spatch --sp-file scripts/coccinelle/auto-propagated-errp.cocci \
     --macro-file scripts/cocci-macro-file.h --in-place --no-show-diff $f; \

done;

then fix a bit of compilation problems: coccinelle for some reason leaves several

f() {
     ...
     goto out;
     ...
     out:
}

patterns, with "out:" at function end.

then
./python/commit-per-subsystem.py MAINTAINERS "$(< auto-msg)"

(auto-msg was a file with this commit message)

Still, for backporting it may be more comfortable to use only the first command and then do one huge commit.

---
  hw/core/loader-fit.c | 2 ++
  1 file changed, 2 insertions(+)
hw/core/loader-fit.c +0 -0
index 3ee9fb2f2e..84f35a1fe2 100644

hw/core/loader-fit.c static int fit_load_kernel(const struct fit_loader *ldr, const void *itb, · line 123

Quoted 4 lines
hw/core/loader-fit.c +1 -0
@@ -120,6 +120,7 @@ static int fit_load_kernel(const struct fit_loader *ldr, const void *itb,
                             int cfg, void *opaque, hwaddr *pend,
                             Error **errp)
  {
+    ERRP_AUTO_PROPAGATE();

This certainly looks odd and took me some time to figure it out.

Per include/qapi/error.h:

/*
* ERRP_AUTO_PROPAGATE
*
* This macro is created to be the first line of a function with Error
*errp
* OUT parameter. It's needed only in cases where we want to use
rror_prepend,
* error_append_hint or dereference *errp. It's still safe (but useless) in
* other cases.

This function indeed uses error_prepend():

load_data = data = fit_load_image_alloc(itb, name, &img_off, &sz,

errp);
    if (!data) {
        error_prepend(errp, "unable to load kernel image from FIT: ");
        return -EINVAL;
    }

    err = fit_image_addr(itb, img_off, "load", &load_addr, errp);
    if (err) {
        error_prepend(errp, "unable to read kernel load address from 
FIT: ");
        ret = err;
        goto out;
    }

    err = fit_image_addr(itb, img_off, "entry", &entry_addr, errp);
    if (err) {
        error_prepend(errp, "unable to read kernel entry address from 
FIT: ");
        ret = err;
        goto out;
    }

Generating the patch with more lines context would have help a bit.

Can you add a line about error_prepend() in the commit description?

hw/core/loader-fit.c static int fit_load_fdt(const struct fit_loader *ldr, const void *itb, · line 185

Quoted 12 lines
hw/core/loader-fit.c +1 -0
      const char *name;
      const void *data;
      const void *load_data;
@@ -178,6 +179,7 @@ static int fit_load_fdt(const struct fit_loader *ldr, const void *itb,
                          int cfg, void *opaque, const void *match_data,
                          hwaddr kernel_end, Error **errp)
  {
+    ERRP_AUTO_PROPAGATE();
      const char *name;
      const void *data;
      const void *load_data;

Ditto:

load_data = data = fit_load_image_alloc(itb, name, &img_off, &sz,

errp);
    if (!data) {
        error_prepend(errp, "unable to load FDT image from FIT: ");
        return -EINVAL;
    }

    err = fit_image_addr(itb, img_off, "load", &load_addr, errp);
    if (err == -ENOENT) {
        load_addr = ROUND_UP(kernel_end, 64 * KiB) + (10 * MiB);
        error_free(*errp);
    } else if (err) {
        error_prepend(errp, "unable to read FDT load address from FIT: ");
        ret = err;
        goto out;
    }
#79 lore raw

Re: [RFC v5 034/126] MIPS Machines: introduce ERRP_AUTO_PROPAGATE

Quoted 94 lines · Philippe Mathieu-Daudé

Hi Vladimir,

Quoted 52 lines · Vladimir Sementsov-Ogievskiy

If we want to add some info to errp (by error_prepend() or error_append_hint()), we must use the ERRP_AUTO_PROPAGATE macro. Otherwise, this info will not be added when errp == &fatal_err (the program will exit prior to the error_append_hint() or error_prepend() call).  Fix such cases.

If we want to check error after errp-function call, we need to introduce local_err and than propagate it to errp. Instead, use ERRP_AUTO_PROPAGATE macro, benefits are:
1. No need of explicit error_propagate call
2. No need of explicit local_err variable: use errp directly
3. ERRP_AUTO_PROPAGATE leaves errp as is if it's not NULL or &error_fatel, this means that we don't break error_abort (we'll abort on error_set, not on error_propagate)

This commit (together with its neighbors) was generated by

for f in $(git grep -l errp \*.[ch]); do \
     spatch --sp-file scripts/coccinelle/auto-propagated-errp.cocci \
     --macro-file scripts/cocci-macro-file.h --in-place --no-show-diff $f; \
done;

then fix a bit of compilation problems: coccinelle for some reason leaves several
f() {
     ...
     goto out;
     ...
     out:
}
patterns, with "out:" at function end.

then
./python/commit-per-subsystem.py MAINTAINERS "$(< auto-msg)"

(auto-msg was a file with this commit message)

Still, for backporting it may be more comfortable to use only the first command and then do one huge commit.

---
  hw/core/loader-fit.c | 2 ++

  1 file changed, 2 insertions(+)
hw/core/loader-fit.c +0 -0
index 3ee9fb2f2e..84f35a1fe2 100644

hw/core/loader-fit.c static int fit_load_kernel(const struct fit_loader *ldr, const void *itb, · line 123

Quoted 4 lines
hw/core/loader-fit.c +1 -0
@@ -120,6 +120,7 @@ static int fit_load_kernel(const struct fit_loader *ldr, const void *itb,
                              int cfg, void *opaque, hwaddr *pend,
                              Error **errp)
   {
+    ERRP_AUTO_PROPAGATE();

This certainly looks odd and took me some time to figure it out.

Per include/qapi/error.h:

/*
 * ERRP_AUTO_PROPAGATE
 *
 * This macro is created to be the first line of a function with Error *errp
 * OUT parameter. It's needed only in cases where we want to use rror_prepend,
 * error_append_hint or dereference *errp. It's still safe (but useless) in
 * other cases.

This function indeed uses error_prepend():

    load_data = data = fit_load_image_alloc(itb, name, &img_off, &sz, errp); if (!data) {
        error_prepend(errp, "unable to load kernel image from FIT: "); return -EINVAL;
    }

    err = fit_image_addr(itb, img_off, "load", &load_addr, errp); if (err) {
        error_prepend(errp, "unable to read kernel load address from FIT: "); ret = err;
        goto out;
    }

    err = fit_image_addr(itb, img_off, "entry", &entry_addr, errp); if (err) {
        error_prepend(errp, "unable to read kernel entry address from FIT: "); ret = err;
        goto out;
    }

Quoted 3 lines

Generating the patch with more lines context would have help a bit.

Can you add a line about error_prepend() in the commit description?

Hmm, its already in it: "If we want to add some info to errp (by error_prepend() ...". But better suggestions for commit message wording are welcome, of course.

Quoted 33 lines

hw/core/loader-fit.c static int fit_load_fdt(const struct fit_loader *ldr, const void *itb, · line 185

Quoted 13 lines
hw/core/loader-fit.c +1 -0
       const char *name;
       const void *data;
       const void *load_data;
@@ -178,6 +179,7 @@ static int fit_load_fdt(const struct fit_loader *ldr, const void *itb,
                           int cfg, void *opaque, const void *match_data,
                           hwaddr kernel_end, Error **errp)
   {
+    ERRP_AUTO_PROPAGATE();
       const char *name;
       const void *data;
       const void *load_data;

Ditto:

    load_data = data = fit_load_image_alloc(itb, name, &img_off, &sz, errp); if (!data) {
        error_prepend(errp, "unable to load FDT image from FIT: "); return -EINVAL;
    }

    err = fit_image_addr(itb, img_off, "load", &load_addr, errp); if (err == -ENOENT) {
        load_addr = ROUND_UP(kernel_end, 64 * KiB) + (10 * MiB); error_free(*errp);
    } else if (err) {
        error_prepend(errp, "unable to read FDT load address from FIT: "); ret = err;
        goto out;
    }

Signature · 2 lines
Best regards,
Vladimir
#80 lore raw

RFC v5 35/126 PowerPC Machines: introduce ERRP_AUTO_PROPAGATE

In reply to Vladimir Sementsov-Ogievskiy

If we want to add some info to errp (by error_prepend() or error_append_hint()), we must use the ERRP_AUTO_PROPAGATE macro. Otherwise, this info will not be added when errp == &fatal_err (the program will exit prior to the error_append_hint() or error_prepend() call). Fix such cases.

If we want to check error after errp-function call, we need to introduce local_err and than propagate it to errp. Instead, use ERRP_AUTO_PROPAGATE macro, benefits are:
1. No need of explicit error_propagate call
2. No need of explicit local_err variable: use errp directly
3. ERRP_AUTO_PROPAGATE leaves errp as is if it's not NULL or &error_fatel, this means that we don't break error_abort (we'll abort on error_set, not on error_propagate)

This commit (together with its neighbors) was generated by

for f in $(git grep -l errp \*.[ch]); do \

    spatch --sp-file scripts/coccinelle/auto-propagated-errp.cocci \
    --macro-file scripts/cocci-macro-file.h --in-place --no-show-diff $f; \

done;

then fix a bit of compilation problems: coccinelle for some reason leaves several

f() {
    ...
    goto out;
    ...
    out:
}

patterns, with "out:" at function end.

then
./python/commit-per-subsystem.py MAINTAINERS "$(< auto-msg)"

(auto-msg was a file with this commit message)

Still, for backporting it may be more comfortable to use only the first command and then do one huge commit.

---
 hw/intc/pnv_xive.c      |  15 ++---
 hw/intc/xics.c          |  28 ++++-----
 hw/intc/xics_kvm.c      |  30 +++++----
 hw/intc/xics_pnv.c      |   7 +--
 hw/intc/xics_spapr.c    |   7 +--
 hw/isa/pc87312.c        |   7 +--
 hw/misc/macio/macio.c   |  68 +++++++++-----------
 hw/ppc/e500.c           |   7 +--
 hw/ppc/mac_newworld.c   |   1 +
 hw/ppc/pnv.c            | 109 ++++++++++++++------------------
 hw/ppc/pnv_core.c       |  23 +++----
 hw/ppc/pnv_homer.c      |   5 +-
 hw/ppc/pnv_lpc.c        |  26 ++++----
 hw/ppc/pnv_occ.c        |   5 +-
 hw/ppc/pnv_psi.c        |  23 +++----
 hw/ppc/spapr.c          | 133 ++++++++++++++++++----------------------
 hw/ppc/spapr_caps.c     |  57 ++++++++---------
 hw/ppc/spapr_cpu_core.c |  36 +++++------
 hw/ppc/spapr_drc.c      |  48 ++++++---------
 hw/ppc/spapr_irq.c      |  98 +++++++++++++----------------
 hw/ppc/spapr_pci.c      |  97 +++++++++++++----------------
 hw/ppc/spapr_vio.c      |  12 ++--
 22 files changed, 364 insertions(+), 478 deletions(-)
hw/intc/pnv_xive.c +6 -9
index ed6e9d71bb..05acec9b91 100644
@@ -1659,15 +1659,14 @@ static void pnv_xive_init(Object *obj)
 
 static void pnv_xive_realize(DeviceState *dev, Error **errp)
 {
+    ERRP_AUTO_PROPAGATE();
     PnvXive *xive = PNV_XIVE(dev);
     XiveSource *xsrc = &xive->ipi_source;
     XiveENDSource *end_xsrc = &xive->end_source;
-    Error *local_err = NULL;
     Object *obj;
 
-    obj = object_property_get_link(OBJECT(dev), "chip", &local_err);
+    obj = object_property_get_link(OBJECT(dev), "chip", errp);
     if (!obj) {
-        error_propagate(errp, local_err);
         error_prepend(errp, "required link 'chip' not found: ");
         return;
     }
@@ -1685,9 +1684,8 @@ static void pnv_xive_realize(DeviceState *dev, Error **errp)
                             &error_fatal);
     object_property_add_const_link(OBJECT(xsrc), "xive", OBJECT(xive),
                                    &error_fatal);
-    object_property_set_bool(OBJECT(xsrc), true, "realized", &local_err);
-    if (local_err) {
-        error_propagate(errp, local_err);
+    object_property_set_bool(OBJECT(xsrc), true, "realized", errp);
+    if (*errp) {
         return;
     }
 
@@ -1695,9 +1693,8 @@ static void pnv_xive_realize(DeviceState *dev, Error **errp)
                             &error_fatal);
     object_property_add_const_link(OBJECT(end_xsrc), "xive", OBJECT(xive),
                                    &error_fatal);
-    object_property_set_bool(OBJECT(end_xsrc), true, "realized", &local_err);
-    if (local_err) {
-        error_propagate(errp, local_err);
+    object_property_set_bool(OBJECT(end_xsrc), true, "realized", errp);
+    if (*errp) {
         return;
     }
 
hw/intc/xics.c +13 -15
index dfe7dbd254..91a3e8840a 100644
@@ -297,15 +297,15 @@ static void icp_reset_handler(void *dev)
 
 static void icp_realize(DeviceState *dev, Error **errp)
 {
+    ERRP_AUTO_PROPAGATE();
     ICPState *icp = ICP(dev);
     PowerPCCPU *cpu;
     CPUPPCState *env;
     Object *obj;
-    Error *err = NULL;
 
-    obj = object_property_get_link(OBJECT(dev), ICP_PROP_XICS, &err);
+    obj = object_property_get_link(OBJECT(dev), ICP_PROP_XICS, errp);
     if (!obj) {
-        error_propagate_prepend(errp, err,
+        error_prepend(errp,
                                 "required link '" ICP_PROP_XICS
                                 "' not found: ");
         return;
@@ -313,9 +313,9 @@ static void icp_realize(DeviceState *dev, Error **errp)
 
     icp->xics = XICS_FABRIC(obj);
 
-    obj = object_property_get_link(OBJECT(dev), ICP_PROP_CPU, &err);
+    obj = object_property_get_link(OBJECT(dev), ICP_PROP_CPU, errp);
     if (!obj) {
-        error_propagate_prepend(errp, err,
+        error_prepend(errp,
                                 "required link '" ICP_PROP_CPU
                                 "' not found: ");
         return;
@@ -344,9 +344,8 @@ static void icp_realize(DeviceState *dev, Error **errp)
 
     /* Connect the presenter to the VCPU (required for CPU hotplug) */
     if (kvm_irqchip_in_kernel()) {
-        icp_kvm_realize(dev, &err);
-        if (err) {
-            error_propagate(errp, err);
+        icp_kvm_realize(dev, errp);
+        if (*errp) {
             return;
         }
     }
@@ -381,7 +380,7 @@ static const TypeInfo icp_info = {
 
 Object *icp_create(Object *cpu, const char *type, XICSFabric *xi, Error **errp)
 {
-    Error *local_err = NULL;
+    ERRP_AUTO_PROPAGATE();
     Object *obj;
 
     obj = object_new(type);
@@ -390,10 +389,9 @@ Object *icp_create(Object *cpu, const char *type, XICSFabric *xi, Error **errp)
     object_property_add_const_link(obj, ICP_PROP_XICS, OBJECT(xi),
                                    &error_abort);
     object_property_add_const_link(obj, ICP_PROP_CPU, cpu, &error_abort);
-    object_property_set_bool(obj, true, "realized", &local_err);
-    if (local_err) {
+    object_property_set_bool(obj, true, "realized", errp);
+    if (*errp) {
         object_unparent(obj);
-        error_propagate(errp, local_err);
         obj = NULL;
     }
 
@@ -587,13 +585,13 @@ static void ics_reset_handler(void *dev)
 
 static void ics_realize(DeviceState *dev, Error **errp)
 {
+    ERRP_AUTO_PROPAGATE();
     ICSState *ics = ICS(dev);
-    Error *local_err = NULL;
     Object *obj;
 
-    obj = object_property_get_link(OBJECT(dev), ICS_PROP_XICS, &local_err);
+    obj = object_property_get_link(OBJECT(dev), ICS_PROP_XICS, errp);
     if (!obj) {
-        error_propagate_prepend(errp, local_err,
+        error_prepend(errp,
                                 "required link '" ICS_PROP_XICS
                                 "' not found: ");
         return;
hw/intc/xics_kvm.c +14 -16
index ba90d6dc96..66902228e3 100644
@@ -294,6 +294,7 @@ int ics_set_kvm_state_one(ICSState *ics, int srcno, Error **errp)
 
 int ics_set_kvm_state(ICSState *ics, Error **errp)
 {
+    ERRP_AUTO_PROPAGATE();
     int i;
 
     /* The KVM XICS device is not in use */
@@ -302,16 +303,14 @@ int ics_set_kvm_state(ICSState *ics, Error **errp)
     }
 
     for (i = 0; i < ics->nr_irqs; i++) {
-        Error *local_err = NULL;
         int ret;
 
         if (ics_irq_free(ics, i)) {
             continue;
         }
 
-        ret = ics_set_kvm_state_one(ics, i, &local_err);
+        ret = ics_set_kvm_state_one(ics, i, errp);
         if (ret < 0) {
-            error_propagate(errp, local_err);
             return ret;
         }
     }
@@ -344,9 +343,9 @@ void ics_kvm_set_irq(ICSState *ics, int srcno, int val)
 
 int xics_kvm_connect(SpaprMachineState *spapr, Error **errp)
 {
+    ERRP_AUTO_PROPAGATE();
     int rc;
     CPUState *cs;
-    Error *local_err = NULL;
 
     /*
      * The KVM XICS device already in use. This is the case when
@@ -364,28 +363,28 @@ int xics_kvm_connect(SpaprMachineState *spapr, Error **errp)
 
     rc = kvmppc_define_rtas_kernel_token(RTAS_IBM_SET_XIVE, "ibm,set-xive");
     if (rc < 0) {
-        error_setg_errno(&local_err, -rc,
+        error_setg_errno(errp, -rc,
                          "kvmppc_define_rtas_kernel_token: ibm,set-xive");
         goto fail;
     }
 
     rc = kvmppc_define_rtas_kernel_token(RTAS_IBM_GET_XIVE, "ibm,get-xive");
     if (rc < 0) {
-        error_setg_errno(&local_err, -rc,
+        error_setg_errno(errp, -rc,
                          "kvmppc_define_rtas_kernel_token: ibm,get-xive");
         goto fail;
     }
 
     rc = kvmppc_define_rtas_kernel_token(RTAS_IBM_INT_ON, "ibm,int-on");
     if (rc < 0) {
-        error_setg_errno(&local_err, -rc,
+        error_setg_errno(errp, -rc,
                          "kvmppc_define_rtas_kernel_token: ibm,int-on");
         goto fail;
     }
 
     rc = kvmppc_define_rtas_kernel_token(RTAS_IBM_INT_OFF, "ibm,int-off");
     if (rc < 0) {
-        error_setg_errno(&local_err, -rc,
+        error_setg_errno(errp, -rc,
                          "kvmppc_define_rtas_kernel_token: ibm,int-off");
         goto fail;
     }
@@ -393,7 +392,7 @@ int xics_kvm_connect(SpaprMachineState *spapr, Error **errp)
     /* Create the KVM XICS device */
     rc = kvm_create_device(kvm_state, KVM_DEV_TYPE_XICS, false);
     if (rc < 0) {
-        error_setg_errno(&local_err, -rc, "Error on KVM_CREATE_DEVICE for XICS");
+        error_setg_errno(errp, -rc, "Error on KVM_CREATE_DEVICE for XICS");
         goto fail;
     }
 
@@ -406,23 +405,23 @@ int xics_kvm_connect(SpaprMachineState *spapr, Error **errp)
     CPU_FOREACH(cs) {
         PowerPCCPU *cpu = POWERPC_CPU(cs);
 
-        icp_kvm_realize(DEVICE(spapr_cpu_state(cpu)->icp), &local_err);
-        if (local_err) {
+        icp_kvm_realize(DEVICE(spapr_cpu_state(cpu)->icp), errp);
+        if (*errp) {
             goto fail;
         }
     }
 
     /* Update the KVM sources */
-    ics_set_kvm_state(spapr->ics, &local_err);
-    if (local_err) {
+    ics_set_kvm_state(spapr->ics, errp);
+    if (*errp) {
         goto fail;
     }
 
     /* Connect the presenters to the initial VCPUs of the machine */
     CPU_FOREACH(cs) {
         PowerPCCPU *cpu = POWERPC_CPU(cs);
-        icp_set_kvm_state(spapr_cpu_state(cpu)->icp, &local_err);
-        if (local_err) {
+        icp_set_kvm_state(spapr_cpu_state(cpu)->icp, errp);
+        if (*errp) {
             goto fail;
         }
     }
@@ -430,7 +429,6 @@ int xics_kvm_connect(SpaprMachineState *spapr, Error **errp)
     return 0;
 
 fail:
-    error_propagate(errp, local_err);
     xics_kvm_disconnect(spapr, NULL);
     return -1;
 }
hw/intc/xics_pnv.c +3 -4
index 35f3811264..501aee21d7 100644
@@ -161,14 +161,13 @@ static const MemoryRegionOps pnv_icp_ops = {
 
 static void pnv_icp_realize(DeviceState *dev, Error **errp)
 {
+    ERRP_AUTO_PROPAGATE();
     ICPState *icp = ICP(dev);
     PnvICPState *pnv_icp = PNV_ICP(icp);
     ICPStateClass *icpc = ICP_GET_CLASS(icp);
-    Error *local_err = NULL;
 
-    icpc->parent_realize(dev, &local_err);
-    if (local_err) {
-        error_propagate(errp, local_err);
+    icpc->parent_realize(dev, errp);
+    if (*errp) {
         return;
     }
 
hw/intc/xics_spapr.c +3 -4
index 6e5eb24b3c..2c21ad8ea9 100644
@@ -285,13 +285,12 @@ static void rtas_int_on(PowerPCCPU *cpu, SpaprMachineState *spapr,
 
 static void ics_spapr_realize(DeviceState *dev, Error **errp)
 {
+    ERRP_AUTO_PROPAGATE();
     ICSState *ics = ICS_SPAPR(dev);
     ICSStateClass *icsc = ICS_GET_CLASS(ics);
-    Error *local_err = NULL;
 
-    icsc->parent_realize(dev, &local_err);
-    if (local_err) {
-        error_propagate(errp, local_err);
+    icsc->parent_realize(dev, errp);
+    if (*errp) {
         return;
     }
 
hw/isa/pc87312.c +3 -4
index b9bd57471e..ac30eaed33 100644
@@ -291,18 +291,17 @@ static void pc87312_reset(DeviceState *d)
 
 static void pc87312_realize(DeviceState *dev, Error **errp)
 {
+    ERRP_AUTO_PROPAGATE();
     PC87312State *s;
     ISADevice *isa;
-    Error *local_err = NULL;
 
     s = PC87312(dev);
     isa = ISA_DEVICE(dev);
     isa_register_ioport(isa, &s->io, s->iobase);
     pc87312_hard_reset(s);
 
-    ISA_SUPERIO_GET_CLASS(dev)->parent_realize(dev, &local_err);
-    if (local_err) {
-        error_propagate(errp, local_err);
+    ISA_SUPERIO_GET_CLASS(dev)->parent_realize(dev, errp);
+    if (*errp) {
         return;
     }
 }
hw/misc/macio/macio.c +28 -40

159 lines not on this page · raw message

hw/ppc/e500.c +3 -4
index 91cd4c26f9..468d667261 100644
@@ -764,16 +764,15 @@ static DeviceState *ppce500_init_mpic_qemu(PPCE500MachineState *pms,
 static DeviceState *ppce500_init_mpic_kvm(const PPCE500MachineClass *pmc,
                                           IrqLines *irqs, Error **errp)
 {
-    Error *err = NULL;
+    ERRP_AUTO_PROPAGATE();
     DeviceState *dev;
     CPUState *cs;
 
     dev = qdev_create(NULL, TYPE_KVM_OPENPIC);
     qdev_prop_set_uint32(dev, "model", pmc->mpic_version);
 
-    object_property_set_bool(OBJECT(dev), true, "realized", &err);
-    if (err) {
-        error_propagate(errp, err);
+    object_property_set_bool(OBJECT(dev), true, "realized", errp);
+    if (*errp) {
         object_unparent(OBJECT(dev));
         return NULL;
     }
hw/ppc/mac_newworld.c +1 -0
index c5bbcc7433..1a37412d31 100644
@@ -609,6 +609,7 @@ static char *core99_get_via_config(Object *obj, Error **errp)
 
 static void core99_set_via_config(Object *obj, const char *value, Error **errp)
 {
+    ERRP_AUTO_PROPAGATE();
     Core99MachineState *cms = CORE99_MACHINE(obj);
 
     if (!strcmp(value, "cuda")) {
hw/ppc/pnv.c +45 -64

250 lines not on this page · raw message

hw/ppc/pnv_core.c +10 -13
index b1a7489e7a..c45b326f78 100644
@@ -162,22 +162,20 @@ static const MemoryRegionOps pnv_core_power9_xscom_ops = {
 
 static void pnv_realize_vcpu(PowerPCCPU *cpu, PnvChip *chip, Error **errp)
 {
+    ERRP_AUTO_PROPAGATE();
     CPUPPCState *env = &cpu->env;
     int core_pir;
     int thread_index = 0; /* TODO: TCG supports only one thread */
     ppc_spr_t *pir = &env->spr_cb[SPR_PIR];
-    Error *local_err = NULL;
     PnvChipClass *pcc = PNV_CHIP_GET_CLASS(chip);
 
-    object_property_set_bool(OBJECT(cpu), true, "realized", &local_err);
-    if (local_err) {
-        error_propagate(errp, local_err);
+    object_property_set_bool(OBJECT(cpu), true, "realized", errp);
+    if (*errp) {
         return;
     }
 
-    pcc->intc_create(chip, cpu, &local_err);
-    if (local_err) {
-        error_propagate(errp, local_err);
+    pcc->intc_create(chip, cpu, errp);
+    if (*errp) {
         return;
     }
 
@@ -198,19 +196,19 @@ static void pnv_realize_vcpu(PowerPCCPU *cpu, PnvChip *chip, Error **errp)
 
 static void pnv_core_realize(DeviceState *dev, Error **errp)
 {
+    ERRP_AUTO_PROPAGATE();
     PnvCore *pc = PNV_CORE(OBJECT(dev));
     PnvCoreClass *pcc = PNV_CORE_GET_CLASS(pc);
     CPUCore *cc = CPU_CORE(OBJECT(dev));
     const char *typename = pnv_core_cpu_typename(pc);
-    Error *local_err = NULL;
     void *obj;
     int i, j;
     char name[32];
     Object *chip;
 
-    chip = object_property_get_link(OBJECT(dev), "chip", &local_err);
+    chip = object_property_get_link(OBJECT(dev), "chip", errp);
     if (!chip) {
-        error_propagate_prepend(errp, local_err,
+        error_prepend(errp,
                                 "required link 'chip' not found: ");
         return;
     }
@@ -235,8 +233,8 @@ static void pnv_core_realize(DeviceState *dev, Error **errp)
     }
 
     for (j = 0; j < cc->nr_threads; j++) {
-        pnv_realize_vcpu(pc->threads[j], PNV_CHIP(chip), &local_err);
-        if (local_err) {
+        pnv_realize_vcpu(pc->threads[j], PNV_CHIP(chip), errp);
+        if (*errp) {
             goto err;
         }
     }
@@ -252,7 +250,6 @@ err:
         object_unparent(obj);
     }
     g_free(pc->threads);
-    error_propagate(errp, local_err);
 }
 
 static void pnv_unrealize_vcpu(PowerPCCPU *cpu)
hw/ppc/pnv_homer.c +2 -3
index cc881a3b32..80e3acf94a 100644
@@ -227,14 +227,13 @@ static const TypeInfo pnv_homer_power9_type_info = {
 
 static void pnv_homer_realize(DeviceState *dev, Error **errp)
 {
+    ERRP_AUTO_PROPAGATE();
     PnvHomer *homer = PNV_HOMER(dev);
     PnvHomerClass *hmrc = PNV_HOMER_GET_CLASS(homer);
     Object *obj;
-    Error *local_err = NULL;
 
-    obj = object_property_get_link(OBJECT(dev), "chip", &local_err);
+    obj = object_property_get_link(OBJECT(dev), "chip", errp);
     if (!obj) {
-        error_propagate(errp, local_err);
         error_prepend(errp, "required link 'chip' not found: ");
         return;
     }
hw/ppc/pnv_lpc.c +11 -15
index 9466d4a1be..7f6041cc28 100644
@@ -599,13 +599,12 @@ static const MemoryRegionOps opb_master_ops = {
 
 static void pnv_lpc_power8_realize(DeviceState *dev, Error **errp)
 {
+    ERRP_AUTO_PROPAGATE();
     PnvLpcController *lpc = PNV_LPC(dev);
     PnvLpcClass *plc = PNV_LPC_GET_CLASS(dev);
-    Error *local_err = NULL;
 
-    plc->parent_realize(dev, &local_err);
-    if (local_err) {
-        error_propagate(errp, local_err);
+    plc->parent_realize(dev, errp);
+    if (*errp) {
         return;
     }
 
@@ -644,13 +643,12 @@ static const TypeInfo pnv_lpc_power8_info = {
 
 static void pnv_lpc_power9_realize(DeviceState *dev, Error **errp)
 {
+    ERRP_AUTO_PROPAGATE();
     PnvLpcController *lpc = PNV_LPC(dev);
     PnvLpcClass *plc = PNV_LPC_GET_CLASS(dev);
-    Error *local_err = NULL;
 
-    plc->parent_realize(dev, &local_err);
-    if (local_err) {
-        error_propagate(errp, local_err);
+    plc->parent_realize(dev, errp);
+    if (*errp) {
         return;
     }
 
@@ -681,13 +679,12 @@ static const TypeInfo pnv_lpc_power9_info = {
 
 static void pnv_lpc_realize(DeviceState *dev, Error **errp)
 {
+    ERRP_AUTO_PROPAGATE();
     PnvLpcController *lpc = PNV_LPC(dev);
     Object *obj;
-    Error *local_err = NULL;
 
-    obj = object_property_get_link(OBJECT(dev), "psi", &local_err);
+    obj = object_property_get_link(OBJECT(dev), "psi", errp);
     if (!obj) {
-        error_propagate(errp, local_err);
         error_prepend(errp, "required link 'psi' not found: ");
         return;
     }
@@ -797,7 +794,7 @@ static void pnv_lpc_isa_irq_handler(void *opaque, int n, int level)
 
 ISABus *pnv_lpc_isa_create(PnvLpcController *lpc, bool use_cpld, Error **errp)
 {
-    Error *local_err = NULL;
+    ERRP_AUTO_PROPAGATE();
     ISABus *isa_bus;
     qemu_irq *irqs;
     qemu_irq_handler handler;
@@ -806,9 +803,8 @@ ISABus *pnv_lpc_isa_create(PnvLpcController *lpc, bool use_cpld, Error **errp)
      * devices speficied on the command line won't find the bus and
      * will fail to create.
      */
-    isa_bus = isa_bus_new(NULL, &lpc->isa_mem, &lpc->isa_io, &local_err);
-    if (local_err) {
-        error_propagate(errp, local_err);
+    isa_bus = isa_bus_new(NULL, &lpc->isa_mem, &lpc->isa_io, errp);
+    if (*errp) {
         return NULL;
     }
 
hw/ppc/pnv_occ.c +2 -3
index 785653bb67..3306109a9b 100644
@@ -255,16 +255,15 @@ static const TypeInfo pnv_occ_power9_type_info = {
 
 static void pnv_occ_realize(DeviceState *dev, Error **errp)
 {
+    ERRP_AUTO_PROPAGATE();
     PnvOCC *occ = PNV_OCC(dev);
     PnvOCCClass *poc = PNV_OCC_GET_CLASS(occ);
     Object *obj;
-    Error *local_err = NULL;
 
     occ->occmisc = 0;
 
-    obj = object_property_get_link(OBJECT(dev), "psi", &local_err);
+    obj = object_property_get_link(OBJECT(dev), "psi", errp);
     if (!obj) {
-        error_propagate(errp, local_err);
         error_prepend(errp, "required link 'psi' not found: ");
         return;
     }
hw/ppc/pnv_psi.c +10 -13
index a997f16bb4..e96db52b82 100644
@@ -483,30 +483,28 @@ static const uint8_t irq_to_xivr[] = {
 
 static void pnv_psi_power8_realize(DeviceState *dev, Error **errp)
 {
+    ERRP_AUTO_PROPAGATE();
     PnvPsi *psi = PNV_PSI(dev);
     ICSState *ics = &PNV8_PSI(psi)->ics;
     Object *obj;
-    Error *err = NULL;
     unsigned int i;
 
-    obj = object_property_get_link(OBJECT(dev), "xics", &err);
+    obj = object_property_get_link(OBJECT(dev), "xics", errp);
     if (!obj) {
         error_setg(errp, "%s: required link 'xics' not found: %s",
-                   __func__, error_get_pretty(err));
+                   __func__, error_get_pretty(*errp));
         return;
     }
 
     /* Create PSI interrupt control source */
     object_property_add_const_link(OBJECT(ics), ICS_PROP_XICS, obj,
                                    &error_abort);
-    object_property_set_int(OBJECT(ics), PSI_NUM_INTERRUPTS, "nr-irqs", &err);
-    if (err) {
-        error_propagate(errp, err);
+    object_property_set_int(OBJECT(ics), PSI_NUM_INTERRUPTS, "nr-irqs", errp);
+    if (*errp) {
         return;
     }
-    object_property_set_bool(OBJECT(ics), true, "realized",  &err);
-    if (err) {
-        error_propagate(errp, err);
+    object_property_set_bool(OBJECT(ics), true, "realized",  errp);
+    if (*errp) {
         return;
     }
 
@@ -832,9 +830,9 @@ static void pnv_psi_power9_instance_init(Object *obj)
 
 static void pnv_psi_power9_realize(DeviceState *dev, Error **errp)
 {
+    ERRP_AUTO_PROPAGATE();
     PnvPsi *psi = PNV_PSI(dev);
     XiveSource *xsrc = &PNV9_PSI(psi)->source;
-    Error *local_err = NULL;
     int i;
 
     /* This is the only device with 4k ESB pages */
@@ -844,9 +842,8 @@ static void pnv_psi_power9_realize(DeviceState *dev, Error **errp)
                             &error_fatal);
     object_property_add_const_link(OBJECT(xsrc), "xive", OBJECT(psi),
                                    &error_fatal);
-    object_property_set_bool(OBJECT(xsrc), true, "realized", &local_err);
-    if (local_err) {
-        error_propagate(errp, local_err);
+    object_property_set_bool(OBJECT(xsrc), true, "realized", errp);
+    if (*errp) {
         return;
     }
 
hw/ppc/spapr.c +59 -74

357 lines not on this page · raw message

hw/ppc/spapr_caps.c +26 -31

156 lines not on this page · raw message

hw/ppc/spapr_cpu_core.c +16 -20
index 1d93de8161..471eaee317 100644
@@ -219,13 +219,13 @@ static void spapr_cpu_core_unrealize(DeviceState *dev, Error **errp)
 static void spapr_realize_vcpu(PowerPCCPU *cpu, SpaprMachineState *spapr,
                                SpaprCpuCore *sc, Error **errp)
 {
+    ERRP_AUTO_PROPAGATE();
     CPUPPCState *env = &cpu->env;
     CPUState *cs = CPU(cpu);
-    Error *local_err = NULL;
 
-    object_property_set_bool(OBJECT(cpu), true, "realized", &local_err);
-    if (local_err) {
-        goto error;
+    object_property_set_bool(OBJECT(cpu), true, "realized", errp);
+    if (*errp) {
+        return;
     }
 
     /* Set time-base frequency to 512 MHz */
@@ -237,8 +237,8 @@ static void spapr_realize_vcpu(PowerPCCPU *cpu, SpaprMachineState *spapr,
     qemu_register_reset(spapr_cpu_reset, cpu);
     spapr_cpu_reset(cpu);
 
-    spapr->irq->cpu_intc_create(spapr, cpu, &local_err);
-    if (local_err) {
+    spapr->irq->cpu_intc_create(spapr, cpu, errp);
+    if (*errp) {
         goto error_unregister;
     }
 
@@ -252,36 +252,34 @@ static void spapr_realize_vcpu(PowerPCCPU *cpu, SpaprMachineState *spapr,
 error_unregister:
     qemu_unregister_reset(spapr_cpu_reset, cpu);
     cpu_remove_sync(CPU(cpu));
-error:
-    error_propagate(errp, local_err);
 }
 
 static PowerPCCPU *spapr_create_vcpu(SpaprCpuCore *sc, int i, Error **errp)
 {
+    ERRP_AUTO_PROPAGATE();
     SpaprCpuCoreClass *scc = SPAPR_CPU_CORE_GET_CLASS(sc);
     CPUCore *cc = CPU_CORE(sc);
     Object *obj;
     char *id;
     CPUState *cs;
     PowerPCCPU *cpu;
-    Error *local_err = NULL;
 
     obj = object_new(scc->cpu_type);
 
     cs = CPU(obj);
     cpu = POWERPC_CPU(obj);
     cs->cpu_index = cc->core_id + i;
-    spapr_set_vcpu_id(cpu, cs->cpu_index, &local_err);
-    if (local_err) {
+    spapr_set_vcpu_id(cpu, cs->cpu_index, errp);
+    if (*errp) {
         goto err;
     }
 
     cpu->node_id = sc->node_id;
 
     id = g_strdup_printf("thread[%d]", i);
-    object_property_add_child(OBJECT(sc), id, obj, &local_err);
+    object_property_add_child(OBJECT(sc), id, obj, errp);
     g_free(id);
-    if (local_err) {
+    if (*errp) {
         goto err;
     }
 
@@ -292,7 +290,6 @@ static PowerPCCPU *spapr_create_vcpu(SpaprCpuCore *sc, int i, Error **errp)
 
 err:
     object_unref(obj);
-    error_propagate(errp, local_err);
     return NULL;
 }
 
@@ -307,6 +304,7 @@ static void spapr_delete_vcpu(PowerPCCPU *cpu, SpaprCpuCore *sc)
 
 static void spapr_cpu_core_realize(DeviceState *dev, Error **errp)
 {
+    ERRP_AUTO_PROPAGATE();
     /* We don't use SPAPR_MACHINE() in order to exit gracefully if the user
      * tries to add a sPAPR CPU core to a non-pseries machine.
      */
@@ -315,7 +313,6 @@ static void spapr_cpu_core_realize(DeviceState *dev, Error **errp)
                                                   TYPE_SPAPR_MACHINE);
     SpaprCpuCore *sc = SPAPR_CPU_CORE(OBJECT(dev));
     CPUCore *cc = CPU_CORE(OBJECT(dev));
-    Error *local_err = NULL;
     int i, j;
 
     if (!spapr) {
@@ -325,15 +322,15 @@ static void spapr_cpu_core_realize(DeviceState *dev, Error **errp)
 
     sc->threads = g_new(PowerPCCPU *, cc->nr_threads);
     for (i = 0; i < cc->nr_threads; i++) {
-        sc->threads[i] = spapr_create_vcpu(sc, i, &local_err);
-        if (local_err) {
+        sc->threads[i] = spapr_create_vcpu(sc, i, errp);
+        if (*errp) {
             goto err;
         }
     }
 
     for (j = 0; j < cc->nr_threads; j++) {
-        spapr_realize_vcpu(sc->threads[j], spapr, sc, &local_err);
-        if (local_err) {
+        spapr_realize_vcpu(sc->threads[j], spapr, sc, errp);
+        if (*errp) {
             goto err_unrealize;
         }
     }
@@ -348,7 +345,6 @@ err:
         spapr_delete_vcpu(sc->threads[i], sc);
     }
     g_free(sc->threads);
-    error_propagate(errp, local_err);
 }
 
 static Property spapr_cpu_core_properties[] = {
hw/ppc/spapr_drc.c +20 -28

116 lines not on this page · raw message

hw/ppc/spapr_irq.c +42 -56

215 lines not on this page · raw message

hw/ppc/spapr_pci.c +42 -55

259 lines not on this page · raw message

hw/ppc/spapr_vio.c +5 -7
index 554de9930d..cae3e99412 100644
@@ -463,11 +463,11 @@ static inline uint32_t spapr_vio_reg_to_irq(uint32_t reg)
 
 static void spapr_vio_busdev_realize(DeviceState *qdev, Error **errp)
 {
+    ERRP_AUTO_PROPAGATE();
     SpaprMachineState *spapr = SPAPR_MACHINE(qdev_get_machine());
     SpaprVioDevice *dev = (SpaprVioDevice *)qdev;
     SpaprVioDeviceClass *pc = VIO_SPAPR_DEVICE_GET_CLASS(dev);
     char *id;
-    Error *local_err = NULL;
 
     if (dev->reg != -1) {
         /*
@@ -503,16 +503,14 @@ static void spapr_vio_busdev_realize(DeviceState *qdev, Error **errp)
     dev->irq = spapr_vio_reg_to_irq(dev->reg);
 
     if (SPAPR_MACHINE_GET_CLASS(spapr)->legacy_irq_allocation) {
-        dev->irq = spapr_irq_findone(spapr, &local_err);
-        if (local_err) {
-            error_propagate(errp, local_err);
+        dev->irq = spapr_irq_findone(spapr, errp);
+        if (*errp) {
             return;
         }
     }
 
-    spapr_irq_claim(spapr, dev->irq, false, &local_err);
-    if (local_err) {
-        error_propagate(errp, local_err);
+    spapr_irq_claim(spapr, dev->irq, false, errp);
+    if (*errp) {
         return;
     }
 
Signature · 1 line
2.21.0