All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH 00/19] usb: convert device init to realize
@ 2014-09-18  9:32 arei.gonglei
  2014-09-18  9:32 ` [Qemu-devel] [PATCH 01/19] usb-storage: fix possible memory leak and missing error message arei.gonglei
                   ` (18 more replies)
  0 siblings, 19 replies; 43+ messages in thread
From: arei.gonglei @ 2014-09-18  9:32 UTC (permalink / raw)
  To: qemu-devel
  Cc: weidong.huang, luonengjun, peter.huangpeng, armbru, Gonglei,
	kraxel, pbonzini

From: Gonglei <arei.gonglei@huawei.com>

DeviceClass->init is the old interface, let's convert usb
devices to the new realize API. In this way, all the
implementations now use error_setg instead of 
qerror_report/error_report for reporting error.

Please review, Thanks!

Cc: Markus Armbruster <armbru@redhat.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Gerd Hoffmann <kraxel@redhat.com>

Gonglei (19):
  usb-storage: fix possible memory leak and missing error message
  usb-bus: convert USBDeviceClass init to realize
  usb-net: convert init to realize
  libusb: convert init to realize
  libusb: using error_report instead of fprintf
  usb-hub: convert init to realize
  dev-storage: convert init to realize
  dev-storage: usring error_report instead of fprintf/printf
  dev-uas: convert init to realize
  dev-uas: using error_report instead of fprintf
  dev-bluetooth: convert init to realize
  dev-serial: convert init to realize
  usb-ccid: convert init to realize
  dev-hid: convert init to realize
  dev-wacom: convert init to realize
  usb-audio: convert init to realize
  usb-redir: convert init to realize
  usb-mtp: convert init to realize
  usb-bus: remove "init" from USBDeviceClass struct

 hw/usb/bus.c                  | 79 ++++++++++++++++++++++---------------------
 hw/usb/dev-audio.c            |  5 ++-
 hw/usb/dev-bluetooth.c        |  6 ++--
 hw/usb/dev-hid.c              | 23 ++++++-------
 hw/usb/dev-hub.c              |  9 +++--
 hw/usb/dev-mtp.c              |  5 ++-
 hw/usb/dev-network.c          |  9 +++--
 hw/usb/dev-serial.c           | 15 ++++----
 hw/usb/dev-smartcard-reader.c |  5 ++-
 hw/usb/dev-storage.c          | 42 ++++++++++++-----------
 hw/usb/dev-uas.c              | 17 +++++-----
 hw/usb/dev-wacom.c            |  5 ++-
 hw/usb/host-libusb.c          | 33 +++++++++---------
 hw/usb/redirect.c             | 21 +++++++-----
 include/hw/usb.h              | 10 ++++--
 15 files changed, 142 insertions(+), 142 deletions(-)

-- 
1.7.12.4

^ permalink raw reply	[flat|nested] 43+ messages in thread

* [Qemu-devel] [PATCH 01/19] usb-storage: fix possible memory leak and missing error message
  2014-09-18  9:32 [Qemu-devel] [PATCH 00/19] usb: convert device init to realize arei.gonglei
@ 2014-09-18  9:32 ` arei.gonglei
  2014-09-18 10:17   ` Paolo Bonzini
  2014-09-18  9:32 ` [Qemu-devel] [PATCH 02/19] usb-bus: convert USBDeviceClass init to realize arei.gonglei
                   ` (17 subsequent siblings)
  18 siblings, 1 reply; 43+ messages in thread
From: arei.gonglei @ 2014-09-18  9:32 UTC (permalink / raw)
  To: qemu-devel
  Cc: weidong.huang, luonengjun, peter.huangpeng, armbru, Gonglei,
	kraxel, pbonzini

From: Gonglei <arei.gonglei@huawei.com>

When scsi_bus_legacy_add_drive() return NULL, meanwhile err will
be not NULL, which will casue memory leak and missing error message.

Cc: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Gonglei <arei.gonglei@huawei.com>
---
 hw/usb/dev-storage.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/hw/usb/dev-storage.c b/hw/usb/dev-storage.c
index ae4efcb..f731b0a 100644
--- a/hw/usb/dev-storage.c
+++ b/hw/usb/dev-storage.c
@@ -624,6 +624,8 @@ static int usb_msd_initfn_storage(USBDevice *dev)
                                          s->conf.bootindex, dev->serial,
                                          &err);
     if (!scsi_dev) {
+        error_report("%s", error_get_pretty(err));
+        error_free(err);
         return -1;
     }
     s->bus.qbus.allow_hotplug = 0;
-- 
1.7.12.4

^ permalink raw reply related	[flat|nested] 43+ messages in thread

* [Qemu-devel] [PATCH 02/19] usb-bus: convert USBDeviceClass init to realize
  2014-09-18  9:32 [Qemu-devel] [PATCH 00/19] usb: convert device init to realize arei.gonglei
  2014-09-18  9:32 ` [Qemu-devel] [PATCH 01/19] usb-storage: fix possible memory leak and missing error message arei.gonglei
@ 2014-09-18  9:32 ` arei.gonglei
  2014-09-18 10:08   ` Paolo Bonzini
  2014-09-18 10:09   ` Paolo Bonzini
  2014-09-18  9:32 ` [Qemu-devel] [PATCH 03/19] usb-net: convert " arei.gonglei
                   ` (16 subsequent siblings)
  18 siblings, 2 replies; 43+ messages in thread
From: arei.gonglei @ 2014-09-18  9:32 UTC (permalink / raw)
  To: qemu-devel
  Cc: weidong.huang, luonengjun, peter.huangpeng, armbru, Gonglei,
	kraxel, pbonzini

From: Gonglei <arei.gonglei@huawei.com>

Add "realize/unrealize" in USBDeviceClass, which has errp
as a parameter. So all the implementations now use
error_setg instead of error_report for reporting error.

Note: this patch still keep "init" in USBDeviceClass, and
call kclass->init in usb_device_realize(), avoid breaking
git bisect. After realize all usb devices, will be removed.

Signed-off-by: Gonglei <arei.gonglei@huawei.com>
---
 hw/usb/bus.c         | 81 +++++++++++++++++++++++++++-------------------------
 hw/usb/dev-serial.c  |  4 +--
 hw/usb/dev-storage.c | 11 +++++--
 hw/usb/host-libusb.c |  7 +++--
 hw/usb/redirect.c    |  6 +++-
 include/hw/usb.h     | 10 +++++--
 6 files changed, 70 insertions(+), 49 deletions(-)

diff --git a/hw/usb/bus.c b/hw/usb/bus.c
index c7c4dad..12881cb 100644
--- a/hw/usb/bus.c
+++ b/hw/usb/bus.c
@@ -9,7 +9,7 @@ static void usb_bus_dev_print(Monitor *mon, DeviceState *qdev, int indent);
 
 static char *usb_get_dev_path(DeviceState *dev);
 static char *usb_get_fw_dev_path(DeviceState *qdev);
-static int usb_qdev_exit(DeviceState *qdev);
+static void usb_qdev_unrealize(DeviceState *qdev, Error **errp);
 
 static Property usb_props[] = {
     DEFINE_PROP_STRING("port", USBDevice, port_path),
@@ -107,13 +107,15 @@ USBBus *usb_bus_find(int busnr)
     return NULL;
 }
 
-static int usb_device_init(USBDevice *dev)
+static void usb_device_realize(USBDevice *dev, Error **errp)
 {
     USBDeviceClass *klass = USB_DEVICE_GET_CLASS(dev);
-    if (klass->init) {
-        return klass->init(dev);
+
+    if (klass->realize) {
+        klass->realize(dev, errp);
+    } else if (klass->init) {
+        klass->init(dev);
     }
-    return 0;
 }
 
 USBDevice *usb_device_find_device(USBDevice *dev, uint8_t addr)
@@ -232,36 +234,41 @@ void usb_device_free_streams(USBDevice *dev, USBEndpoint **eps, int nr_eps)
     }
 }
 
-static int usb_qdev_init(DeviceState *qdev)
+static void usb_qdev_realize(DeviceState *qdev, Error **errp)
 {
     USBDevice *dev = USB_DEVICE(qdev);
-    int rc;
+    Error *local_err = NULL;
 
     pstrcpy(dev->product_desc, sizeof(dev->product_desc),
             usb_device_get_product_desc(dev));
     dev->auto_attach = 1;
     QLIST_INIT(&dev->strings);
     usb_ep_init(dev);
-    rc = usb_claim_port(dev);
-    if (rc != 0) {
-        return rc;
+
+    usb_claim_port(dev, &local_err);
+    if (local_err) {
+        error_propagate(errp, local_err);
+        return;
     }
-    rc = usb_device_init(dev);
-    if (rc != 0) {
+
+    usb_device_realize(dev, &local_err);
+    if (local_err) {
         usb_release_port(dev);
-        return rc;
+        error_propagate(errp, local_err);
+        return;
     }
+
     if (dev->auto_attach) {
-        rc = usb_device_attach(dev);
-        if (rc != 0) {
-            usb_qdev_exit(qdev);
-            return rc;
+        usb_device_attach(dev, &local_err);
+        if (local_err) {
+            usb_qdev_unrealize(qdev, NULL);
+            error_propagate(errp, local_err);
+            return;
         }
     }
-    return 0;
 }
 
-static int usb_qdev_exit(DeviceState *qdev)
+static void usb_qdev_unrealize(DeviceState *qdev, Error **errp)
 {
     USBDevice *dev = USB_DEVICE(qdev);
 
@@ -272,7 +279,6 @@ static int usb_qdev_exit(DeviceState *qdev)
     if (dev->port) {
         usb_release_port(dev);
     }
-    return 0;
 }
 
 typedef struct LegacyUSBFactory
@@ -392,7 +398,7 @@ void usb_unregister_port(USBBus *bus, USBPort *port)
     bus->nfree--;
 }
 
-int usb_claim_port(USBDevice *dev)
+void usb_claim_port(USBDevice *dev, Error **errp)
 {
     USBBus *bus = usb_bus_from_device(dev);
     USBPort *port;
@@ -406,9 +412,9 @@ int usb_claim_port(USBDevice *dev)
             }
         }
         if (port == NULL) {
-            error_report("Error: usb port %s (bus %s) not found (in use?)",
-                         dev->port_path, bus->qbus.name);
-            return -1;
+            error_setg(errp, "Error: usb port %s (bus %s) not found (in use?)",
+                       dev->port_path, bus->qbus.name);
+            return;
         }
     } else {
         if (bus->nfree == 1 && strcmp(object_get_typename(OBJECT(dev)), "usb-hub") != 0) {
@@ -416,9 +422,9 @@ int usb_claim_port(USBDevice *dev)
             usb_create_simple(bus, "usb-hub");
         }
         if (bus->nfree == 0) {
-            error_report("Error: tried to attach usb device %s to a bus "
-                         "with no free ports", dev->product_desc);
-            return -1;
+            error_setg(errp, "Error: tried to attach usb device %s to a bus "
+                       "with no free ports", dev->product_desc);
+            return;
         }
         port = QTAILQ_FIRST(&bus->free);
     }
@@ -432,7 +438,6 @@ int usb_claim_port(USBDevice *dev)
 
     QTAILQ_INSERT_TAIL(&bus->used, port, next);
     bus->nused++;
-    return 0;
 }
 
 void usb_release_port(USBDevice *dev)
@@ -475,7 +480,7 @@ static void usb_mask_to_str(char *dest, size_t size,
     }
 }
 
-int usb_device_attach(USBDevice *dev)
+void usb_device_attach(USBDevice *dev, Error **errp)
 {
     USBBus *bus = usb_bus_from_device(dev);
     USBPort *port = dev->port;
@@ -489,18 +494,16 @@ int usb_device_attach(USBDevice *dev)
                           devspeed, portspeed);
 
     if (!(port->speedmask & dev->speedmask)) {
-        error_report("Warning: speed mismatch trying to attach"
-                     " usb device \"%s\" (%s speed)"
-                     " to bus \"%s\", port \"%s\" (%s speed)",
-                     dev->product_desc, devspeed,
-                     bus->qbus.name, port->path, portspeed);
-        return -1;
+        error_setg(errp, "Warning: speed mismatch trying to attach"
+                   " usb device \"%s\" (%s speed)"
+                   " to bus \"%s\", port \"%s\" (%s speed)",
+                   dev->product_desc, devspeed,
+                   bus->qbus.name, port->path, portspeed);
+        return;
     }
 
     dev->attached++;
     usb_attach(port);
-
-    return 0;
 }
 
 int usb_device_detach(USBDevice *dev)
@@ -688,9 +691,9 @@ static void usb_device_class_init(ObjectClass *klass, void *data)
 {
     DeviceClass *k = DEVICE_CLASS(klass);
     k->bus_type = TYPE_USB_BUS;
-    k->init     = usb_qdev_init;
     k->unplug   = qdev_simple_unplug_cb;
-    k->exit     = usb_qdev_exit;
+    k->realize  = usb_qdev_realize;
+    k->unrealize = usb_qdev_unrealize;
     k->props    = usb_props;
 }
 
diff --git a/hw/usb/dev-serial.c b/hw/usb/dev-serial.c
index d360614..178ecb2 100644
--- a/hw/usb/dev-serial.c
+++ b/hw/usb/dev-serial.c
@@ -460,7 +460,7 @@ static void usb_serial_event(void *opaque, int event)
             break;
         case CHR_EVENT_OPENED:
             if (!s->dev.attached) {
-                usb_device_attach(&s->dev);
+                usb_device_attach(&s->dev, NULL);
             }
             break;
         case CHR_EVENT_CLOSED:
@@ -489,7 +489,7 @@ static int usb_serial_initfn(USBDevice *dev)
     usb_serial_handle_reset(dev);
 
     if (s->cs->be_open && !dev->attached) {
-        usb_device_attach(dev);
+        usb_device_attach(dev, NULL);
     }
     return 0;
 }
diff --git a/hw/usb/dev-storage.c b/hw/usb/dev-storage.c
index f731b0a..a9f31f0 100644
--- a/hw/usb/dev-storage.c
+++ b/hw/usb/dev-storage.c
@@ -549,12 +549,17 @@ static void usb_msd_handle_data(USBDevice *dev, USBPacket *p)
 static void usb_msd_password_cb(void *opaque, int err)
 {
     MSDState *s = opaque;
+    Error *local_err = NULL;
 
-    if (!err)
-        err = usb_device_attach(&s->dev);
+    if (!err) {
+        usb_device_attach(&s->dev, &local_err);
+    }
 
-    if (err)
+    if (local_err) {
+        error_report("%s", error_get_pretty(local_err));
+        error_free(local_err);
         qdev_unplug(&s->dev.qdev, NULL);
+    }
 }
 
 static void *usb_msd_load_request(QEMUFile *f, SCSIRequest *req)
diff --git a/hw/usb/host-libusb.c b/hw/usb/host-libusb.c
index c189147..9f92705 100644
--- a/hw/usb/host-libusb.c
+++ b/hw/usb/host-libusb.c
@@ -834,6 +834,7 @@ static int usb_host_open(USBHostDevice *s, libusb_device *dev)
     int bus_num = libusb_get_bus_number(dev);
     int addr    = libusb_get_device_address(dev);
     int rc;
+    Error *local_err = NULL;
 
     trace_usb_host_open_started(bus_num, addr);
 
@@ -869,8 +870,10 @@ static int usb_host_open(USBHostDevice *s, libusb_device *dev)
                  "host:%d.%d", bus_num, addr);
     }
 
