diff mbox

[v4,4/4] error-report: leverage error_report_abort()

Message ID 1473228390-18669-5-git-send-email-peterx@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Peter Xu Sept. 7, 2016, 6:06 a.m. UTC
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 <peterx@redhat.com>
---
 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 mbox

Patch

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;