From patchwork Wed Sep 7 06:06:30 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 9318233 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id B460E6077F for ; Wed, 7 Sep 2016 06:12:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A3ACE28D71 for ; Wed, 7 Sep 2016 06:12:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 96DDC29028; Wed, 7 Sep 2016 06:12:33 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id E9AAF28D71 for ; Wed, 7 Sep 2016 06:12:32 +0000 (UTC) Received: from localhost ([::1]:38240 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bhW62-00053D-Pq for patchwork-qemu-devel@patchwork.kernel.org; Wed, 07 Sep 2016 02:12:30 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51707) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bhW0Y-0008Hx-CK for qemu-devel@nongnu.org; Wed, 07 Sep 2016 02:06:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bhW0U-0001nh-3D for qemu-devel@nongnu.org; Wed, 07 Sep 2016 02:06:49 -0400 Received: from mx1.redhat.com ([209.132.183.28]:37182) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bhW0T-0001nd-RD for qemu-devel@nongnu.org; Wed, 07 Sep 2016 02:06:46 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7191F824; Wed, 7 Sep 2016 06:06:45 +0000 (UTC) Received: from pxdev.xzpeter.org.com (dhcp-14-106.nay.redhat.com [10.66.14.106]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u8766W2m024709; Wed, 7 Sep 2016 02:06:43 -0400 From: Peter Xu To: qemu-devel@nongnu.org Date: Wed, 7 Sep 2016 14:06:30 +0800 Message-Id: <1473228390-18669-5-git-send-email-peterx@redhat.com> In-Reply-To: <1473228390-18669-1-git-send-email-peterx@redhat.com> References: <1473228390-18669-1-git-send-email-peterx@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Wed, 07 Sep 2016 06:06:45 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v4 4/4] error-report: leverage error_report_abort() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, famz@redhat.com, armbru@redhat.com, peterx@redhat.com, pbonzini@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Two cases that can leverage error_report_abort(): Case 1: error_report(...); abort(); Case 2: error_setg(&error_abort, ...); This patch converts these cases to use error_report_abort(). Script error_report_abort.cocci is added to automate the convertion. Signed-off-by: Peter Xu --- block/qcow2.c | 4 ++-- hw/block/fdc.c | 6 +++--- hw/i386/kvm/pci-assign.c | 4 ++-- hw/intc/xics.c | 5 ++--- hw/pci/pci.c | 3 +-- hw/ppc/spapr_drc.c | 2 +- hw/vfio/platform.c | 10 ++++------ net/netmap.c | 5 ++--- net/tap-linux.c | 10 ++++++---- scripts/coccinelle/error_report_abort.cocci | 14 ++++++++++++++ target-ppc/translate_init.c | 3 +-- vl.c | 7 +++---- 12 files changed, 41 insertions(+), 32 deletions(-) create mode 100644 scripts/coccinelle/error_report_abort.cocci diff --git a/block/qcow2.c b/block/qcow2.c index 91ef4df..d491564 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -2254,8 +2254,8 @@ static int qcow2_create2(const char *filename, int64_t total_size, goto out; } else if (ret != 0) { - error_report("Huh, first cluster in empty image is already in use?"); - abort(); + error_report_abort("Huh, first cluster in empty image is " + "already in use?"); } /* Create a full header (including things like feature table) */ diff --git a/hw/block/fdc.c b/hw/block/fdc.c index f73af7d..14d2f20 100644 --- a/hw/block/fdc.c +++ b/hw/block/fdc.c @@ -372,9 +372,9 @@ static int pick_geometry(FDrive *drv) /* No match of any kind found -- fd_format is misconfigured, abort. */ if (match == -1) { - error_setg(&error_abort, "No candidate geometries present in table " - " for floppy drive type '%s'", - FloppyDriveType_lookup[drv->drive]); + error_report_abort("No candidate geometries present in table " + " for floppy drive type '%s'", + FloppyDriveType_lookup[drv->drive]); } parse = &(fd_formats[match]); diff --git a/hw/i386/kvm/pci-assign.c b/hw/i386/kvm/pci-assign.c index 8238fbc..e27f307 100644 --- a/hw/i386/kvm/pci-assign.c +++ b/hw/i386/kvm/pci-assign.c @@ -465,8 +465,8 @@ static void assigned_dev_register_regions(PCIRegion *io_regions, * so should return EINVAL for a 3 byte read */ ret = pread(pci_dev->v_addrs[i].region->resource_fd, &val, 3, 0); if (ret >= 0) { - error_report("Unexpected return from I/O port read: %d", ret); - abort(); + error_report_abort("Unexpected return from I/O port read: %d", + ret); } else if (errno != EINVAL) { error_report("Kernel doesn't support ioport resource " "access, hiding this region."); diff --git a/hw/intc/xics.c b/hw/intc/xics.c index cd48f42..86e5ddc8 100644 --- a/hw/intc/xics.c +++ b/hw/intc/xics.c @@ -84,9 +84,8 @@ void xics_cpu_setup(XICSState *xics, PowerPCCPU *cpu) break; default: - error_report("XICS interrupt controller does not support this CPU " - "bus model"); - abort(); + error_report_abort("XICS interrupt controller does not support " + "this CPU bus model"); } } diff --git a/hw/pci/pci.c b/hw/pci/pci.c index 0642def..f54b43c 100644 --- a/hw/pci/pci.c +++ b/hw/pci/pci.c @@ -2606,8 +2606,7 @@ MSIMessage pci_get_msi_message(PCIDevice *dev, int vector) msg = msi_get_message(dev, vector); } else { /* Should never happen */ - error_report("%s: unknown interrupt type", __func__); - abort(); + error_report_abort("%s: unknown interrupt type", __func__); } return msg; } diff --git a/hw/ppc/spapr_drc.c b/hw/ppc/spapr_drc.c index 26a0679..8d59a8d 100644 --- a/hw/ppc/spapr_drc.c +++ b/hw/ppc/spapr_drc.c @@ -327,7 +327,7 @@ static void prop_get_fdt(Object *obj, Visitor *v, const char *name, break; } default: - error_setg(&error_abort, "device FDT in unexpected state: %d", tag); + error_report_abort("device FDT in unexpected state: %d", tag); } fdt_offset = fdt_offset_next; } while (fdt_depth != 0); diff --git a/hw/vfio/platform.c b/hw/vfio/platform.c index a559e7b..1190c92 100644 --- a/hw/vfio/platform.c +++ b/hw/vfio/platform.c @@ -339,9 +339,8 @@ static void vfio_start_eventfd_injection(SysBusDevice *sbdev, qemu_irq irq) ret = vfio_set_trigger_eventfd(intp, vfio_intp_interrupt); if (ret) { - error_report("vfio: failed to start eventfd signaling for IRQ %d: %m", - intp->pin); - abort(); + error_report_abort("vfio: failed to start eventfd signaling " + "for IRQ %d: %m", intp->pin); } } @@ -431,9 +430,8 @@ static void vfio_start_irqfd_injection(SysBusDevice *sbdev, qemu_irq irq) return; fail_vfio: kvm_irqchip_remove_irqfd_notifier(kvm_state, intp->interrupt, irq); - error_report("vfio: failed to start eventfd signaling for IRQ %d: %m", - intp->pin); - abort(); + error_report_abort("vfio: failed to start eventfd signaling for IRQ %d: %m", + intp->pin); fail_irqfd: vfio_start_eventfd_injection(sbdev, irq); return; diff --git a/net/netmap.c b/net/netmap.c index 2d11a8f..53ef57e 100644 --- a/net/netmap.c +++ b/net/netmap.c @@ -352,9 +352,8 @@ static bool netmap_has_vnet_hdr_len(NetClientState *nc, int len) /* Restore the previous length. */ if (netmap_fd_set_vnet_hdr_len(s, prev_len)) { - error_report("Failed to restore vnet-hdr length %d on %s: %s", - prev_len, s->ifname, strerror(errno)); - abort(); + error_report_abort("Failed to restore vnet-hdr length %d on %s: %s", + prev_len, s->ifname, strerror(errno)); } return true; diff --git a/net/tap-linux.c b/net/tap-linux.c index a503fa9..f7a6808 100644 --- a/net/tap-linux.c +++ b/net/tap-linux.c @@ -213,8 +213,9 @@ int tap_fd_set_vnet_le(int fd, int is_le) return -errno; } - error_report("TUNSETVNETLE ioctl() failed: %s.", strerror(errno)); - abort(); + error_report_abort("TUNSETVNETLE ioctl() failed: %s.", strerror(errno)); + /* Not reach here. */ + return -1; } int tap_fd_set_vnet_be(int fd, int is_be) @@ -230,8 +231,9 @@ int tap_fd_set_vnet_be(int fd, int is_be) return -errno; } - error_report("TUNSETVNETBE ioctl() failed: %s.", strerror(errno)); - abort(); + error_report_abort("TUNSETVNETBE ioctl() failed: %s.", strerror(errno)); + /* Not reach here. */ + return -1; } void tap_fd_set_offload(int fd, int csum, int tso4, diff --git a/scripts/coccinelle/error_report_abort.cocci b/scripts/coccinelle/error_report_abort.cocci new file mode 100644 index 0000000..cd95fa5 --- /dev/null +++ b/scripts/coccinelle/error_report_abort.cocci @@ -0,0 +1,14 @@ +@@ +expression list X; +@@ + +-error_report(X); +-abort(); ++error_report_abort(X); + +@@ +expression list X; +@@ + +-error_setg(&error_abort, X); ++error_report_abort(X); diff --git a/target-ppc/translate_init.c b/target-ppc/translate_init.c index 7a9b15e..4007bb6 100644 --- a/target-ppc/translate_init.c +++ b/target-ppc/translate_init.c @@ -8446,8 +8446,7 @@ static void powerpc_get_compat(Object *obj, Visitor *v, const char *name, case 0: break; default: - error_report("Internal error: compat is set to %x", *max_compat); - abort(); + error_report_abort("Internal error: compat is set to %x", *max_compat); break; } diff --git a/vl.c b/vl.c index 6939b99..cd10a3b 100644 --- a/vl.c +++ b/vl.c @@ -676,10 +676,9 @@ void runstate_set(RunState new_state) } if (!runstate_valid_transitions[current_run_state][new_state]) { - error_report("invalid runstate transition: '%s' -> '%s'", - RunState_lookup[current_run_state], - RunState_lookup[new_state]); - abort(); + error_report_abort("invalid runstate transition: '%s' -> '%s'", + RunState_lookup[current_run_state], + RunState_lookup[new_state]); } trace_runstate_set(new_state); current_run_state = new_state;