-    rc = usb_device_attach(udev);
-    if (rc) {
+    usb_device_attach(udev, &local_err);
+    if (local_err) {
+        error_report("%s", error_get_pretty(local_err));
+        error_free(local_err);
         goto fail;
     }
 
diff --git a/hw/usb/redirect.c b/hw/usb/redirect.c
index 44522d9..95158b3 100644
--- a/hw/usb/redirect.c
+++ b/hw/usb/redirect.c
@@ -1256,6 +1256,7 @@ static void usbredir_device_reject_bh(void *opaque)
 static void usbredir_do_attach(void *opaque)
 {
     USBRedirDevice *dev = opaque;
+    Error *local_err = NULL;
 
     /* In order to work properly with XHCI controllers we need these caps */
     if ((dev->dev.port->speedmask & USB_SPEED_MASK_SUPER) && !(
@@ -1270,7 +1271,10 @@ static void usbredir_do_attach(void *opaque)
         return;
     }
 
-    if (usb_device_attach(&dev->dev) != 0) {
+    usb_device_attach(&dev->dev, &local_err);
+    if (local_err) {
+        error_report("%s", error_get_pretty(local_err));
+        error_free(local_err);
         WARNING("rejecting device due to speed mismatch\n");
         usbredir_reject_device(dev);
     }
diff --git a/include/hw/usb.h b/include/hw/usb.h
index 6b32a3b..612f09f 100644
--- a/include/hw/usb.h
+++ b/include/hw/usb.h
@@ -267,11 +267,17 @@ struct USBDevice {
 #define USB_DEVICE_GET_CLASS(obj) \
      OBJECT_GET_CLASS(USBDeviceClass, (obj), TYPE_USB_DEVICE)
 
+typedef void (*USBDeviceRealize)(USBDevice *dev, Error **errp);
+typedef void (*USBDeviceUnrealize)(USBDevice *dev, Error **errp);
+
 typedef struct USBDeviceClass {
     DeviceClass parent_class;
 
     int (*init)(USBDevice *dev);
 
+    USBDeviceRealize realize;
+    USBDeviceUnrealize unrealize;
+
     /*
      * Walk (enabled) downstream ports, check for a matching device.
      * Only hubs implement this.
@@ -544,9 +550,9 @@ int usb_register_companion(const char *masterbus, USBPort *ports[],
                            void *opaque, USBPortOps *ops, int speedmask);
 void usb_port_location(USBPort *downstream, USBPort *upstream, int portnr);
 void usb_unregister_port(USBBus *bus, USBPort *port);
-int usb_claim_port(USBDevice *dev);
+void usb_claim_port(USBDevice *dev, Error **errp);
 void usb_release_port(USBDevice *dev);
-int usb_device_attach(USBDevice *dev);
+void usb_device_attach(USBDevice *dev, Error **errp);
 int usb_device_detach(USBDevice *dev);
 int usb_device_delete_addr(int busnr, int addr);
 
-- 
1.7.12.4

^ permalink raw reply related	[flat|nested] 43+ messages in thread

* [Qemu-devel] [PATCH 03/19] usb-net: convert init to realize
  2014-09-18  9:32 [Qemu-devel] [PATCH 00/19] usb: convert device init to realize arei.gonglei
  2014-09-18  9:32 ` [Qemu-devel] [PATCH 01/19] usb-storage: fix possible memory leak and missing error message arei.gonglei
  2014-09-18  9:32 ` [Qemu-devel] [PATCH 02/19] usb-bus: convert USBDeviceClass init to realize arei.gonglei
@ 2014-09-18  9:32 ` arei.gonglei
  2014-09-18 10:17   ` Paolo Bonzini
  2014-09-18  9:32 ` [Qemu-devel] [PATCH 04/19] libusb: " arei.gonglei
                   ` (15 subsequent siblings)
  18 siblings, 1 reply; 43+ messages in thread
From: arei.gonglei @ 2014-09-18  9:32 UTC (permalink / raw)
  To: qemu-devel
  Cc: weidong.huang, luonengjun, peter.huangpeng, armbru, Gonglei,
	kraxel, pbonzini

From: Gonglei <arei.gonglei@huawei.com>

meanwhile, qerror_report_err() is a transitional interface to
help with converting existing HMP commands to QMP. It should
not be used elsewhere.

Signed-off-by: Gonglei <arei.gonglei@huawei.com>
---
 hw/usb/dev-network.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/hw/usb/dev-network.c b/hw/usb/dev-network.c
index 518d536..686bd69 100644
--- a/hw/usb/dev-network.c
+++ b/hw/usb/dev-network.c
@@ -27,7 +27,7 @@
 #include "hw/usb.h"
 #include "hw/usb/desc.h"
 #include "net/net.h"
-#include "qapi/qmp/qerror.h"
+#include "qemu/error-report.h"
 #include "qemu/queue.h"
 #include "qemu/config-file.h"
 #include "sysemu/sysemu.h"
@@ -1341,7 +1341,7 @@ static NetClientInfo net_usbnet_info = {
     .cleanup = usbnet_cleanup,
 };
 
-static int usb_net_initfn(USBDevice *dev)
+static void usb_net_realize(USBDevice *dev, Error **errrp)
 {
     USBNetState *s = DO_UPCAST(USBNetState, dev, dev);
 
@@ -1373,7 +1373,6 @@ static int usb_net_initfn(USBDevice *dev)
     usb_desc_set_string(dev, STRING_ETHADDR, s->usbstring_mac);
 
     add_boot_device_path(s->conf.bootindex, &dev->qdev, "/ethernet@0");
-    return 0;
 }
 
 static USBDevice *usb_net_init(USBBus *bus, const char *cmdline)
@@ -1392,7 +1391,7 @@ static USBDevice *usb_net_init(USBBus *bus, const char *cmdline)
 
     idx = net_client_init(opts, 0, &local_err);
     if (local_err) {
-        qerror_report_err(local_err);
+        error_report("%s", error_get_pretty(local_err));
         error_free(local_err);
         return NULL;
     }
@@ -1421,7 +1420,7 @@ static void usb_net_class_initfn(ObjectClass *klass, void *data)
     DeviceClass *dc = DEVICE_CLASS(klass);
     USBDeviceClass *uc = USB_DEVICE_CLASS(klass);
 
-    uc->init           = usb_net_initfn;
+    uc->realize           = usb_net_realize;
     uc->product_desc   = "QEMU USB Network Interface";
     uc->usb_desc       = &desc_net;
     uc->handle_reset   = usb_net_handle_reset;
-- 
1.7.12.4

^ permalink raw reply related	[flat|nested] 43+ messages in thread

* [Qemu-devel] [PATCH 04/19] libusb: convert init to realize
  2014-09-18  9:32 [Qemu-devel] [PATCH 00/19] usb: convert device init to realize arei.gonglei
                   ` (2 preceding siblings ...)
  2014-09-18  9:32 ` [Qemu-devel] [PATCH 03/19] usb-net: convert " arei.gonglei
@ 2014-09-18  9:32 ` arei.gonglei
  2014-09-18 10:11   ` Paolo Bonzini
  2014-09-18  9:32 ` [Qemu-devel] [PATCH 05/19] libusb: using error_report instead of fprintf arei.gonglei
                   ` (14 subsequent siblings)
  18 siblings, 1 reply; 43+ messages in thread
From: arei.gonglei @ 2014-09-18  9:32 UTC (permalink / raw)
  To: qemu-devel
  Cc: weidong.huang, luonengjun, peter.huangpeng, armbru, Gonglei,
	kraxel, pbonzini

From: Gonglei <arei.gonglei@huawei.com>

In this way, all the implementations now use
error_setg instead of error_report for reporting error.

Signed-off-by: Gonglei <arei.gonglei@huawei.com>
---
 hw/usb/host-libusb.c | 17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)

diff --git a/hw/usb/host-libusb.c b/hw/usb/host-libusb.c
index 9f92705..863be64 100644
--- a/hw/usb/host-libusb.c
+++ b/hw/usb/host-libusb.c
@@ -951,21 +951,21 @@ static void usb_host_exit_notifier(struct Notifier *n, void *data)
     }
 }
 
-static int usb_host_initfn(USBDevice *udev)
+static void usb_host_realize(USBDevice *udev, Error **errp)
 {
     USBHostDevice *s = USB_HOST_DEVICE(udev);
 
     if (s->match.vendor_id > 0xffff) {
-        error_report("vendorid out of range");
-        return -1;
+        error_setg(errp, "vendorid out of range");
+        return;
     }
     if (s->match.product_id > 0xffff) {
-        error_report("productid out of range");
-        return -1;
+        error_setg(errp, "productid out of range");
+        return;
     }
     if (s->match.addr > 127) {
-        error_report("hostaddr out of range");
-        return -1;
+        error_setg(errp, "hostaddr out of range");
+        return;
     }
 
     loglevel = s->loglevel;
@@ -980,7 +980,6 @@ static int usb_host_initfn(USBDevice *udev)
     QTAILQ_INSERT_TAIL(&hostdevs, s, next);
     add_boot_device_path(s->bootindex, &udev->qdev, NULL);
     usb_host_auto_check(NULL);
-    return 0;
 }
 
 static void usb_host_handle_destroy(USBDevice *udev)
@@ -1480,7 +1479,7 @@ static void usb_host_class_initfn(ObjectClass *klass, void *data)
     DeviceClass *dc = DEVICE_CLASS(klass);
     USBDeviceClass *uc = USB_DEVICE_CLASS(klass);
 
-    uc->init           = usb_host_initfn;
+    uc->realize           = usb_host_realize;
     uc->product_desc   = "USB Host Device";
     uc->cancel_packet  = usb_host_cancel_packet;
     uc->handle_data    = usb_host_handle_data;
-- 
1.7.12.4

^ permalink raw reply related	[flat|nested] 43+ messages in thread

* [Qemu-devel] [PATCH 05/19] libusb: using error_report instead of fprintf
  2014-09-18  9:32 [Qemu-devel] [PATCH 00/19] usb: convert device init to realize arei.gonglei
                   ` (3 preceding siblings ...)
  2014-09-18  9:32 ` [Qemu-devel] [PATCH 04/19] libusb: " arei.gonglei
@ 2014-09-18  9:32 ` arei.gonglei
  2014-09-18 10:12   ` Paolo Bonzini
  2014-09-18  9:32 ` [Qemu-devel] [PATCH 06/19] usb-hub: convert init to realize arei.gonglei
                   ` (13 subsequent siblings)
  18 siblings, 1 reply; 43+ messages in thread
From: arei.gonglei @ 2014-09-18  9:32 UTC (permalink / raw)
  To: qemu-devel
  Cc: weidong.huang, luonengjun, peter.huangpeng, armbru, Gonglei,
	kraxel, pbonzini

From: Gonglei <arei.gonglei@huawei.com>

Signed-off-by: Gonglei <arei.gonglei@huawei.com>
---
 hw/usb/host-libusb.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/hw/usb/host-libusb.c b/hw/usb/host-libusb.c
index 863be64..0650910 100644
--- a/hw/usb/host-libusb.c
+++ b/hw/usb/host-libusb.c
@@ -275,7 +275,7 @@ static void usb_host_libusb_error(const char *func, int rc)
     } else {
         errname = "?";
     }
-    fprintf(stderr, "%s: %d [%s]\n", func, rc, errname);
+    error_report("%s: %d [%s]", func, rc, errname);
 }
 
 /* ------------------------------------------------------------------------ */
@@ -1376,14 +1376,13 @@ static int usb_host_alloc_streams(USBDevice *udev, USBEndpoint **eps,
     if (rc < 0) {
         usb_host_libusb_error("libusb_alloc_streams", rc);
     } else if (rc != streams) {
-        fprintf(stderr,
-            "libusb_alloc_streams: got less streams then requested %d < %d\n",
-            rc, streams);
+        error_report("libusb_alloc_streams: got less streams "
+                     "then requested %d < %d", rc, streams);
     }
 
     return (rc == streams) ? 0 : -1;
 #else
-    fprintf(stderr, "libusb_alloc_streams: error not implemented\n");
+    error_report("libusb_alloc_streams: error not implemented");
     return -1;
 #endif
 }
-- 
1.7.12.4

^ permalink raw reply related	[flat|nested] 43+ messages in thread

* [Qemu-devel] [PATCH 06/19] usb-hub: convert init to realize
  2014-09-18  9:32 [Qemu-devel] [PATCH 00/19] usb: convert device init to realize arei.gonglei
                   ` (4 preceding siblings ...)
  2014-09-18  9:32 ` [Qemu-devel] [PATCH 05/19] libusb: using error_report instead of fprintf arei.gonglei
@ 2014-09-18  9:32 ` arei.gonglei
  2014-09-18 10:12   ` Paolo Bonzini
  2014-09-18  9:32 ` [Qemu-devel] [PATCH 07/19] dev-storage: " arei.gonglei
                   ` (12 subsequent siblings)
  18 siblings, 1 reply; 43+ messages in thread
From: arei.gonglei @ 2014-09-18  9:32 UTC (permalink / raw)
  To: qemu-devel
  Cc: weidong.huang, luonengjun, peter.huangpeng, armbru, Gonglei,
	kraxel, pbonzini

From: Gonglei <arei.gonglei@huawei.com>

In this way, all the implementations now use
error_setg instead of error_report for reporting error.

Signed-off-by: Gonglei <arei.gonglei@huawei.com>
---
 hw/usb/dev-hub.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/hw/usb/dev-hub.c b/hw/usb/dev-hub.c
index 7492174..8e3f7a8 100644
--- a/hw/usb/dev-hub.c
+++ b/hw/usb/dev-hub.c
@@ -511,15 +511,15 @@ static USBPortOps usb_hub_port_ops = {
     .complete = usb_hub_complete,
 };
 
-static int usb_hub_initfn(USBDevice *dev)
+static void usb_hub_realize(USBDevice *dev, Error **errp)
 {
     USBHubState *s = DO_UPCAST(USBHubState, dev, dev);
     USBHubPort *port;
     int i;
 
     if (dev->port->hubcount == 5) {
-        error_report("usb hub chain too deep");
-        return -1;
+        error_setg(errp, "usb hub chain too deep");
+        return;
     }
 
     usb_desc_create_serial(dev);
@@ -533,7 +533,6 @@ static int usb_hub_initfn(USBDevice *dev)
         usb_port_location(&port->port, dev->port, i+1);
     }
     usb_hub_handle_reset(dev);
-    return 0;
 }
 
 static const VMStateDescription vmstate_usb_hub_port = {
@@ -564,7 +563,7 @@ static void usb_hub_class_initfn(ObjectClass *klass, void *data)
     DeviceClass *dc = DEVICE_CLASS(klass);
     USBDeviceClass *uc = USB_DEVICE_CLASS(klass);
 
-    uc->init           = usb_hub_initfn;
+    uc->realize           = usb_hub_realize;
     uc->product_desc   = "QEMU USB Hub";
     uc->usb_desc       = &desc_hub;
     uc->find_device    = usb_hub_find_device;
-- 
1.7.12.4

^ permalink raw reply related	[flat|nested] 43+ messages in thread

* [Qemu-devel] [PATCH 07/19] dev-storage: convert init to realize
  2014-09-18  9:32 [Qemu-devel] [PATCH 00/19] usb: convert device init to realize arei.gonglei
                   ` (5 preceding siblings ...)
  2014-09-18  9:32 ` [Qemu-devel] [PATCH 06/19] usb-hub: convert init to realize arei.gonglei
@ 2014-09-18  9:32 ` arei.gonglei
  2014-09-18 10:13   ` Paolo Bonzini
  2014-09-18  9:32 ` [Qemu-devel] [PATCH 08/19] dev-storage: usring error_report instead of fprintf/printf arei.gonglei
                   ` (11 subsequent siblings)
  18 siblings, 1 reply; 43+ messages in thread
From: arei.gonglei @ 2014-09-18  9:32 UTC (permalink / raw)
  To: qemu-devel
  Cc: weidong.huang, luonengjun, peter.huangpeng, armbru, Gonglei,
	kraxel, pbonzini

From: Gonglei <arei.gonglei@huawei.com>

In this way, all the implementations now use
error_setg instead of error_report for reporting error.

Signed-off-by: Gonglei <arei.gonglei@huawei.com>
---
 hw/usb/dev-storage.c | 21 ++++++++-------------
 1 file changed, 8 insertions(+), 13 deletions(-)

diff --git a/hw/usb/dev-storage.c b/hw/usb/dev-storage.c
index a9f31f0..6dc5f47 100644
--- a/hw/usb/dev-storage.c
+++ b/hw/usb/dev-storage.c
@@ -595,7 +595,7 @@ static const struct SCSIBusInfo usb_msd_scsi_info_bot = {
     .load_request = usb_msd_load_request,
 };
 
-static int usb_msd_initfn_storage(USBDevice *dev)
+static void usb_msd_realize_storage(USBDevice *dev, Error **errp)
 {
     MSDState *s = DO_UPCAST(MSDState, dev, dev);
     BlockDriverState *bs = s->conf.bs;
@@ -603,8 +603,8 @@ static int usb_msd_initfn_storage(USBDevice *dev)
     Error *err = NULL;
 
     if (!bs) {
-        error_report("drive property not set");
-        return -1;
+        error_setg(errp, "drive property not set");
+        return;
     }
 
     blkconf_serial(&s->conf, &dev->serial);
@@ -629,9 +629,8 @@ static int usb_msd_initfn_storage(USBDevice *dev)
                                          s->conf.bootindex, dev->serial,
                                          &err);
     if (!scsi_dev) {
-        error_report("%s", error_get_pretty(err));
-        error_free(err);
-        return -1;
+        error_propagate(errp, err);
+        return;
     }
     s->bus.qbus.allow_hotplug = 0;
     usb_msd_handle_reset(dev);
@@ -644,11 +643,9 @@ static int usb_msd_initfn_storage(USBDevice *dev)
             autostart = 0;
         }
     }
-
-    return 0;
 }
 
-static int usb_msd_initfn_bot(USBDevice *dev)
+static void usb_msd_realize_bot(USBDevice *dev, Error **errp)
 {
     MSDState *s = DO_UPCAST(MSDState, dev, dev);
 
@@ -658,8 +655,6 @@ static int usb_msd_initfn_bot(USBDevice *dev)
                  &usb_msd_scsi_info_bot, NULL);
     s->bus.qbus.allow_hotplug = 0;
     usb_msd_handle_reset(dev);
-
-    return 0;
 }
 
 static USBDevice *usb_msd_init(USBBus *bus, const char *filename)
@@ -765,7 +760,7 @@ static void usb_msd_class_initfn_storage(ObjectClass *klass, void *data)
     DeviceClass *dc = DEVICE_CLASS(klass);
     USBDeviceClass *uc = USB_DEVICE_CLASS(klass);
 
-    uc->init = usb_msd_initfn_storage;
+    uc->realize = usb_msd_realize_storage;
     dc->props = msd_properties;
     usb_msd_class_initfn_common(klass);
 }
@@ -774,7 +769,7 @@ static void usb_msd_class_initfn_bot(ObjectClass *klass, void *data)
 {
     USBDeviceClass *uc = USB_DEVICE_CLASS(klass);
 
-    uc->init = usb_msd_initfn_bot;
+    uc->realize = usb_msd_realize_bot;
     usb_msd_class_initfn_common(klass);
 }
 
-- 
1.7.12.4

^ permalink raw reply related	[flat|nested] 43+ messages in thread

* [Qemu-devel] [PATCH 08/19] dev-storage: usring error_report instead of fprintf/printf
  2014-09-18  9:32 [Qemu-devel] [PATCH 00/19] usb: convert device init to realize arei.gonglei
                   ` (6 preceding siblings ...)
  2014-09-18  9:32 ` [Qemu-devel] [PATCH 07/19] dev-storage: " arei.gonglei
@ 2014-09-18  9:32 ` arei.gonglei
  2014-09-18 10:13   ` Paolo Bonzini
  2014-09-18  9:32 ` [Qemu-devel] [PATCH 09/19] dev-uas: convert init to realize arei.gonglei
                   ` (10 subsequent siblings)
  18 siblings, 1 reply; 43+ messages in thread
From: arei.gonglei @ 2014-09-18  9:32 UTC (permalink / raw)
  To: qemu-devel
  Cc: weidong.huang, luonengjun, peter.huangpeng, armbru, Gonglei,
	kraxel, pbonzini

From: Gonglei <arei.gonglei@huawei.com>

Signed-off-by: Gonglei <arei.gonglei@huawei.com>
---
 hw/usb/dev-storage.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/hw/usb/dev-storage.c b/hw/usb/dev-storage.c
index 6dc5f47..681959d 100644
--- a/hw/usb/dev-storage.c
+++ b/hw/usb/dev-storage.c
@@ -409,19 +409,19 @@ static void usb_msd_handle_data(USBDevice *dev, USBPacket *p)
         switch (s->mode) {
         case USB_MSDM_CBW:
             if (p->iov.size != 31) {
-                fprintf(stderr, "usb-msd: Bad CBW size");
+                error_report("usb-msd: Bad CBW size");
                 goto fail;
             }
             usb_packet_copy(p, &cbw, 31);
             if (le32_to_cpu(cbw.sig) != 0x43425355) {
-                fprintf(stderr, "usb-msd: Bad signature %08x\n",
-                        le32_to_cpu(cbw.sig));
+                error_report("usb-msd: Bad signature %08x",
+                             le32_to_cpu(cbw.sig));
                 goto fail;
             }
             DPRINTF("Command on LUN %d\n", cbw.lun);
             scsi_dev = scsi_device_find(&s->bus, 0, 0, cbw.lun);
             if (scsi_dev == NULL) {
-                fprintf(stderr, "usb-msd: Bad LUN %d\n", cbw.lun);
+                error_report("usb-msd: Bad LUN %d", cbw.lun);
                 goto fail;
             }
             tag = le32_to_cpu(cbw.tag);
@@ -680,13 +680,13 @@ static USBDevice *usb_msd_init(USBBus *bus, const char *filename)
             pstrcpy(fmt, len, p2);
             qemu_opt_set(opts, "format", fmt);
         } else if (*filename != ':') {
-            printf("unrecognized USB mass-storage option %s\n", filename);
+            error_report("unrecognized USB mass-storage option %s", filename);
             return NULL;
         }
         filename = p1;
     }
     if (!*filename) {
-        printf("block device specification needed\n");
+        error_report("block device specification needed");
         return NULL;
     }
     qemu_opt_set(opts, "file", filename);
-- 
1.7.12.4

^ permalink raw reply related	[flat|nested] 43+ messages in thread

* [Qemu-devel] [PATCH 09/19] dev-uas: convert init to realize
  2014-09-18  9:32 [Qemu-devel] [PATCH 00/19] usb: convert device init to realize arei.gonglei
                   ` (7 preceding siblings ...)
  2014-09-18  9:32 ` [Qemu-devel] [PATCH 08/19] dev-storage: usring error_report instead of fprintf/printf arei.gonglei
@ 2014-09-18  9:32 ` arei.gonglei
  2014-09-18 10:13   ` Paolo Bonzini
  2014-09-18  9:32 ` [Qemu-devel] [PATCH 10/19] dev-uas: using error_report instead of fprintf arei.gonglei
                   ` (9 subsequent siblings)
  18 siblings, 1 reply; 43+ messages in thread
From: arei.gonglei @ 2014-09-18  9:32 UTC (permalink / raw)
  To: qemu-devel
  Cc: weidong.huang, luonengjun, peter.huangpeng, armbru, Gonglei,
	kraxel, pbonzini

From: Gonglei <arei.gonglei@huawei.com>

Signed-off-by: Gonglei <arei.gonglei@huawei.com>
---
 hw/usb/dev-uas.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/hw/usb/dev-uas.c b/hw/usb/dev-uas.c
index 9832385..884c003 100644
--- a/hw/usb/dev-uas.c
+++ b/hw/usb/dev-uas.c
@@ -892,7 +892,7 @@ static void usb_uas_handle_destroy(USBDevice *dev)
     qemu_bh_delete(uas->status_bh);
 }
 
-static int usb_uas_init(USBDevice *dev)
+static void usb_uas_realize(USBDevice *dev, Error **errp)
 {
     UASDevice *uas = DO_UPCAST(UASDevice, dev, dev);
 
@@ -905,8 +905,6 @@ static int usb_uas_init(USBDevice *dev)
 
     scsi_bus_new(&uas->bus, sizeof(uas->bus), DEVICE(dev),
                  &usb_uas_scsi_info, NULL);
-
-    return 0;
 }
 
 static const VMStateDescription vmstate_usb_uas = {
@@ -928,7 +926,7 @@ static void usb_uas_class_initfn(ObjectClass *klass, void *data)
     DeviceClass *dc = DEVICE_CLASS(klass);
     USBDeviceClass *uc = USB_DEVICE_CLASS(klass);
 
-    uc->init           = usb_uas_init;
+    uc->realize           = usb_uas_realize;
     uc->product_desc   = desc_strings[STR_PRODUCT];
     uc->usb_desc       = &desc;
     uc->cancel_packet  = usb_uas_cancel_io;
-- 
1.7.12.4

^ permalink raw reply related	[flat|nested] 43+ messages in thread

* [Qemu-devel] [PATCH 10/19] dev-uas: using error_report instead of fprintf
  2014-09-18  9:32 [Qemu-devel] [PATCH 00/19] usb: convert device init to realize arei.gonglei
                   ` (8 preceding siblings ...)
  2014-09-18  9:32 ` [Qemu-devel] [PATCH 09/19] dev-uas: convert init to realize arei.gonglei
@ 2014-09-18  9:32 ` arei.gonglei
  2014-09-18 10:14   ` Paolo Bonzini
  2014-09-18  9:32 ` [Qemu-devel] [PATCH 11/19] dev-bluetooth: convert init to realize arei.gonglei
                   ` (8 subsequent siblings)
  18 siblings, 1 reply; 43+ messages in thread
From: arei.gonglei @ 2014-09-18  9:32 UTC (permalink / raw)
  To: qemu-devel
  Cc: weidong.huang, luonengjun, peter.huangpeng, armbru, Gonglei,
	kraxel, pbonzini

From: Gonglei <arei.gonglei@huawei.com>

Signed-off-by: Gonglei <arei.gonglei@huawei.com>
---
 hw/usb/dev-uas.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/hw/usb/dev-uas.c b/hw/usb/dev-uas.c
index 884c003..1508064 100644
--- a/hw/usb/dev-uas.c
+++ b/hw/usb/dev-uas.c
@@ -13,6 +13,7 @@
 #include "qemu/option.h"
 #include "qemu/config-file.h"
 #include "trace.h"
+#include "qemu/error-report.h"
 
 #include "hw/usb.h"
 #include "hw/usb/desc.h"
@@ -648,7 +649,7 @@ static void usb_uas_handle_control(USBDevice *dev, USBPacket *p,
     if (ret >= 0) {
         return;
     }
-    fprintf(stderr, "%s: unhandled control request\n", __func__);
+    error_report("%s: unhandled control request", __func__);
     p->status = USB_RET_STALL;
 }
 
@@ -814,8 +815,8 @@ static void usb_uas_handle_data(USBDevice *dev, USBPacket *p)
             usb_uas_task(uas, &iu);
             break;
         default:
-            fprintf(stderr, "%s: unknown command iu: id 0x%x\n",
-                    __func__, iu.hdr.id);
+            error_report("%s: unknown command iu: id 0x%x",
+                         __func__, iu.hdr.id);
             p->status = USB_RET_STALL;
             break;
         }
@@ -861,7 +862,7 @@ static void usb_uas_handle_data(USBDevice *dev, USBPacket *p)
                 p->status = USB_RET_ASYNC;
                 break;
             } else {
-                fprintf(stderr, "%s: no inflight request\n", __func__);
+                error_report("%s: no inflight request", __func__);
                 p->status = USB_RET_STALL;
                 break;
             }
@@ -879,7 +880,7 @@ static void usb_uas_handle_data(USBDevice *dev, USBPacket *p)
         usb_uas_start_next_transfer(uas);
         break;
     default:
-        fprintf(stderr, "%s: invalid endpoint %d\n", __func__, p->ep->nr);
+        error_report("%s: invalid endpoint %d", __func__, p->ep->nr);
         p->status = USB_RET_STALL;
         break;
     }
-- 
1.7.12.4

^ permalink raw reply related	[flat|nested] 43+ messages in thread

* [Qemu-devel] [PATCH 11/19] dev-bluetooth: convert init to realize
  2014-09-18  9:32 [Qemu-devel] [PATCH 00/19] usb: convert device init to realize arei.gonglei
                   ` (9 preceding siblings ...)
  2014-09-18  9:32 ` [Qemu-devel] [PATCH 10/19] dev-uas: using error_report instead of fprintf arei.gonglei
@ 2014-09-18  9:32 ` arei.gonglei
  2014-09-18 10:14   ` Paolo Bonzini
  2014-09-18  9:32 ` [Qemu-devel] [PATCH 12/19] dev-serial: " arei.gonglei
                   ` (7 subsequent siblings)
  18 siblings, 1 reply; 43+ messages in thread
From: arei.gonglei @ 2014-09-18  9:32 UTC (permalink / raw)
  To: qemu-devel
  Cc: weidong.huang, luonengjun, peter.huangpeng, armbru, Gonglei,
	kraxel, pbonzini

From: Gonglei <arei.gonglei@huawei.com>

Signed-off-by: Gonglei <arei.gonglei@huawei.com>
---
 hw/usb/dev-bluetooth.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/hw/usb/dev-bluetooth.c b/hw/usb/dev-bluetooth.c
index a76e581..7db9921 100644
--- a/hw/usb/dev-bluetooth.c
+++ b/hw/usb/dev-bluetooth.c
@@ -501,7 +501,7 @@ static void usb_bt_handle_destroy(USBDevice *dev)
     s->hci->acl_recv = NULL;
 }
 
-static int usb_bt_initfn(USBDevice *dev)
+static void usb_bt_realize(USBDevice *dev, Error **errp)
 {
     struct USBBtState *s = DO_UPCAST(struct USBBtState, dev, dev);
 
@@ -516,8 +516,6 @@ static int usb_bt_initfn(USBDevice *dev)
     s->hci->acl_recv = usb_bt_out_hci_packet_acl;
     usb_bt_handle_reset(&s->dev);
     s->intr = usb_ep_get(dev, USB_TOKEN_IN, USB_EVT_EP);
-
-    return 0;
 }
 
 static USBDevice *usb_bt_init(USBBus *bus, const char *cmdline)
@@ -560,7 +558,7 @@ static void usb_bt_class_initfn(ObjectClass *klass, void *data)
     DeviceClass *dc = DEVICE_CLASS(klass);
     USBDeviceClass *uc = USB_DEVICE_CLASS(klass);
 
-    uc->init           = usb_bt_initfn;
+    uc->realize           = usb_bt_realize;
     uc->product_desc   = "QEMU BT dongle";
     uc->usb_desc       = &desc_bluetooth;
     uc->handle_reset   = usb_bt_handle_reset;
-- 
1.7.12.4

^ permalink raw reply related	[flat|nested] 43+ messages in thread

* [Qemu-devel] [PATCH 12/19] dev-serial: convert init to realize
  2014-09-18  9:32 [Qemu-devel] [PATCH 00/19] usb: convert device init to realize arei.gonglei
                   ` (10 preceding siblings ...)
  2014-09-18  9:32 ` [Qemu-devel] [PATCH 11/19] dev-bluetooth: convert init to realize arei.gonglei
@ 2014-09-18  9:32 ` arei.gonglei
  2014-09-18 10:14   ` Paolo Bonzini
  2014-09-18  9:32 ` [Qemu-devel] [PATCH 13/19] usb-ccid: " arei.gonglei
                   ` (6 subsequent siblings)
  18 siblings, 1 reply; 43+ messages in thread
From: arei.gonglei @ 2014-09-18  9:32 UTC (permalink / raw)
  To: qemu-devel
  Cc: weidong.huang, luonengjun, peter.huangpeng, armbru, Gonglei,
	kraxel, pbonzini

From: Gonglei <arei.gonglei@huawei.com>

In this way, all the implementations now use
error_setg instead of error_report for reporting error.

Signed-off-by: Gonglei <arei.gonglei@huawei.com>
---
 hw/usb/dev-serial.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/hw/usb/dev-serial.c b/hw/usb/dev-serial.c
index 178ecb2..3384db6 100644
--- a/hw/usb/dev-serial.c
+++ b/hw/usb/dev-serial.c
@@ -471,7 +471,7 @@ static void usb_serial_event(void *opaque, int event)
     }
 }
 
-static int usb_serial_initfn(USBDevice *dev)
+static void usb_serial_realize(USBDevice *dev, Error **errp)
 {
     USBSerialState *s = DO_UPCAST(USBSerialState, dev, dev);
 
@@ -480,8 +480,8 @@ static int usb_serial_initfn(USBDevice *dev)
     dev->auto_attach = 0;
 
     if (!s->cs) {
-        error_report("Property chardev is required");
-        return -1;
+        error_setg(errp, "Property chardev is required");
+        return;
     }
 
     qemu_chr_add_handlers(s->cs, usb_serial_can_read, usb_serial_read,
@@ -491,7 +491,6 @@ static int usb_serial_initfn(USBDevice *dev)
     if (s->cs->be_open && !dev->attached) {
         usb_device_attach(dev, NULL);
     }
-    return 0;
 }
 
 static USBDevice *usb_serial_init(USBBus *bus, const char *filename)
@@ -582,7 +581,7 @@ static void usb_serial_class_initfn(ObjectClass *klass, void *data)
     DeviceClass *dc = DEVICE_CLASS(klass);
     USBDeviceClass *uc = USB_DEVICE_CLASS(klass);
 
-    uc->init = usb_serial_initfn;
+    uc->realize = usb_serial_realize;
     uc->product_desc   = "QEMU USB Serial";
     uc->usb_desc       = &desc_serial;
     uc->handle_reset   = usb_serial_handle_reset;
@@ -610,7 +609,7 @@ static void usb_braille_class_initfn(ObjectClass *klass, void *data)
     DeviceClass *dc = DEVICE_CLASS(klass);
     USBDeviceClass *uc = USB_DEVICE_CLASS(klass);
 
-    uc->init           = usb_serial_initfn;
+    uc->realize           = usb_serial_realize;
     uc->product_desc   = "QEMU USB Braille";
     uc->usb_desc       = &desc_braille;
     uc->handle_reset   = usb_serial_handle_reset;
-- 
1.7.12.4

^ permalink raw reply related	[flat|nested] 43+ messages in thread

* [Qemu-devel] [PATCH 13/19] usb-ccid: convert init to realize
  2014-09-18  9:32 [Qemu-devel] [PATCH 00/19] usb: convert device init to realize arei.gonglei
                   ` (11 preceding siblings ...)
  2014-09-18  9:32 ` [Qemu-devel] [PATCH 12/19] dev-serial: " arei.gonglei
@ 2014-09-18  9:32 ` arei.gonglei
  2014-09-18 10:14   ` Paolo Bonzini
  2014-09-18  9:32 ` [Qemu-devel] [PATCH 14/19] dev-hid: " arei.gonglei
                   ` (5 subsequent siblings)
  18 siblings, 1 reply; 43+ messages in thread
From: arei.gonglei @ 2014-09-18  9:32 UTC (permalink / raw)
  To: qemu-devel
  Cc: weidong.huang, luonengjun, peter.huangpeng, armbru, Gonglei,
	kraxel, pbonzini

From: Gonglei <arei.gonglei@huawei.com>

Signed-off-by: Gonglei <arei.gonglei@huawei.com>
---
 hw/usb/dev-smartcard-reader.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/hw/usb/dev-smartcard-reader.c b/hw/usb/dev-smartcard-reader.c
index 470e69f..442f487 100644
--- a/hw/usb/dev-smartcard-reader.c
+++ b/hw/usb/dev-smartcard-reader.c
@@ -1304,7 +1304,7 @@ static int ccid_card_init(DeviceState *qdev)
     return ret;
 }
 
-static int ccid_initfn(USBDevice *dev)
+static void ccid_realize(USBDevice *dev, Error **errp)
 {
     USBCCIDState *s = DO_UPCAST(USBCCIDState, dev, dev);
 
@@ -1332,7 +1332,6 @@ static int ccid_initfn(USBDevice *dev)
     ccid_reset_parameters(s);
     ccid_reset(s);
     s->debug = parse_debug_env("QEMU_CCID_DEBUG", D_VERBOSE, s->debug);
-    return 0;
 }
 
 static int ccid_post_load(void *opaque, int version_id)
@@ -1441,7 +1440,7 @@ static void ccid_class_initfn(ObjectClass *klass, void *data)
     DeviceClass *dc = DEVICE_CLASS(klass);
     USBDeviceClass *uc = USB_DEVICE_CLASS(klass);
 
-    uc->init           = ccid_initfn;
+    uc->realize           = ccid_realize;
     uc->product_desc   = "QEMU USB CCID";
     uc->usb_desc       = &desc_ccid;
     uc->handle_reset   = ccid_handle_reset;
-- 
1.7.12.4

^ permalink raw reply related	[flat|nested] 43+ messages in thread

* [Qemu-devel] [PATCH 14/19] dev-hid: convert init to realize
  2014-09-18  9:32 [Qemu-devel] [PATCH 00/19] usb: convert device init to realize arei.gonglei
                   ` (12 preceding siblings ...)
  2014-09-18  9:32 ` [Qemu-devel] [PATCH 13/19] usb-ccid: " arei.gonglei
@ 2014-09-18  9:32 ` arei.gonglei
  2014-09-18 10:15   ` Paolo Bonzini
  2014-09-18  9:32 ` [Qemu-devel] [PATCH 15/19] dev-wacom: " arei.gonglei
                   ` (4 subsequent siblings)
  18 siblings, 1 reply; 43+ messages in thread
From: arei.gonglei @ 2014-09-18  9:32 UTC (permalink / raw)
  To: qemu-devel
  Cc: weidong.huang, luonengjun, peter.huangpeng, armbru, Gonglei,
	kraxel, pbonzini

From: Gonglei <arei.gonglei@huawei.com>

In this way, all the implementations now use
error_setg instead of error_report for reporting error.

Signed-off-by: Gonglei <arei.gonglei@huawei.com>
---
 hw/usb/dev-hid.c | 23 +++++++++++------------
 1 file changed, 11 insertions(+), 12 deletions(-)

diff --git a/hw/usb/dev-hid.c b/hw/usb/dev-hid.c
index 67a57f1..7e9d2d6 100644
--- a/hw/usb/dev-hid.c
+++ b/hw/usb/dev-hid.c
@@ -582,7 +582,7 @@ static int usb_hid_initfn(USBDevice *dev, int kind)
     return 0;
 }
 
-static int usb_tablet_initfn(USBDevice *dev)
+static void usb_tablet_realize(USBDevice *dev, Error **errp)
 {
     USBHIDState *us = DO_UPCAST(USBHIDState, dev, dev);
 
@@ -594,22 +594,21 @@ static int usb_tablet_initfn(USBDevice *dev)
         dev->usb_desc = &desc_tablet2;
         break;
     default:
-        error_report("Invalid usb version %d for usb-tabler (must be 1 or 2)",
-                     us->usb_version);
-        return -1;
+        error_setg(errp, "Invalid usb version %d for usb-tablet "
+                   "(must be 1 or 2)", us->usb_version);
     }
 
-    return usb_hid_initfn(dev, HID_TABLET);
+    usb_hid_initfn(dev, HID_TABLET);
 }
 
-static int usb_mouse_initfn(USBDevice *dev)
+static void usb_mouse_realize(USBDevice *dev, Error **errp)
 {
-    return usb_hid_initfn(dev, HID_MOUSE);
+    usb_hid_initfn(dev, HID_MOUSE);
 }
 
-static int usb_keyboard_initfn(USBDevice *dev)
+static void usb_keyboard_realize(USBDevice *dev, Error **errp)
 {
-    return usb_hid_initfn(dev, HID_KEYBOARD);
+    usb_hid_initfn(dev, HID_KEYBOARD);
 }
 
 static int usb_ptr_post_load(void *opaque, int version_id)
@@ -669,7 +668,7 @@ static void usb_tablet_class_initfn(ObjectClass *klass, void *data)
     USBDeviceClass *uc = USB_DEVICE_CLASS(klass);
 
     usb_hid_class_initfn(klass, data);
-    uc->init           = usb_tablet_initfn;
+    uc->realize           = usb_tablet_realize;
     uc->product_desc   = "QEMU USB Tablet";
     dc->vmsd = &vmstate_usb_ptr;
     dc->props = usb_tablet_properties;
@@ -689,7 +688,7 @@ static void usb_mouse_class_initfn(ObjectClass *klass, void *data)
     USBDeviceClass *uc = USB_DEVICE_CLASS(klass);
 
     usb_hid_class_initfn(klass, data);
-    uc->init           = usb_mouse_initfn;
+    uc->realize           = usb_mouse_realize;
     uc->product_desc   = "QEMU USB Mouse";
     uc->usb_desc       = &desc_mouse;
     dc->vmsd = &vmstate_usb_ptr;
@@ -714,7 +713,7 @@ static void usb_keyboard_class_initfn(ObjectClass *klass, void *data)
     USBDeviceClass *uc = USB_DEVICE_CLASS(klass);
 
     usb_hid_class_initfn(klass, data);
-    uc->init           = usb_keyboard_initfn;
+    uc->realize           = usb_keyboard_realize;
     uc->product_desc   = "QEMU USB Keyboard";
     uc->usb_desc       = &desc_keyboard;
     dc->vmsd = &vmstate_usb_kbd;
-- 
1.7.12.4

^ permalink raw reply related	[flat|nested] 43+ messages in thread

* [Qemu-devel] [PATCH 15/19] dev-wacom: convert init to realize
  2014-09-18  9:32 [Qemu-devel] [PATCH 00/19] usb: convert device init to realize arei.gonglei
                   ` (13 preceding siblings ...)
  2014-09-18  9:32 ` [Qemu-devel] [PATCH 14/19] dev-hid: " arei.gonglei
@ 2014-09-18  9:32 ` arei.gonglei
  2014-09-18 10:15   ` Paolo Bonzini
  2014-09-18  9:32 ` [Qemu-devel] [PATCH 16/19] usb-audio: " arei.gonglei
                   ` (3 subsequent siblings)
  18 siblings, 1 reply; 43+ messages in thread
From: arei.gonglei @ 2014-09-18  9:32 UTC (permalink / raw)
  To: qemu-devel
  Cc: weidong.huang, luonengjun, peter.huangpeng, armbru, Gonglei,
	kraxel, pbonzini

From: Gonglei <arei.gonglei@huawei.com>

Signed-off-by: Gonglei <arei.gonglei@huawei.com>
---
 hw/usb/dev-wacom.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/hw/usb/dev-wacom.c b/hw/usb/dev-wacom.c
index 1b73fd0..217d48e 100644
--- a/hw/usb/dev-wacom.c
+++ b/hw/usb/dev-wacom.c
@@ -335,14 +335,13 @@ static void usb_wacom_handle_destroy(USBDevice *dev)
     }
 }
 
-static int usb_wacom_initfn(USBDevice *dev)
+static void usb_wacom_realize(USBDevice *dev, Error **errp)
 {
     USBWacomState *s = DO_UPCAST(USBWacomState, dev, dev);
     usb_desc_create_serial(dev);
     usb_desc_init(dev);
     s->intr = usb_ep_get(dev, USB_TOKEN_IN, 1);
     s->changed = 1;
-    return 0;
 }
 
 static const VMStateDescription vmstate_usb_wacom = {
@@ -357,7 +356,7 @@ static void usb_wacom_class_init(ObjectClass *klass, void *data)
 
     uc->product_desc   = "QEMU PenPartner Tablet";
     uc->usb_desc       = &desc_wacom;
-    uc->init           = usb_wacom_initfn;
+    uc->realize           = usb_wacom_realize;
     uc->handle_reset   = usb_wacom_handle_reset;
     uc->handle_control = usb_wacom_handle_control;
     uc->handle_data    = usb_wacom_handle_data;
-- 
1.7.12.4

^ permalink raw reply related	[flat|nested] 43+ messages in thread

* [Qemu-devel] [PATCH 16/19] usb-audio: convert init to realize
  2014-09-18  9:32 [Qemu-devel] [PATCH 00/19] usb: convert device init to realize arei.gonglei
                   ` (14 preceding siblings ...)
  2014-09-18  9:32 ` [Qemu-devel] [PATCH 15/19] dev-wacom: " arei.gonglei
@ 2014-09-18  9:32 ` arei.gonglei
  2014-09-18 10:16   ` Paolo Bonzini
  2014-09-18  9:32 ` [Qemu-devel] [PATCH 17/19] usb-redir: " arei.gonglei
                   ` (2 subsequent siblings)
  18 siblings, 1 reply; 43+ messages in thread
From: arei.gonglei @ 2014-09-18  9:32 UTC (permalink / raw)
  To: qemu-devel
  Cc: weidong.huang, luonengjun, peter.huangpeng, armbru, Gonglei,
	kraxel, pbonzini

From: Gonglei <arei.gonglei@huawei.com>

Signed-off-by: Gonglei <arei.gonglei@huawei.com>
---
 hw/usb/dev-audio.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/hw/usb/dev-audio.c b/hw/usb/dev-audio.c
index 7b9957b..83ebe83 100644
--- a/hw/usb/dev-audio.c
+++ b/hw/usb/dev-audio.c
@@ -628,7 +628,7 @@ static void usb_audio_handle_destroy(USBDevice *dev)
     streambuf_fini(&s->out.buf);
 }
 
-static int usb_audio_initfn(USBDevice *dev)
+static void usb_audio_realize(USBDevice *dev, Error **errp)
 {
     USBAudioState *s = DO_UPCAST(USBAudioState, dev, dev);
 
@@ -651,7 +651,6 @@ static int usb_audio_initfn(USBDevice *dev)
                                 s, output_callback, &s->out.as);
     AUD_set_volume_out(s->out.voice, s->out.mute, s->out.vol[0], s->out.vol[1]);
     AUD_set_active_out(s->out.voice, 0);
-    return 0;
 }
 
 static const VMStateDescription vmstate_usb_audio = {
@@ -676,7 +675,7 @@ static void usb_audio_class_init(ObjectClass *klass, void *data)
     set_bit(DEVICE_CATEGORY_SOUND, dc->categories);
     k->product_desc   = "QEMU USB Audio Interface";
     k->usb_desc       = &desc_audio;
-    k->init           = usb_audio_initfn;
+    k->realize           = usb_audio_realize;
     k->handle_reset   = usb_audio_handle_reset;
     k->handle_control = usb_audio_handle_control;
     k->handle_data    = usb_audio_handle_data;
-- 
1.7.12.4

^ permalink raw reply related	[flat|nested] 43+ messages in thread

* [Qemu-devel] [PATCH 17/19] usb-redir: convert init to realize
  2014-09-18  9:32 [Qemu-devel] [PATCH 00/19] usb: convert device init to realize arei.gonglei
                   ` (15 preceding siblings ...)
  2014-09-18  9:32 ` [Qemu-devel] [PATCH 16/19] usb-audio: " arei.gonglei
@ 2014-09-18  9:32 ` arei.gonglei
  2014-09-18 10:16   ` Paolo Bonzini
  2014-09-18  9:32 ` [Qemu-devel] [PATCH 18/19] usb-mtp: " arei.gonglei
  2014-09-18  9:33 ` [Qemu-devel] [PATCH 19/19] usb-bus: remove "init" from USBDeviceClass struct arei.gonglei
  18 siblings, 1 reply; 43+ messages in thread
From: arei.gonglei @ 2014-09-18  9:32 UTC (permalink / raw)
  To: qemu-devel
  Cc: weidong.huang, luonengjun, peter.huangpeng, armbru, Gonglei,
	kraxel, pbonzini

From: Gonglei <arei.gonglei@huawei.com>

In this way, all the implementations now use
error_setg instead of qerror_report for reporting error.

Signed-off-by: Gonglei <arei.gonglei@huawei.com>
---
 hw/usb/redirect.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/hw/usb/redirect.c b/hw/usb/redirect.c
index 95158b3..e2c9896 100644
--- a/hw/usb/redirect.c
+++ b/hw/usb/redirect.c
@@ -1361,14 +1361,14 @@ static void usbredir_init_endpoints(USBRedirDevice *dev)
     }
 }
 
-static int usbredir_initfn(USBDevice *udev)
+static void usbredir_realize(USBDevice *udev, Error **errp)
 {
     USBRedirDevice *dev = DO_UPCAST(USBRedirDevice, dev, udev);
     int i;
 
     if (dev->cs == NULL) {
-        qerror_report(QERR_MISSING_PARAMETER, "chardev");
-        return -1;
+        error_set(errp, QERR_MISSING_PARAMETER, "chardev");
+        return;
     }
 
     if (dev->filter_str) {
@@ -1376,9 +1376,9 @@ static int usbredir_initfn(USBDevice *udev)
                                            &dev->filter_rules,
                                            &dev->filter_rules_count);
         if (i) {
-            qerror_report(QERR_INVALID_PARAMETER_VALUE, "filter",
-                          "a usb device filter string");
-            return -1;
+            error_set(errp, QERR_INVALID_PARAMETER_VALUE, "filter",
+                      "a usb device filter string");
+            return;
         }
     }
 
@@ -1402,7 +1402,6 @@ static int usbredir_initfn(USBDevice *udev)
 
     qemu_add_vm_change_state_handler(usbredir_vm_state_change, dev);
     add_boot_device_path(dev->bootindex, &udev->qdev, NULL);
-    return 0;
 }
 
 static void usbredir_cleanup_device_queues(USBRedirDevice *dev)
@@ -2481,7 +2480,7 @@ static void usbredir_class_initfn(ObjectClass *klass, void *data)
     USBDeviceClass *uc = USB_DEVICE_CLASS(klass);
     DeviceClass *dc = DEVICE_CLASS(klass);
 
-    uc->init           = usbredir_initfn;
+    uc->realize        = usbredir_realize;
     uc->product_desc   = "USB Redirection Device";
     uc->handle_destroy = usbredir_handle_destroy;
     uc->cancel_packet  = usbredir_cancel_packet;
-- 
1.7.12.4

^ permalink raw reply related	[flat|nested] 43+ messages in thread

* [Qemu-devel] [PATCH 18/19] usb-mtp: convert init to realize
  2014-09-18  9:32 [Qemu-devel] [PATCH 00/19] usb: convert device init to realize arei.gonglei
                   ` (16 preceding siblings ...)
  2014-09-18  9:32 ` [Qemu-devel] [PATCH 17/19] usb-redir: " arei.gonglei
@ 2014-09-18  9:32 ` arei.gonglei
  2014-09-18 10:16   ` Paolo Bonzini
  2014-09-18  9:33 ` [Qemu-devel] [PATCH 19/19] usb-bus: remove "init" from USBDeviceClass struct arei.gonglei
  18 siblings, 1 reply; 43+ messages in thread
From: arei.gonglei @ 2014-09-18  9:32 UTC (permalink / raw)
  To: qemu-devel
  Cc: weidong.huang, luonengjun, peter.huangpeng, armbru, Gonglei,
	kraxel, pbonzini

From: Gonglei <arei.gonglei@huawei.com>

Signed-off-by: Gonglei <arei.gonglei@huawei.com>
---
 hw/usb/dev-mtp.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/hw/usb/dev-mtp.c b/hw/usb/dev-mtp.c
index 0820046..108ece8 100644
--- a/hw/usb/dev-mtp.c
+++ b/hw/usb/dev-mtp.c
@@ -1060,7 +1060,7 @@ static void usb_mtp_handle_data(USBDevice *dev, USBPacket *p)
     }
 }
 
-static int usb_mtp_initfn(USBDevice *dev)
+static void usb_mtp_realize(USBDevice *dev, Error **errp)
 {
     MTPState *s = DO_UPCAST(MTPState, dev, dev);
 
@@ -1075,7 +1075,6 @@ static int usb_mtp_initfn(USBDevice *dev)
             s->desc = g_strdup("none");
         }
     }
-    return 0;
 }
 
 static const VMStateDescription vmstate_usb_mtp = {
@@ -1100,7 +1099,7 @@ static void usb_mtp_class_initfn(ObjectClass *klass, void *data)
     DeviceClass *dc = DEVICE_CLASS(klass);
     USBDeviceClass *uc = USB_DEVICE_CLASS(klass);
 
-    uc->init           = usb_mtp_initfn;
+    uc->realize        = usb_mtp_realize;
     uc->product_desc   = "QEMU USB MTP";
     uc->usb_desc       = &desc;
     uc->cancel_packet  = usb_mtp_cancel_packet;
-- 
1.7.12.4

^ permalink raw reply related	[flat|nested] 43+ messages in thread

* [Qemu-devel] [PATCH 19/19] usb-bus: remove "init" from USBDeviceClass struct
  2014-09-18  9:32 [Qemu-devel] [PATCH 00/19] usb: convert device init to realize arei.gonglei
                   ` (17 preceding siblings ...)
  2014-09-18  9:32 ` [Qemu-devel] [PATCH 18/19] usb-mtp: " arei.gonglei
@ 2014-09-18  9:33 ` arei.gonglei
  2014-09-18 10:16   ` Paolo Bonzini
  18 siblings, 1 reply; 43+ messages in thread
From: arei.gonglei @ 2014-09-18  9:33 UTC (permalink / raw)
  To: qemu-devel
  Cc: weidong.huang, luonengjun, peter.huangpeng, armbru, Gonglei,
	kraxel, pbonzini

From: Gonglei <arei.gonglei@huawei.com>

All usb-bus devices are realized by realize(),
remove init callback function from USBDeviceClass struct.

Signed-off-by: Gonglei <arei.gonglei@huawei.com>
---
 hw/usb/bus.c     | 2 --
 include/hw/usb.h | 2 --
 2 files changed, 4 deletions(-)

diff --git a/hw/usb/bus.c b/hw/usb/bus.c
index 12881cb..b375293 100644
--- a/hw/usb/bus.c
+++ b/hw/usb/bus.c
@@ -113,8 +113,6 @@ static void usb_device_realize(USBDevice *dev, Error **errp)
 
     if (klass->realize) {
         klass->realize(dev, errp);
-    } else if (klass->init) {
-        klass->init(dev);
     }
 }
 
diff --git a/include/hw/usb.h b/include/hw/usb.h
index 612f09f..8ffbba2 100644
--- a/include/hw/usb.h
+++ b/include/hw/usb.h
@@ -273,8 +273,6 @@ typedef void (*USBDeviceUnrealize)(USBDevice *dev, Error **errp);
 typedef struct USBDeviceClass {
     DeviceClass parent_class;
 
-    int (*init)(USBDevice *dev);
-
     USBDeviceRealize realize;
     USBDeviceUnrealize unrealize;
 
-- 
1.7.12.4

^ permalink raw reply related	[flat|nested] 43+ messages in thread

* Re: [Qemu-devel] [PATCH 02/19] usb-bus: convert USBDeviceClass init to realize
  2014-09-18  9:32 ` [Qemu-devel] [PATCH 02/19] usb-bus: convert USBDeviceClass init to realize arei.gonglei
@ 2014-09-18 10:08   ` Paolo Bonzini
  2014-09-18 10:19     ` Gonglei (Arei)
  2014-09-18 10:09   ` Paolo Bonzini
  1 sibling, 1 reply; 43+ messages in thread
From: Paolo Bonzini @ 2014-09-18 10:08 UTC (permalink / raw)
  To: arei.gonglei, qemu-devel
  Cc: luonengjun, peter.huangpeng, weidong.huang, kraxel, armbru

Il 18/09/2014 11:32, arei.gonglei@huawei.com ha scritto:
> @@ -460,7 +460,7 @@ static void usb_serial_event(void *opaque, int event)
>              break;
>          case CHR_EVENT_OPENED:
>              if (!s->dev.attached) {
> -                usb_device_attach(&s->dev);
> +                usb_device_attach(&s->dev, NULL);

After this patch, this stops printing the error if the attach fails.
Please add qerror_report_err.

>              }
>              break;
>          case CHR_EVENT_CLOSED:
> @@ -489,7 +489,7 @@ static int usb_serial_initfn(USBDevice *dev)
>      usb_serial_handle_reset(dev);
>  
>      if (s->cs->be_open && !dev->attached) {
> -        usb_device_attach(dev);
> +        usb_device_attach(dev, NULL);

This too.  Please add qerror_report_err here too and, in this case,
please make patch 12 pass the errp instead of using qerror_report_err.

Paolo

>      }
>      return 0;

^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: [Qemu-devel] [PATCH 02/19] usb-bus: convert USBDeviceClass init to realize
  2014-09-18  9:32 ` [Qemu-devel] [PATCH 02/19] usb-bus: convert USBDeviceClass init to realize arei.gonglei
  2014-09-18 10:08   ` Paolo Bonzini
@ 2014-09-18 10:09   ` Paolo Bonzini
  2014-09-18 10:21     ` Gonglei (Arei)
  1 sibling, 1 reply; 43+ messages in thread
From: Paolo Bonzini @ 2014-09-18 10:09 UTC (permalink / raw)
  To: arei.gonglei, qemu-devel
  Cc: luonengjun, peter.huangpeng, weidong.huang, kraxel, armbru

Il 18/09/2014 11:32, arei.gonglei@huawei.com ha scritto:
>  static void usb_msd_password_cb(void *opaque, int err)
>  {
>      MSDState *s = opaque;
> +    Error *local_err = NULL;
>  
> -    if (!err)
> -        err = usb_device_attach(&s->dev);
> +    if (!err) {
> +        usb_device_attach(&s->dev, &local_err);
> +    }
>  
> -    if (err)
> +    if (local_err) {
> +        error_report("%s", error_get_pretty(local_err));

I think this should use qerror_report_err.

Paolo

^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: [Qemu-devel] [PATCH 04/19] libusb: convert init to realize
  2014-09-18  9:32 ` [Qemu-devel] [PATCH 04/19] libusb: " arei.gonglei
@ 2014-09-18 10:11   ` Paolo Bonzini
  0 siblings, 0 replies; 43+ messages in thread
From: Paolo Bonzini @ 2014-09-18 10:11 UTC (permalink / raw)
  To: arei.gonglei, qemu-devel
  Cc: luonengjun, peter.huangpeng, weidong.huang, kraxel, armbru

Il 18/09/2014 11:32, arei.gonglei@huawei.com ha scritto:
> From: Gonglei <arei.gonglei@huawei.com>
> 
> In this way, all the implementations now use
> error_setg instead of error_report for reporting error.
> 
> Signed-off-by: Gonglei <arei.gonglei@huawei.com>
> ---
>  hw/usb/host-libusb.c | 17 ++++++++---------
>  1 file changed, 8 insertions(+), 9 deletions(-)
> 
> diff --git a/hw/usb/host-libusb.c b/hw/usb/host-libusb.c
> index 9f92705..863be64 100644
> --- a/hw/usb/host-libusb.c
> +++ b/hw/usb/host-libusb.c
> @@ -951,21 +951,21 @@ static void usb_host_exit_notifier(struct Notifier *n, void *data)
>      }
>  }
>  
> -static int usb_host_initfn(USBDevice *udev)
> +static void usb_host_realize(USBDevice *udev, Error **errp)
>  {
>      USBHostDevice *s = USB_HOST_DEVICE(udev);
>  
>      if (s->match.vendor_id > 0xffff) {
> -        error_report("vendorid out of range");
> -        return -1;
> +        error_setg(errp, "vendorid out of range");
> +        return;
>      }
>      if (s->match.product_id > 0xffff) {
> -        error_report("productid out of range");
> -        return -1;
> +        error_setg(errp, "productid out of range");
> +        return;
>      }
>      if (s->match.addr > 127) {
> -        error_report("hostaddr out of range");
> -        return -1;
> +        error_setg(errp, "hostaddr out of range");
> +        return;
>      }
>  
>      loglevel = s->loglevel;
> @@ -980,7 +980,6 @@ static int usb_host_initfn(USBDevice *udev)
>      QTAILQ_INSERT_TAIL(&hostdevs, s, next);
>      add_boot_device_path(s->bootindex, &udev->qdev, NULL);
>      usb_host_auto_check(NULL);
> -    return 0;
>  }
>  
>  static void usb_host_handle_destroy(USBDevice *udev)
> @@ -1480,7 +1479,7 @@ static void usb_host_class_initfn(ObjectClass *klass, void *data)
>      DeviceClass *dc = DEVICE_CLASS(klass);
>      USBDeviceClass *uc = USB_DEVICE_CLASS(klass);
>  
> -    uc->init           = usb_host_initfn;
> +    uc->realize           = usb_host_realize;
>      uc->product_desc   = "USB Host Device";
>      uc->cancel_packet  = usb_host_cancel_packet;
>      uc->handle_data    = usb_host_handle_data;
> 

Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>

^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: [Qemu-devel] [PATCH 05/19] libusb: using error_report instead of fprintf
  2014-09-18  9:32 ` [Qemu-devel] [PATCH 05/19] libusb: using error_report instead of fprintf arei.gonglei
@ 2014-09-18 10:12   ` Paolo Bonzini
  0 siblings, 0 replies; 43+ messages in thread
From: Paolo Bonzini @ 2014-09-18 10:12 UTC (permalink / raw)
  To: arei.gonglei, qemu-devel
  Cc: luonengjun, peter.huangpeng, weidong.huang, kraxel, armbru

Il 18/09/2014 11:32, arei.gonglei@huawei.com ha scritto:
> From: Gonglei <arei.gonglei@huawei.com>
> 
> Signed-off-by: Gonglei <arei.gonglei@huawei.com>
> ---
>  hw/usb/host-libusb.c | 9 ++++-----
>  1 file changed, 4 insertions(+), 5 deletions(-)
> 
> diff --git a/hw/usb/host-libusb.c b/hw/usb/host-libusb.c
> index 863be64..0650910 100644
> --- a/hw/usb/host-libusb.c
> +++ b/hw/usb/host-libusb.c
> @@ -275,7 +275,7 @@ static void usb_host_libusb_error(const char *func, int rc)
>      } else {
>          errname = "?";
>      }
> -    fprintf(stderr, "%s: %d [%s]\n", func, rc, errname);
> +    error_report("%s: %d [%s]", func, rc, errname);
>  }
>  
>  /* ------------------------------------------------------------------------ */
> @@ -1376,14 +1376,13 @@ static int usb_host_alloc_streams(USBDevice *udev, USBEndpoint **eps,
>      if (rc < 0) {
>          usb_host_libusb_error("libusb_alloc_streams", rc);
>      } else if (rc != streams) {
> -        fprintf(stderr,
> -            "libusb_alloc_streams: got less streams then requested %d < %d\n",
> -            rc, streams);
> +        error_report("libusb_alloc_streams: got less streams "
> +                     "then requested %d < %d", rc, streams);
>      }
>  
>      return (rc == streams) ? 0 : -1;
>  #else
> -    fprintf(stderr, "libusb_alloc_streams: error not implemented\n");
> +    error_report("libusb_alloc_streams: error not implemented");
>      return -1;
>  #endif
>  }
> 

Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>

^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: [Qemu-devel] [PATCH 06/19] usb-hub: convert init to realize
  2014-09-18  9:32 ` [Qemu-devel] [PATCH 06/19] usb-hub: convert init to realize arei.gonglei
@ 2014-09-18 10:12   ` Paolo Bonzini
  0 siblings, 0 replies; 43+ messages in thread
From: Paolo Bonzini @ 2014-09-18 10:12 UTC (permalink / raw)
  To: arei.gonglei, qemu-devel
  Cc: luonengjun, peter.huangpeng, weidong.huang, kraxel, armbru

Il 18/09/2014 11:32, arei.gonglei@huawei.com ha scritto:
> From: Gonglei <arei.gonglei@huawei.com>
> 
> In this way, all the implementations now use
> error_setg instead of error_report for reporting error.
> 
> Signed-off-by: Gonglei <arei.gonglei@huawei.com>
> ---
>  hw/usb/dev-hub.c | 9 ++++-----
>  1 file changed, 4 insertions(+), 5 deletions(-)
> 
> diff --git a/hw/usb/dev-hub.c b/hw/usb/dev-hub.c
> index 7492174..8e3f7a8 100644
> --- a/hw/usb/dev-hub.c
> +++ b/hw/usb/dev-hub.c
> @@ -511,15 +511,15 @@ static USBPortOps usb_hub_port_ops = {
>      .complete = usb_hub_complete,
>  };
>  
> -static int usb_hub_initfn(USBDevice *dev)
> +static void usb_hub_realize(USBDevice *dev, Error **errp)
>  {
>      USBHubState *s = DO_UPCAST(USBHubState, dev, dev);
>      USBHubPort *port;
>      int i;
>  
>      if (dev->port->hubcount == 5) {
> -        error_report("usb hub chain too deep");
> -        return -1;
> +        error_setg(errp, "usb hub chain too deep");
> +        return;
>      }
>  
>      usb_desc_create_serial(dev);
> @@ -533,7 +533,6 @@ static int usb_hub_initfn(USBDevice *dev)
>          usb_port_location(&port->port, dev->port, i+1);
>      }
>      usb_hub_handle_reset(dev);
> -    return 0;
>  }
>  
>  static const VMStateDescription vmstate_usb_hub_port = {
> @@ -564,7 +563,7 @@ static void usb_hub_class_initfn(ObjectClass *klass, void *data)
>      DeviceClass *dc = DEVICE_CLASS(klass);
>      USBDeviceClass *uc = USB_DEVICE_CLASS(klass);
>  
> -    uc->init           = usb_hub_initfn;
> +    uc->realize           = usb_hub_realize;
>      uc->product_desc   = "QEMU USB Hub";
>      uc->usb_desc       = &desc_hub;
>      uc->find_device    = usb_hub_find_device;
> 

Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>

^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: [Qemu-devel] [PATCH 07/19] dev-storage: convert init to realize
  2014-09-18  9:32 ` [Qemu-devel] [PATCH 07/19] dev-storage: " arei.gonglei
@ 2014-09-18 10:13   ` Paolo Bonzini
  0 siblings, 0 replies; 43+ messages in thread
From: Paolo Bonzini @ 2014-09-18 10:13 UTC (permalink / raw)
  To: arei.gonglei, qemu-devel
  Cc: luonengjun, peter.huangpeng, weidong.huang, kraxel, armbru

Il 18/09/2014 11:32, arei.gonglei@huawei.com ha scritto:
> From: Gonglei <arei.gonglei@huawei.com>
> 
> In this way, all the implementations now use
> error_setg instead of error_report for reporting error.
> 
> Signed-off-by: Gonglei <arei.gonglei@huawei.com>
> ---
>  hw/usb/dev-storage.c | 21 ++++++++-------------
>  1 file changed, 8 insertions(+), 13 deletions(-)
> 
> diff --git a/hw/usb/dev-storage.c b/hw/usb/dev-storage.c
> index a9f31f0..6dc5f47 100644
> --- a/hw/usb/dev-storage.c
> +++ b/hw/usb/dev-storage.c
> @@ -595,7 +595,7 @@ static const struct SCSIBusInfo usb_msd_scsi_info_bot = {
>      .load_request = usb_msd_load_request,
>  };
>  
> -static int usb_msd_initfn_storage(USBDevice *dev)
> +static void usb_msd_realize_storage(USBDevice *dev, Error **errp)
>  {
>      MSDState *s = DO_UPCAST(MSDState, dev, dev);
>      BlockDriverState *bs = s->conf.bs;
> @@ -603,8 +603,8 @@ static int usb_msd_initfn_storage(USBDevice *dev)
>      Error *err = NULL;
>  
>      if (!bs) {
> -        error_report("drive property not set");
> -        return -1;
> +        error_setg(errp, "drive property not set");
> +        return;
>      }
>  
>      blkconf_serial(&s->conf, &dev->serial);
> @@ -629,9 +629,8 @@ static int usb_msd_initfn_storage(USBDevice *dev)
>                                           s->conf.bootindex, dev->serial,
>                                           &err);
>      if (!scsi_dev) {
> -        error_report("%s", error_get_pretty(err));
> -        error_free(err);
> -        return -1;
> +        error_propagate(errp, err);
> +        return;
>      }
>      s->bus.qbus.allow_hotplug = 0;
>      usb_msd_handle_reset(dev);
> @@ -644,11 +643,9 @@ static int usb_msd_initfn_storage(USBDevice *dev)
>              autostart = 0;
>          }
>      }
> -
> -    return 0;
>  }
>  
> -static int usb_msd_initfn_bot(USBDevice *dev)
> +static void usb_msd_realize_bot(USBDevice *dev, Error **errp)
>  {
>      MSDState *s = DO_UPCAST(MSDState, dev, dev);
>  
> @@ -658,8 +655,6 @@ static int usb_msd_initfn_bot(USBDevice *dev)
>                   &usb_msd_scsi_info_bot, NULL);
>      s->bus.qbus.allow_hotplug = 0;
>      usb_msd_handle_reset(dev);
> -
> -    return 0;
>  }
>  
>  static USBDevice *usb_msd_init(USBBus *bus, const char *filename)
> @@ -765,7 +760,7 @@ static void usb_msd_class_initfn_storage(ObjectClass *klass, void *data)
>      DeviceClass *dc = DEVICE_CLASS(klass);
>      USBDeviceClass *uc = USB_DEVICE_CLASS(klass);
>  
> -    uc->init = usb_msd_initfn_storage;
> +    uc->realize = usb_msd_realize_storage;
>      dc->props = msd_properties;
>      usb_msd_class_initfn_common(klass);
>  }
> @@ -774,7 +769,7 @@ static void usb_msd_class_initfn_bot(ObjectClass *klass, void *data)
>  {
>      USBDeviceClass *uc = USB_DEVICE_CLASS(klass);
>  
> -    uc->init = usb_msd_initfn_bot;
> +    uc->realize = usb_msd_realize_bot;
>      usb_msd_class_initfn_common(klass);
>  }
>  
> 

Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>

^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: [Qemu-devel] [PATCH 08/19] dev-storage: usring error_report instead of fprintf/printf
  2014-09-18  9:32 ` [Qemu-devel] [PATCH 08/19] dev-storage: usring error_report instead of fprintf/printf arei.gonglei
@ 2014-09-18 10:13   ` Paolo Bonzini
  0 siblings, 0 replies; 43+ messages in thread
From: Paolo Bonzini @ 2014-09-18 10:13 UTC (permalink / raw)
  To: arei.gonglei, qemu-devel
  Cc: luonengjun, peter.huangpeng, weidong.huang, kraxel, armbru

Il 18/09/2014 11:32, arei.gonglei@huawei.com ha scritto:
> From: Gonglei <arei.gonglei@huawei.com>
> 
> Signed-off-by: Gonglei <arei.gonglei@huawei.com>
> ---
>  hw/usb/dev-storage.c | 12 ++++++------
>  1 file changed, 6 insertions(+), 6 deletions(-)
> 
> diff --git a/hw/usb/dev-storage.c b/hw/usb/dev-storage.c
> index 6dc5f47..681959d 100644
> --- a/hw/usb/dev-storage.c
> +++ b/hw/usb/dev-storage.c
> @@ -409,19 +409,19 @@ static void usb_msd_handle_data(USBDevice *dev, USBPacket *p)
>          switch (s->mode) {
>          case USB_MSDM_CBW:
>              if (p->iov.size != 31) {
> -                fprintf(stderr, "usb-msd: Bad CBW size");
> +                error_report("usb-msd: Bad CBW size");
>                  goto fail;
>              }
>              usb_packet_copy(p, &cbw, 31);
>              if (le32_to_cpu(cbw.sig) != 0x43425355) {
> -                fprintf(stderr, "usb-msd: Bad signature %08x\n",
> -                        le32_to_cpu(cbw.sig));
> +                error_report("usb-msd: Bad signature %08x",
> +                             le32_to_cpu(cbw.sig));
>                  goto fail;
>              }
>              DPRINTF("Command on LUN %d\n", cbw.lun);
>              scsi_dev = scsi_device_find(&s->bus, 0, 0, cbw.lun);
>              if (scsi_dev == NULL) {
> -                fprintf(stderr, "usb-msd: Bad LUN %d\n", cbw.lun);
> +                error_report("usb-msd: Bad LUN %d", cbw.lun);
>                  goto fail;
>              }
>              tag = le32_to_cpu(cbw.tag);
> @@ -680,13 +680,13 @@ static USBDevice *usb_msd_init(USBBus *bus, const char *filename)
>              pstrcpy(fmt, len, p2);
>              qemu_opt_set(opts, "format", fmt);
>          } else if (*filename != ':') {
> -            printf("unrecognized USB mass-storage option %s\n", filename);
> +            error_report("unrecognized USB mass-storage option %s", filename);
>              return NULL;
>          }
>          filename = p1;
>      }
>      if (!*filename) {
> -        printf("block device specification needed\n");
> +        error_report("block device specification needed");
>          return NULL;
>      }
>      qemu_opt_set(opts, "file", filename);
> 

Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>

^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: [Qemu-devel] [PATCH 09/19] dev-uas: convert init to realize
  2014-09-18  9:32 ` [Qemu-devel] [PATCH 09/19] dev-uas: convert init to realize arei.gonglei
@ 2014-09-18 10:13   ` Paolo Bonzini
  0 siblings, 0 replies; 43+ messages in thread
From: Paolo Bonzini @ 2014-09-18 10:13 UTC (permalink / raw)
  To: arei.gonglei, qemu-devel
  Cc: luonengjun, peter.huangpeng, weidong.huang, kraxel, armbru

Il 18/09/2014 11:32, arei.gonglei@huawei.com ha scritto:
> From: Gonglei <arei.gonglei@huawei.com>
> 
> Signed-off-by: Gonglei <arei.gonglei@huawei.com>
> ---
>  hw/usb/dev-uas.c | 6 ++----
>  1 file changed, 2 insertions(+), 4 deletions(-)
> 
> diff --git a/hw/usb/dev-uas.c b/hw/usb/dev-uas.c
> index 9832385..884c003 100644
> --- a/hw/usb/dev-uas.c
> +++ b/hw/usb/dev-uas.c
> @@ -892,7 +892,7 @@ static void usb_uas_handle_destroy(USBDevice *dev)
>      qemu_bh_delete(uas->status_bh);
>  }
>  
> -static int usb_uas_init(USBDevice *dev)
> +static void usb_uas_realize(USBDevice *dev, Error **errp)
>  {
>      UASDevice *uas = DO_UPCAST(UASDevice, dev, dev);
>  
> @@ -905,8 +905,6 @@ static int usb_uas_init(USBDevice *dev)
>  
>      scsi_bus_new(&uas->bus, sizeof(uas->bus), DEVICE(dev),
>                   &usb_uas_scsi_info, NULL);
> -
> -    return 0;
>  }
>  
>  static const VMStateDescription vmstate_usb_uas = {
> @@ -928,7 +926,7 @@ static void usb_uas_class_initfn(ObjectClass *klass, void *data)
>      DeviceClass *dc = DEVICE_CLASS(klass);
>      USBDeviceClass *uc = USB_DEVICE_CLASS(klass);
>  
> -    uc->init           = usb_uas_init;
> +    uc->realize           = usb_uas_realize;
>      uc->product_desc   = desc_strings[STR_PRODUCT];
>      uc->usb_desc       = &desc;
>      uc->cancel_packet  = usb_uas_cancel_io;
> 

Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>

^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: [Qemu-devel] [PATCH 10/19] dev-uas: using error_report instead of fprintf
  2014-09-18  9:32 ` [Qemu-devel] [PATCH 10/19] dev-uas: using error_report instead of fprintf arei.gonglei
@ 2014-09-18 10:14   ` Paolo Bonzini
  0 siblings, 0 replies; 43+ messages in thread
From: Paolo Bonzini @ 2014-09-18 10:14 UTC (permalink / raw)
  To: arei.gonglei, qemu-devel
  Cc: luonengjun, peter.huangpeng, weidong.huang, kraxel, armbru

Il 18/09/2014 11:32, arei.gonglei@huawei.com ha scritto:
> From: Gonglei <arei.gonglei@huawei.com>
> 
> Signed-off-by: Gonglei <arei.gonglei@huawei.com>
> ---
>  hw/usb/dev-uas.c | 11 ++++++-----
>  1 file changed, 6 insertions(+), 5 deletions(-)
> 
> diff --git a/hw/usb/dev-uas.c b/hw/usb/dev-uas.c
> index 884c003..1508064 100644
> --- a/hw/usb/dev-uas.c
> +++ b/hw/usb/dev-uas.c
> @@ -13,6 +13,7 @@
>  #include "qemu/option.h"
>  #include "qemu/config-file.h"
>  #include "trace.h"
> +#include "qemu/error-report.h"
>  
>  #include "hw/usb.h"
>  #include "hw/usb/desc.h"
> @@ -648,7 +649,7 @@ static void usb_uas_handle_control(USBDevice *dev, USBPacket *p,
>      if (ret >= 0) {
>          return;
>      }
> -    fprintf(stderr, "%s: unhandled control request\n", __func__);
> +    error_report("%s: unhandled control request", __func__);
>      p->status = USB_RET_STALL;
>  }
>  
> @@ -814,8 +815,8 @@ static void usb_uas_handle_data(USBDevice *dev, USBPacket *p)
>              usb_uas_task(uas, &iu);
>              break;
>          default:
> -            fprintf(stderr, "%s: unknown command iu: id 0x%x\n",
> -                    __func__, iu.hdr.id);
> +            error_report("%s: unknown command iu: id 0x%x",
> +                         __func__, iu.hdr.id);
>              p->status = USB_RET_STALL;
>              break;
>          }
> @@ -861,7 +862,7 @@ static void usb_uas_handle_data(USBDevice *dev, USBPacket *p)
>                  p->status = USB_RET_ASYNC;
>                  break;
>              } else {
> -                fprintf(stderr, "%s: no inflight request\n", __func__);
> +                error_report("%s: no inflight request", __func__);
>                  p->status = USB_RET_STALL;
>                  break;
>              }
> @@ -879,7 +880,7 @@ static void usb_uas_handle_data(USBDevice *dev, USBPacket *p)
>          usb_uas_start_next_transfer(uas);
>          break;
>      default:
> -        fprintf(stderr, "%s: invalid endpoint %d\n", __func__, p->ep->nr);
> +        error_report("%s: invalid endpoint %d", __func__, p->ep->nr);
>          p->status = USB_RET_STALL;
>          break;
>      }
> 

Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>

^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: [Qemu-devel] [PATCH 11/19] dev-bluetooth: convert init to realize
  2014-09-18  9:32 ` [Qemu-devel] [PATCH 11/19] dev-bluetooth: convert init to realize arei.gonglei
@ 2014-09-18 10:14   ` Paolo Bonzini
  0 siblings, 0 replies; 43+ messages in thread
From: Paolo Bonzini @ 2014-09-18 10:14 UTC (permalink / raw)
  To: arei.gonglei, qemu-devel
  Cc: luonengjun, peter.huangpeng, weidong.huang, kraxel, armbru

Il 18/09/2014 11:32, arei.gonglei@huawei.com ha scritto:
> From: Gonglei <arei.gonglei@huawei.com>
> 
> Signed-off-by: Gonglei <arei.gonglei@huawei.com>
> ---
>  hw/usb/dev-bluetooth.c | 6 ++----
>  1 file changed, 2 insertions(+), 4 deletions(-)
> 
> diff --git a/hw/usb/dev-bluetooth.c b/hw/usb/dev-bluetooth.c
> index a76e581..7db9921 100644
> --- a/hw/usb/dev-bluetooth.c
> +++ b/hw/usb/dev-bluetooth.c
> @@ -501,7 +501,7 @@ static void usb_bt_handle_destroy(USBDevice *dev)
>      s->hci->acl_recv = NULL;
>  }
>  
> -static int usb_bt_initfn(USBDevice *dev)
> +static void usb_bt_realize(USBDevice *dev, Error **errp)
>  {
>      struct USBBtState *s = DO_UPCAST(struct USBBtState, dev, dev);
>  
> @@ -516,8 +516,6 @@ static int usb_bt_initfn(USBDevice *dev)
>      s->hci->acl_recv = usb_bt_out_hci_packet_acl;
>      usb_bt_handle_reset(&s->dev);
>      s->intr = usb_ep_get(dev, USB_TOKEN_IN, USB_EVT_EP);
> -
> -    return 0;
>  }
>  
>  static USBDevice *usb_bt_init(USBBus *bus, const char *cmdline)
> @@ -560,7 +558,7 @@ static void usb_bt_class_initfn(ObjectClass *klass, void *data)
>      DeviceClass *dc = DEVICE_CLASS(klass);
>      USBDeviceClass *uc = USB_DEVICE_CLASS(klass);
>  
> -    uc->init           = usb_bt_initfn;
> +    uc->realize           = usb_bt_realize;
>      uc->product_desc   = "QEMU BT dongle";
>      uc->usb_desc       = &desc_bluetooth;
>      uc->handle_reset   = usb_bt_handle_reset;
> 

Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>

^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: [Qemu-devel] [PATCH 12/19] dev-serial: convert init to realize
  2014-09-18  9:32 ` [Qemu-devel] [PATCH 12/19] dev-serial: " arei.gonglei
@ 2014-09-18 10:14   ` Paolo Bonzini
  0 siblings, 0 replies; 43+ messages in thread
From: Paolo Bonzini @ 2014-09-18 10:14 UTC (permalink / raw)
  To: arei.gonglei, qemu-devel
  Cc: luonengjun, peter.huangpeng, weidong.huang, kraxel, armbru

Il 18/09/2014 11:32, arei.gonglei@huawei.com ha scritto:
> From: Gonglei <arei.gonglei@huawei.com>
> 
> In this way, all the implementations now use
> error_setg instead of error_report for reporting error.
> 
> Signed-off-by: Gonglei <arei.gonglei@huawei.com>
> ---
>  hw/usb/dev-serial.c | 11 +++++------
>  1 file changed, 5 insertions(+), 6 deletions(-)
> 
> diff --git a/hw/usb/dev-serial.c b/hw/usb/dev-serial.c
> index 178ecb2..3384db6 100644
> --- a/hw/usb/dev-serial.c
> +++ b/hw/usb/dev-serial.c
> @@ -471,7 +471,7 @@ static void usb_serial_event(void *opaque, int event)
>      }
>  }
>  
> -static int usb_serial_initfn(USBDevice *dev)
> +static void usb_serial_realize(USBDevice *dev, Error **errp)
>  {
>      USBSerialState *s = DO_UPCAST(USBSerialState, dev, dev);
>  
> @@ -480,8 +480,8 @@ static int usb_serial_initfn(USBDevice *dev)
>      dev->auto_attach = 0;
>  
>      if (!s->cs) {
> -        error_report("Property chardev is required");
> -        return -1;
> +        error_setg(errp, "Property chardev is required");
> +        return;
>      }
>  
>      qemu_chr_add_handlers(s->cs, usb_serial_can_read, usb_serial_read,
> @@ -491,7 +491,6 @@ static int usb_serial_initfn(USBDevice *dev)
>      if (s->cs->be_open && !dev->attached) {
>          usb_device_attach(dev, NULL);
>      }
> -    return 0;
>  }
>  
>  static USBDevice *usb_serial_init(USBBus *bus, const char *filename)
> @@ -582,7 +581,7 @@ static void usb_serial_class_initfn(ObjectClass *klass, void *data)
>      DeviceClass *dc = DEVICE_CLASS(klass);
>      USBDeviceClass *uc = USB_DEVICE_CLASS(klass);
>  
> -    uc->init = usb_serial_initfn;
> +    uc->realize = usb_serial_realize;
>      uc->product_desc   = "QEMU USB Serial";
>      uc->usb_desc       = &desc_serial;
>      uc->handle_reset   = usb_serial_handle_reset;
> @@ -610,7 +609,7 @@ static void usb_braille_class_initfn(ObjectClass *klass, void *data)
>      DeviceClass *dc = DEVICE_CLASS(klass);
>      USBDeviceClass *uc = USB_DEVICE_CLASS(klass);
>  
> -    uc->init           = usb_serial_initfn;
> +    uc->realize           = usb_serial_realize;
>      uc->product_desc   = "QEMU USB Braille";
>      uc->usb_desc       = &desc_braille;
>      uc->handle_reset   = usb_serial_handle_reset;
> 

Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>

^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: [Qemu-devel] [PATCH 13/19] usb-ccid: convert init to realize
  2014-09-18  9:32 ` [Qemu-devel] [PATCH 13/19] usb-ccid: " arei.gonglei
@ 2014-09-18 10:14   ` Paolo Bonzini
  0 siblings, 0 replies; 43+ messages in thread
From: Paolo Bonzini @ 2014-09-18 10:14 UTC (permalink / raw)
  To: arei.gonglei, qemu-devel
  Cc: luonengjun, peter.huangpeng, weidong.huang, kraxel, armbru

Il 18/09/2014 11:32, arei.gonglei@huawei.com ha scritto:
> From: Gonglei <arei.gonglei@huawei.com>
> 
> Signed-off-by: Gonglei <arei.gonglei@huawei.com>
> ---
>  hw/usb/dev-smartcard-reader.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/hw/usb/dev-smartcard-reader.c b/hw/usb/dev-smartcard-reader.c
> index 470e69f..442f487 100644
> --- a/hw/usb/dev-smartcard-reader.c
> +++ b/hw/usb/dev-smartcard-reader.c
> @@ -1304,7 +1304,7 @@ static int ccid_card_init(DeviceState *qdev)
>      return ret;
>  }
>  
> -static int ccid_initfn(USBDevice *dev)
> +static void ccid_realize(USBDevice *dev, Error **errp)
>  {
>      USBCCIDState *s = DO_UPCAST(USBCCIDState, dev, dev);
>  
> @@ -1332,7 +1332,6 @@ static int ccid_initfn(USBDevice *dev)
>      ccid_reset_parameters(s);
>      ccid_reset(s);
>      s->debug = parse_debug_env("QEMU_CCID_DEBUG", D_VERBOSE, s->debug);
> -    return 0;
>  }
>  
>  static int ccid_post_load(void *opaque, int version_id)
> @@ -1441,7 +1440,7 @@ static void ccid_class_initfn(ObjectClass *klass, void *data)
>      DeviceClass *dc = DEVICE_CLASS(klass);
>      USBDeviceClass *uc = USB_DEVICE_CLASS(klass);
>  
> -    uc->init           = ccid_initfn;
> +    uc->realize           = ccid_realize;
>      uc->product_desc   = "QEMU USB CCID";
>      uc->usb_desc       = &desc_ccid;
>      uc->handle_reset   = ccid_handle_reset;
> 

Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>

^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: [Qemu-devel] [PATCH 14/19] dev-hid: convert init to realize
  2014-09-18  9:32 ` [Qemu-devel] [PATCH 14/19] dev-hid: " arei.gonglei
@ 2014-09-18 10:15   ` Paolo Bonzini
  2014-09-18 10:23     ` Gonglei (Arei)
  0 siblings, 1 reply; 43+ messages in thread
From: Paolo Bonzini @ 2014-09-18 10:15 UTC (permalink / raw)
  To: arei.gonglei, qemu-devel
  Cc: luonengjun, peter.huangpeng, weidong.huang, kraxel, armbru

Il 18/09/2014 11:32, arei.gonglei@huawei.com ha scritto:
> From: Gonglei <arei.gonglei@huawei.com>
> 
> In this way, all the implementations now use
> error_setg instead of error_report for reporting error.
> 
> Signed-off-by: Gonglei <arei.gonglei@huawei.com>
> ---
>  hw/usb/dev-hid.c | 23 +++++++++++------------
>  1 file changed, 11 insertions(+), 12 deletions(-)
> 
> diff --git a/hw/usb/dev-hid.c b/hw/usb/dev-hid.c
> index 67a57f1..7e9d2d6 100644
> --- a/hw/usb/dev-hid.c
> +++ b/hw/usb/dev-hid.c
> @@ -582,7 +582,7 @@ static int usb_hid_initfn(USBDevice *dev, int kind)
>      return 0;

Please change usb_hid_initfn to return void.

>  }
>  
> -static int usb_tablet_initfn(USBDevice *dev)
> +static void usb_tablet_realize(USBDevice *dev, Error **errp)
>  {
>      USBHIDState *us = DO_UPCAST(USBHIDState, dev, dev);
>  
> @@ -594,22 +594,21 @@ static int usb_tablet_initfn(USBDevice *dev)
>          dev->usb_desc = &desc_tablet2;
>          break;
>      default:
> -        error_report("Invalid usb version %d for usb-tabler (must be 1 or 2)",
> -                     us->usb_version);
> -        return -1;
> +        error_setg(errp, "Invalid usb version %d for usb-tablet "
> +                   "(must be 1 or 2)", us->usb_version);

Missing return here.

Paolo

>      }
>  
> -    return usb_hid_initfn(dev, HID_TABLET);
> +    usb_hid_initfn(dev, HID_TABLET);
>  }
>  
> -static int usb_mouse_initfn(USBDevice *dev)
> +static void usb_mouse_realize(USBDevice *dev, Error **errp)
>  {
> -    return usb_hid_initfn(dev, HID_MOUSE);
> +    usb_hid_initfn(dev, HID_MOUSE);
>  }
>  
> -static int usb_keyboard_initfn(USBDevice *dev)
> +static void usb_keyboard_realize(USBDevice *dev, Error **errp)
>  {
> -    return usb_hid_initfn(dev, HID_KEYBOARD);
> +    usb_hid_initfn(dev, HID_KEYBOARD);
>  }
>  
>  static int usb_ptr_post_load(void *opaque, int version_id)
> @@ -669,7 +668,7 @@ static void usb_tablet_class_initfn(ObjectClass *klass, void *data)
>      USBDeviceClass *uc = USB_DEVICE_CLASS(klass);
>  
>      usb_hid_class_initfn(klass, data);
> -    uc->init           = usb_tablet_initfn;
> +    uc->realize           = usb_tablet_realize;
>      uc->product_desc   = "QEMU USB Tablet";
>      dc->vmsd = &vmstate_usb_ptr;
>      dc->props = usb_tablet_properties;
> @@ -689,7 +688,7 @@ static void usb_mouse_class_initfn(ObjectClass *klass, void *data)
>      USBDeviceClass *uc = USB_DEVICE_CLASS(klass);
>  
>      usb_hid_class_initfn(klass, data);
> -    uc->init           = usb_mouse_initfn;
> +    uc->realize           = usb_mouse_realize;
>      uc->product_desc   = "QEMU USB Mouse";
>      uc->usb_desc       = &desc_mouse;
>      dc->vmsd = &vmstate_usb_ptr;
> @@ -714,7 +713,7 @@ static void usb_keyboard_class_initfn(ObjectClass *klass, void *data)
>      USBDeviceClass *uc = USB_DEVICE_CLASS(klass);
>  
>      usb_hid_class_initfn(klass, data);
> -    uc->init           = usb_keyboard_initfn;
> +    uc->realize           = usb_keyboard_realize;
>      uc->product_desc   = "QEMU USB Keyboard";
>      uc->usb_desc       = &desc_keyboard;
>      dc->vmsd = &vmstate_usb_kbd;
> 

^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: [Qemu-devel] [PATCH 15/19] dev-wacom: convert init to realize
  2014-09-18  9:32 ` [Qemu-devel] [PATCH 15/19] dev-wacom: " arei.gonglei
@ 2014-09-18 10:15   ` Paolo Bonzini
  0 siblings, 0 replies; 43+ messages in thread
From: Paolo Bonzini @ 2014-09-18 10:15 UTC (permalink / raw)
  To: arei.gonglei, qemu-devel
  Cc: luonengjun, peter.huangpeng, weidong.huang, kraxel, armbru

Il 18/09/2014 11:32, arei.gonglei@huawei.com ha scritto:
> From: Gonglei <arei.gonglei@huawei.com>
> 
> Signed-off-by: Gonglei <arei.gonglei@huawei.com>
> ---
>  hw/usb/dev-wacom.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/hw/usb/dev-wacom.c b/hw/usb/dev-wacom.c
> index 1b73fd0..217d48e 100644
> --- a/hw/usb/dev-wacom.c
> +++ b/hw/usb/dev-wacom.c
> @@ -335,14 +335,13 @@ static void usb_wacom_handle_destroy(USBDevice *dev)
>      }
>  }
>  
> -static int usb_wacom_initfn(USBDevice *dev)
> +static void usb_wacom_realize(USBDevice *dev, Error **errp)
>  {
>      USBWacomState *s = DO_UPCAST(USBWacomState, dev, dev);
>      usb_desc_create_serial(dev);
>      usb_desc_init(dev);
>      s->intr = usb_ep_get(dev, USB_TOKEN_IN, 1);
>      s->changed = 1;
> -    return 0;
>  }
>  
>  static const VMStateDescription vmstate_usb_wacom = {
> @@ -357,7 +356,7 @@ static void usb_wacom_class_init(ObjectClass *klass, void *data)
>  
>      uc->product_desc   = "QEMU PenPartner Tablet";
>      uc->usb_desc       = &desc_wacom;
> -    uc->init           = usb_wacom_initfn;
> +    uc->realize           = usb_wacom_realize;
>      uc->handle_reset   = usb_wacom_handle_reset;
>      uc->handle_control = usb_wacom_handle_control;
>      uc->handle_data    = usb_wacom_handle_data;
> 

Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>

^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: [Qemu-devel] [PATCH 16/19] usb-audio: convert init to realize
  2014-09-18  9:32 ` [Qemu-devel] [PATCH 16/19] usb-audio: " arei.gonglei
@ 2014-09-18 10:16   ` Paolo Bonzini
  0 siblings, 0 replies; 43+ messages in thread
From: Paolo Bonzini @ 2014-09-18 10:16 UTC (permalink / raw)
  To: arei.gonglei, qemu-devel
  Cc: luonengjun, peter.huangpeng, weidong.huang, kraxel, armbru

Il 18/09/2014 11:32, arei.gonglei@huawei.com ha scritto:
> From: Gonglei <arei.gonglei@huawei.com>
> 
> Signed-off-by: Gonglei <arei.gonglei@huawei.com>
> ---
>  hw/usb/dev-audio.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/hw/usb/dev-audio.c b/hw/usb/dev-audio.c
> index 7b9957b..83ebe83 100644
> --- a/hw/usb/dev-audio.c
> +++ b/hw/usb/dev-audio.c
> @@ -628,7 +628,7 @@ static void usb_audio_handle_destroy(USBDevice *dev)
>      streambuf_fini(&s->out.buf);
>  }
>  
> -static int usb_audio_initfn(USBDevice *dev)
> +static void usb_audio_realize(USBDevice *dev, Error **errp)
>  {
>      USBAudioState *s = DO_UPCAST(USBAudioState, dev, dev);
>  
> @@ -651,7 +651,6 @@ static int usb_audio_initfn(USBDevice *dev)
>                                  s, output_callback, &s->out.as);
>      AUD_set_volume_out(s->out.voice, s->out.mute, s->out.vol[0], s->out.vol[1]);
>      AUD_set_active_out(s->out.voice, 0);
> -    return 0;
>  }
>  
>  static const VMStateDescription vmstate_usb_audio = {
> @@ -676,7 +675,7 @@ static void usb_audio_class_init(ObjectClass *klass, void *data)
>      set_bit(DEVICE_CATEGORY_SOUND, dc->categories);
>      k->product_desc   = "QEMU USB Audio Interface";
>      k->usb_desc       = &desc_audio;
> -    k->init           = usb_audio_initfn;
> +    k->realize           = usb_audio_realize;
>      k->handle_reset   = usb_audio_handle_reset;
>      k->handle_control = usb_audio_handle_control;
>      k->handle_data    = usb_audio_handle_data;
> 

Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>

^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: [Qemu-devel] [PATCH 17/19] usb-redir: convert init to realize
  2014-09-18  9:32 ` [Qemu-devel] [PATCH 17/19] usb-redir: " arei.gonglei
@ 2014-09-18 10:16   ` Paolo Bonzini
  0 siblings, 0 replies; 43+ messages in thread
From: Paolo Bonzini @ 2014-09-18 10:16 UTC (permalink / raw)
  To: arei.gonglei, qemu-devel
  Cc: luonengjun, peter.huangpeng, weidong.huang, kraxel, armbru

Il 18/09/2014 11:32, arei.gonglei@huawei.com ha scritto:
> From: Gonglei <arei.gonglei@huawei.com>
> 
> In this way, all the implementations now use
> error_setg instead of qerror_report for reporting error.
> 
> Signed-off-by: Gonglei <arei.gonglei@huawei.com>
> ---
>  hw/usb/redirect.c | 15 +++++++--------
>  1 file changed, 7 insertions(+), 8 deletions(-)
> 
> diff --git a/hw/usb/redirect.c b/hw/usb/redirect.c
> index 95158b3..e2c9896 100644
> --- a/hw/usb/redirect.c
> +++ b/hw/usb/redirect.c
> @@ -1361,14 +1361,14 @@ static void usbredir_init_endpoints(USBRedirDevice *dev)
>      }
>  }
>  
> -static int usbredir_initfn(USBDevice *udev)
> +static void usbredir_realize(USBDevice *udev, Error **errp)
>  {
>      USBRedirDevice *dev = DO_UPCAST(USBRedirDevice, dev, udev);
>      int i;
>  
>      if (dev->cs == NULL) {
> -        qerror_report(QERR_MISSING_PARAMETER, "chardev");
> -        return -1;
> +        error_set(errp, QERR_MISSING_PARAMETER, "chardev");
> +        return;
>      }
>  
>      if (dev->filter_str) {
> @@ -1376,9 +1376,9 @@ static int usbredir_initfn(USBDevice *udev)
>                                             &dev->filter_rules,
>                                             &dev->filter_rules_count);
>          if (i) {
> -            qerror_report(QERR_INVALID_PARAMETER_VALUE, "filter",
> -                          "a usb device filter string");
> -            return -1;
> +            error_set(errp, QERR_INVALID_PARAMETER_VALUE, "filter",
> +                      "a usb device filter string");
> +            return;
>          }
>      }
>  
> @@ -1402,7 +1402,6 @@ static int usbredir_initfn(USBDevice *udev)
>  
>      qemu_add_vm_change_state_handler(usbredir_vm_state_change, dev);
>      add_boot_device_path(dev->bootindex, &udev->qdev, NULL);
> -    return 0;
>  }
>  
>  static void usbredir_cleanup_device_queues(USBRedirDevice *dev)
> @@ -2481,7 +2480,7 @@ static void usbredir_class_initfn(ObjectClass *klass, void *data)
>      USBDeviceClass *uc = USB_DEVICE_CLASS(klass);
>      DeviceClass *dc = DEVICE_CLASS(klass);
>  
> -    uc->init           = usbredir_initfn;
> +    uc->realize        = usbredir_realize;
>      uc->product_desc   = "USB Redirection Device";
>      uc->handle_destroy = usbredir_handle_destroy;
>      uc->cancel_packet  = usbredir_cancel_packet;
> 

Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>

^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: [Qemu-devel] [PATCH 18/19] usb-mtp: convert init to realize
  2014-09-18  9:32 ` [Qemu-devel] [PATCH 18/19] usb-mtp: " arei.gonglei
@ 2014-09-18 10:16   ` Paolo Bonzini
  0 siblings, 0 replies; 43+ messages in thread
From: Paolo Bonzini @ 2014-09-18 10:16 UTC (permalink / raw)
  To: arei.gonglei, qemu-devel
  Cc: luonengjun, peter.huangpeng, weidong.huang, kraxel, armbru

Il 18/09/2014 11:32, arei.gonglei@huawei.com ha scritto:
> From: Gonglei <arei.gonglei@huawei.com>
> 
> Signed-off-by: Gonglei <arei.gonglei@huawei.com>
> ---
>  hw/usb/dev-mtp.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/hw/usb/dev-mtp.c b/hw/usb/dev-mtp.c
> index 0820046..108ece8 100644
> --- a/hw/usb/dev-mtp.c
> +++ b/hw/usb/dev-mtp.c
> @@ -1060,7 +1060,7 @@ static void usb_mtp_handle_data(USBDevice *dev, USBPacket *p)
>      }
>  }
>  
> -static int usb_mtp_initfn(USBDevice *dev)
> +static void usb_mtp_realize(USBDevice *dev, Error **errp)
>  {
>      MTPState *s = DO_UPCAST(MTPState, dev, dev);
>  
> @@ -1075,7 +1075,6 @@ static int usb_mtp_initfn(USBDevice *dev)
>              s->desc = g_strdup("none");
>          }
>      }
> -    return 0;
>  }
>  
>  static const VMStateDescription vmstate_usb_mtp = {
> @@ -1100,7 +1099,7 @@ static void usb_mtp_class_initfn(ObjectClass *klass, void *data)
>      DeviceClass *dc = DEVICE_CLASS(klass);
>      USBDeviceClass *uc = USB_DEVICE_CLASS(klass);
>  
> -    uc->init           = usb_mtp_initfn;
> +    uc->realize        = usb_mtp_realize;
>      uc->product_desc   = "QEMU USB MTP";
>      uc->usb_desc       = &desc;
>      uc->cancel_packet  = usb_mtp_cancel_packet;
> 

Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>

^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: [Qemu-devel] [PATCH 19/19] usb-bus: remove "init" from USBDeviceClass struct
  2014-09-18  9:33 ` [Qemu-devel] [PATCH 19/19] usb-bus: remove "init" from USBDeviceClass struct arei.gonglei
@ 2014-09-18 10:16   ` Paolo Bonzini
  0 siblings, 0 replies; 43+ messages in thread
From: Paolo Bonzini @ 2014-09-18 10:16 UTC (permalink / raw)
  To: arei.gonglei, qemu-devel
  Cc: luonengjun, peter.huangpeng, weidong.huang, kraxel, armbru

Il 18/09/2014 11:33, arei.gonglei@huawei.com ha scritto:
> From: Gonglei <arei.gonglei@huawei.com>
> 
> All usb-bus devices are realized by realize(),
> remove init callback function from USBDeviceClass struct.
> 
> Signed-off-by: Gonglei <arei.gonglei@huawei.com>
> ---
>  hw/usb/bus.c     | 2 --
>  include/hw/usb.h | 2 --
>  2 files changed, 4 deletions(-)
> 
> diff --git a/hw/usb/bus.c b/hw/usb/bus.c
> index 12881cb..b375293 100644
> --- a/hw/usb/bus.c
> +++ b/hw/usb/bus.c
> @@ -113,8 +113,6 @@ static void usb_device_realize(USBDevice *dev, Error **errp)
>  
>      if (klass->realize) {
>          klass->realize(dev, errp);
> -    } else if (klass->init) {
> -        klass->init(dev);
>      }
>  }
>  
> diff --git a/include/hw/usb.h b/include/hw/usb.h
> index 612f09f..8ffbba2 100644
> --- a/include/hw/usb.h
> +++ b/include/hw/usb.h
> @@ -273,8 +273,6 @@ typedef void (*USBDeviceUnrealize)(USBDevice *dev, Error **errp);
>  typedef struct USBDeviceClass {
>      DeviceClass parent_class;
>  
> -    int (*init)(USBDevice *dev);
> -
>      USBDeviceRealize realize;
>      USBDeviceUnrealize unrealize;
>  
> 

Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>

^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: [Qemu-devel] [PATCH 03/19] usb-net: convert init to realize
  2014-09-18  9:32 ` [Qemu-devel] [PATCH 03/19] usb-net: convert " arei.gonglei
@ 2014-09-18 10:17   ` Paolo Bonzini
  0 siblings, 0 replies; 43+ messages in thread
From: Paolo Bonzini @ 2014-09-18 10:17 UTC (permalink / raw)
  To: arei.gonglei, qemu-devel
  Cc: luonengjun, peter.huangpeng, weidong.huang, kraxel, armbru

Il 18/09/2014 11:32, arei.gonglei@huawei.com ha scritto:
> From: Gonglei <arei.gonglei@huawei.com>
> 
> meanwhile, qerror_report_err() is a transitional interface to
> help with converting existing HMP commands to QMP. It should
> not be used elsewhere.
> 
> Signed-off-by: Gonglei <arei.gonglei@huawei.com>
> ---
>  hw/usb/dev-network.c | 9 ++++-----
>  1 file changed, 4 insertions(+), 5 deletions(-)
> 
> diff --git a/hw/usb/dev-network.c b/hw/usb/dev-network.c
> index 518d536..686bd69 100644
> --- a/hw/usb/dev-network.c
> +++ b/hw/usb/dev-network.c
> @@ -27,7 +27,7 @@
>  #include "hw/usb.h"
>  #include "hw/usb/desc.h"
>  #include "net/net.h"
> -#include "qapi/qmp/qerror.h"
> +#include "qemu/error-report.h"
>  #include "qemu/queue.h"
>  #include "qemu/config-file.h"
>  #include "sysemu/sysemu.h"
> @@ -1341,7 +1341,7 @@ static NetClientInfo net_usbnet_info = {
>      .cleanup = usbnet_cleanup,
>  };
>  
> -static int usb_net_initfn(USBDevice *dev)
> +static void usb_net_realize(USBDevice *dev, Error **errrp)
>  {
>      USBNetState *s = DO_UPCAST(USBNetState, dev, dev);
>  
> @@ -1373,7 +1373,6 @@ static int usb_net_initfn(USBDevice *dev)
>      usb_desc_set_string(dev, STRING_ETHADDR, s->usbstring_mac);
>  
>      add_boot_device_path(s->conf.bootindex, &dev->qdev, "/ethernet@0");
> -    return 0;
>  }
>  
>  static USBDevice *usb_net_init(USBBus *bus, const char *cmdline)
> @@ -1392,7 +1391,7 @@ static USBDevice *usb_net_init(USBBus *bus, const char *cmdline)
>  
>      idx = net_client_init(opts, 0, &local_err);
>      if (local_err) {
> -        qerror_report_err(local_err);
> +        error_report("%s", error_get_pretty(local_err));
>          error_free(local_err);
>          return NULL;
>      }
> @@ -1421,7 +1420,7 @@ static void usb_net_class_initfn(ObjectClass *klass, void *data)
>      DeviceClass *dc = DEVICE_CLASS(klass);
>      USBDeviceClass *uc = USB_DEVICE_CLASS(klass);
>  
> -    uc->init           = usb_net_initfn;
> +    uc->realize           = usb_net_realize;
>      uc->product_desc   = "QEMU USB Network Interface";
>      uc->usb_desc       = &desc_net;
>      uc->handle_reset   = usb_net_handle_reset;
> 

Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>

^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: [Qemu-devel] [PATCH 01/19] usb-storage: fix possible memory leak and missing error message
  2014-09-18  9:32 ` [Qemu-devel] [PATCH 01/19] usb-storage: fix possible memory leak and missing error message arei.gonglei
@ 2014-09-18 10:17   ` Paolo Bonzini
  0 siblings, 0 replies; 43+ messages in thread
From: Paolo Bonzini @ 2014-09-18 10:17 UTC (permalink / raw)
  To: arei.gonglei, qemu-devel
  Cc: luonengjun, peter.huangpeng, weidong.huang, kraxel, armbru

Il 18/09/2014 11:32, arei.gonglei@huawei.com ha scritto:
> From: Gonglei <arei.gonglei@huawei.com>
> 
> When scsi_bus_legacy_add_drive() return NULL, meanwhile err will
> be not NULL, which will casue memory leak and missing error message.
> 
> Cc: Markus Armbruster <armbru@redhat.com>
> Signed-off-by: Gonglei <arei.gonglei@huawei.com>
> ---
>  hw/usb/dev-storage.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/hw/usb/dev-storage.c b/hw/usb/dev-storage.c
> index ae4efcb..f731b0a 100644
> --- a/hw/usb/dev-storage.c
> +++ b/hw/usb/dev-storage.c
> @@ -624,6 +624,8 @@ static int usb_msd_initfn_storage(USBDevice *dev)
>                                           s->conf.bootindex, dev->serial,
>                                           &err);
>      if (!scsi_dev) {
> +        error_report("%s", error_get_pretty(err));
> +        error_free(err);
>          return -1;
>      }
>      s->bus.qbus.allow_hotplug = 0;
> 

Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>

^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: [Qemu-devel] [PATCH 02/19] usb-bus: convert USBDeviceClass init to realize
  2014-09-18 10:08   ` Paolo Bonzini
@ 2014-09-18 10:19     ` Gonglei (Arei)
  0 siblings, 0 replies; 43+ messages in thread
From: Gonglei (Arei) @ 2014-09-18 10:19 UTC (permalink / raw)
  To: Paolo Bonzini, qemu-devel
  Cc: Luonengjun, Huangpeng (Peter), Huangweidong (C), kraxel, armbru

> From: Paolo Bonzini [mailto:pbonzini@redhat.com]
> Sent: Thursday, September 18, 2014 6:08 PM
> Subject: Re: [PATCH 02/19] usb-bus: convert USBDeviceClass init to realize
> 
> Il 18/09/2014 11:32, arei.gonglei@huawei.com ha scritto:
> > @@ -460,7 +460,7 @@ static void usb_serial_event(void *opaque, int event)
> >              break;
> >          case CHR_EVENT_OPENED:
> >              if (!s->dev.attached) {
> > -                usb_device_attach(&s->dev);
> > +                usb_device_attach(&s->dev, NULL);
> 
> After this patch, this stops printing the error if the attach fails.
> Please add qerror_report_err.
> 

Good catch. Will fix it in v2. 

Thanks a lot for your fast reviewing! :)

> >              }
> >              break;
> >          case CHR_EVENT_CLOSED:
> > @@ -489,7 +489,7 @@ static int usb_serial_initfn(USBDevice *dev)
> >      usb_serial_handle_reset(dev);
> >
> >      if (s->cs->be_open && !dev->attached) {
> > -        usb_device_attach(dev);
> > +        usb_device_attach(dev, NULL);
> 
> This too.  Please add qerror_report_err here too and, in this case,
> please make patch 12 pass the errp instead of using qerror_report_err.
> 
OK. Got it.

Best regards,
-Gonglei

> Paolo
> 
> >      }
> >      return 0;

^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: [Qemu-devel] [PATCH 02/19] usb-bus: convert USBDeviceClass init to realize
  2014-09-18 10:09   ` Paolo Bonzini
@ 2014-09-18 10:21     ` Gonglei (Arei)
  0 siblings, 0 replies; 43+ messages in thread
From: Gonglei (Arei) @ 2014-09-18 10:21 UTC (permalink / raw)
  To: Paolo Bonzini, qemu-devel
  Cc: Luonengjun, Huangpeng (Peter), Huangweidong (C), kraxel, armbru

> From: Paolo Bonzini [mailto:pbonzini@redhat.com]
> Sent: Thursday, September 18, 2014 6:09 PM
> Subject: Re: [PATCH 02/19] usb-bus: convert USBDeviceClass init to realize
> 
> Il 18/09/2014 11:32, arei.gonglei@huawei.com ha scritto:
> >  static void usb_msd_password_cb(void *opaque, int err)
> >  {
> >      MSDState *s = opaque;
> > +    Error *local_err = NULL;
> >
> > -    if (!err)
> > -        err = usb_device_attach(&s->dev);
> > +    if (!err) {
> > +        usb_device_attach(&s->dev, &local_err);
> > +    }
> >
> > -    if (err)
> > +    if (local_err) {
> > +        error_report("%s", error_get_pretty(local_err));
> 
> I think this should use qerror_report_err.
> 
OK.

Best regards,
-Gonglei

^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: [Qemu-devel] [PATCH 14/19] dev-hid: convert init to realize
  2014-09-18 10:15   ` Paolo Bonzini
@ 2014-09-18 10:23     ` Gonglei (Arei)
  0 siblings, 0 replies; 43+ messages in thread
From: Gonglei (Arei) @ 2014-09-18 10:23 UTC (permalink / raw)
  To: Paolo Bonzini, qemu-devel
  Cc: Luonengjun, Huangpeng (Peter), Huangweidong (C), kraxel, armbru

> From: Paolo Bonzini [mailto:pbonzini@redhat.com]
> Sent: Thursday, September 18, 2014 6:16 PM
> Subject: Re: [PATCH 14/19] dev-hid: convert init to realize
> 
> Il 18/09/2014 11:32, arei.gonglei@huawei.com ha scritto:
> > From: Gonglei <arei.gonglei@huawei.com>
> >
> > In this way, all the implementations now use
> > error_setg instead of error_report for reporting error.
> >
> > Signed-off-by: Gonglei <arei.gonglei@huawei.com>
> > ---
> >  hw/usb/dev-hid.c | 23 +++++++++++------------
> >  1 file changed, 11 insertions(+), 12 deletions(-)
> >
> > diff --git a/hw/usb/dev-hid.c b/hw/usb/dev-hid.c
> > index 67a57f1..7e9d2d6 100644
> > --- a/hw/usb/dev-hid.c
> > +++ b/hw/usb/dev-hid.c
> > @@ -582,7 +582,7 @@ static int usb_hid_initfn(USBDevice *dev, int kind)
> >      return 0;
> 
> Please change usb_hid_initfn to return void.
> 
OK.

> >  }
> >
> > -static int usb_tablet_initfn(USBDevice *dev)
> > +static void usb_tablet_realize(USBDevice *dev, Error **errp)
> >  {
> >      USBHIDState *us = DO_UPCAST(USBHIDState, dev, dev);
> >
> > @@ -594,22 +594,21 @@ static int usb_tablet_initfn(USBDevice *dev)
> >          dev->usb_desc = &desc_tablet2;
> >          break;
> >      default:
> > -        error_report("Invalid usb version %d for usb-tabler (must be 1 or
> 2)",
> > -                     us->usb_version);
> > -        return -1;
> > +        error_setg(errp, "Invalid usb version %d for usb-tablet "
> > +                   "(must be 1 or 2)", us->usb_version);
> 
> Missing return here.
> 
Good catch! Will fix it in v2. Thanks a lot!

Best regards,
-Gonglei

^ permalink raw reply	[flat|nested] 43+ messages in thread

end of thread, other threads:[~2014-09-18 10:24 UTC | newest]

Thread overview: 43+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-09-18  9:32 [Qemu-devel] [PATCH 00/19] usb: convert device init to realize arei.gonglei
2014-09-18  9:32 ` [Qemu-devel] [PATCH 01/19] usb-storage: fix possible memory leak and missing error message arei.gonglei
2014-09-18 10:17   ` Paolo Bonzini
2014-09-18  9:32 ` [Qemu-devel] [PATCH 02/19] usb-bus: convert USBDeviceClass init to realize arei.gonglei
2014-09-18 10:08   ` Paolo Bonzini
2014-09-18 10:19     ` Gonglei (Arei)
2014-09-18 10:09   ` Paolo Bonzini
2014-09-18 10:21     ` Gonglei (Arei)
2014-09-18  9:32 ` [Qemu-devel] [PATCH 03/19] usb-net: convert " arei.gonglei
2014-09-18 10:17   ` Paolo Bonzini
2014-09-18  9:32 ` [Qemu-devel] [PATCH 04/19] libusb: " arei.gonglei
2014-09-18 10:11   ` Paolo Bonzini
2014-09-18  9:32 ` [Qemu-devel] [PATCH 05/19] libusb: using error_report instead of fprintf arei.gonglei
2014-09-18 10:12   ` Paolo Bonzini
2014-09-18  9:32 ` [Qemu-devel] [PATCH 06/19] usb-hub: convert init to realize arei.gonglei
2014-09-18 10:12   ` Paolo Bonzini
2014-09-18  9:32 ` [Qemu-devel] [PATCH 07/19] dev-storage: " arei.gonglei
2014-09-18 10:13   ` Paolo Bonzini
2014-09-18  9:32 ` [Qemu-devel] [PATCH 08/19] dev-storage: usring error_report instead of fprintf/printf arei.gonglei
2014-09-18 10:13   ` Paolo Bonzini
2014-09-18  9:32 ` [Qemu-devel] [PATCH 09/19] dev-uas: convert init to realize arei.gonglei
2014-09-18 10:13   ` Paolo Bonzini
2014-09-18  9:32 ` [Qemu-devel] [PATCH 10/19] dev-uas: using error_report instead of fprintf arei.gonglei
2014-09-18 10:14   ` Paolo Bonzini
2014-09-18  9:32 ` [Qemu-devel] [PATCH 11/19] dev-bluetooth: convert init to realize arei.gonglei
2014-09-18 10:14   ` Paolo Bonzini
2014-09-18  9:32 ` [Qemu-devel] [PATCH 12/19] dev-serial: " arei.gonglei
2014-09-18 10:14   ` Paolo Bonzini
2014-09-18  9:32 ` [Qemu-devel] [PATCH 13/19] usb-ccid: " arei.gonglei
2014-09-18 10:14   ` Paolo Bonzini
2014-09-18  9:32 ` [Qemu-devel] [PATCH 14/19] dev-hid: " arei.gonglei
2014-09-18 10:15   ` Paolo Bonzini
2014-09-18 10:23     ` Gonglei (Arei)
2014-09-18  9:32 ` [Qemu-devel] [PATCH 15/19] dev-wacom: " arei.gonglei
2014-09-18 10:15   ` Paolo Bonzini
2014-09-18  9:32 ` [Qemu-devel] [PATCH 16/19] usb-audio: " arei.gonglei
2014-09-18 10:16   ` Paolo Bonzini
2014-09-18  9:32 ` [Qemu-devel] [PATCH 17/19] usb-redir: " arei.gonglei
2014-09-18 10:16   ` Paolo Bonzini
2014-09-18  9:32 ` [Qemu-devel] [PATCH 18/19] usb-mtp: " arei.gonglei
2014-09-18 10:16   ` Paolo Bonzini
2014-09-18  9:33 ` [Qemu-devel] [PATCH 19/19] usb-bus: remove "init" from USBDeviceClass struct arei.gonglei
2014-09-18 10:16   ` Paolo Bonzini

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.