qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCHv2] usb: Fix usb-bt-dongle initialization.
@ 2014-06-17 23:23 Hani Benhabiles
  2014-06-18  9:32 ` Paolo Bonzini
  2014-06-19  9:38 ` Gerd Hoffmann
  0 siblings, 2 replies; 3+ messages in thread
From: Hani Benhabiles @ 2014-06-17 23:23 UTC (permalink / raw)
  To: qemu-devel, qemu-trivial; +Cc: pbonzini, kraxel, qemu-stable

Due to an incomplete initialization, adding a usb-bt-dongle device through HMP
or QMP will cause a segmentation fault.

Signed-off-by: Hani Benhabiles <hani@linux.com>
Suggested-by: Paolo Bonzini <pbonzini@redhat.com>
---

Compared to v1:
* Remove duplicate code from usb_bt_init() and inline usb_create_simple() call.
* usb_bt_initfn() check for s->hci.

 hw/usb/dev-bluetooth.c | 24 ++++++++++++++++--------
 1 file changed, 16 insertions(+), 8 deletions(-)

diff --git a/hw/usb/dev-bluetooth.c b/hw/usb/dev-bluetooth.c
index a9661d2..a76e581 100644
--- a/hw/usb/dev-bluetooth.c
+++ b/hw/usb/dev-bluetooth.c
@@ -19,6 +19,7 @@
  */
 
 #include "qemu-common.h"
+#include "qemu/error-report.h"
 #include "hw/usb.h"
 #include "hw/usb/desc.h"
 #include "sysemu/bt.h"
@@ -506,6 +507,14 @@ static int usb_bt_initfn(USBDevice *dev)
 
     usb_desc_create_serial(dev);
     usb_desc_init(dev);
+    s->dev.opaque = s;
+    if (!s->hci) {
+        s->hci = bt_new_hci(qemu_find_bt_vlan(0));
+    }
+    s->hci->opaque = s;
+    s->hci->evt_recv = usb_bt_out_hci_packet_event;
+    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;
@@ -516,6 +525,7 @@ static USBDevice *usb_bt_init(USBBus *bus, const char *cmdline)
     USBDevice *dev;
     struct USBBtState *s;
     HCIInfo *hci;
+    const char *name = "usb-bt-dongle";
 
     if (*cmdline) {
         hci = hci_init(cmdline);
@@ -525,19 +535,17 @@ static USBDevice *usb_bt_init(USBBus *bus, const char *cmdline)
 
     if (!hci)
         return NULL;
-    dev = usb_create_simple(bus, "usb-bt-dongle");
+    dev = usb_create(bus, name);
     if (!dev) {
+        error_report("Failed to create USB device '%s'", name);
         return NULL;
     }
     s = DO_UPCAST(struct USBBtState, dev, dev);
-    s->dev.opaque = s;
-
     s->hci = hci;
-    s->hci->opaque = s;
-    s->hci->evt_recv = usb_bt_out_hci_packet_event;
-    s->hci->acl_recv = usb_bt_out_hci_packet_acl;
-
-    usb_bt_handle_reset(&s->dev);
+    if (qdev_init(&dev->qdev) < 0) {
+        error_report("Failed to initialize USB device '%s'", name);
+        return NULL;
+    }
 
     return dev;
 }
-- 
1.8.3.2

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

* Re: [Qemu-devel] [PATCHv2] usb: Fix usb-bt-dongle initialization.
  2014-06-17 23:23 [Qemu-devel] [PATCHv2] usb: Fix usb-bt-dongle initialization Hani Benhabiles
@ 2014-06-18  9:32 ` Paolo Bonzini
  2014-06-19  9:38 ` Gerd Hoffmann
  1 sibling, 0 replies; 3+ messages in thread
From: Paolo Bonzini @ 2014-06-18  9:32 UTC (permalink / raw)
  To: Hani Benhabiles, qemu-devel, qemu-trivial; +Cc: kraxel, qemu-stable

Il 18/06/2014 01:23, Hani Benhabiles ha scritto:
> Due to an incomplete initialization, adding a usb-bt-dongle device through HMP
> or QMP will cause a segmentation fault.
>
> Signed-off-by: Hani Benhabiles <hani@linux.com>
> Suggested-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>
> Compared to v1:
> * Remove duplicate code from usb_bt_init() and inline usb_create_simple() call.
> * usb_bt_initfn() check for s->hci.
>
>  hw/usb/dev-bluetooth.c | 24 ++++++++++++++++--------
>  1 file changed, 16 insertions(+), 8 deletions(-)
>
> diff --git a/hw/usb/dev-bluetooth.c b/hw/usb/dev-bluetooth.c
> index a9661d2..a76e581 100644
> --- a/hw/usb/dev-bluetooth.c
> +++ b/hw/usb/dev-bluetooth.c
> @@ -19,6 +19,7 @@
>   */
>
>  #include "qemu-common.h"
> +#include "qemu/error-report.h"
>  #include "hw/usb.h"
>  #include "hw/usb/desc.h"
>  #include "sysemu/bt.h"
> @@ -506,6 +507,14 @@ static int usb_bt_initfn(USBDevice *dev)
>
>      usb_desc_create_serial(dev);
>      usb_desc_init(dev);
> +    s->dev.opaque = s;
> +    if (!s->hci) {
> +        s->hci = bt_new_hci(qemu_find_bt_vlan(0));
> +    }
> +    s->hci->opaque = s;
> +    s->hci->evt_recv = usb_bt_out_hci_packet_event;
> +    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;
> @@ -516,6 +525,7 @@ static USBDevice *usb_bt_init(USBBus *bus, const char *cmdline)
>      USBDevice *dev;
>      struct USBBtState *s;
>      HCIInfo *hci;
> +    const char *name = "usb-bt-dongle";
>
>      if (*cmdline) {
>          hci = hci_init(cmdline);
> @@ -525,19 +535,17 @@ static USBDevice *usb_bt_init(USBBus *bus, const char *cmdline)
>
>      if (!hci)
>          return NULL;
> -    dev = usb_create_simple(bus, "usb-bt-dongle");
> +    dev = usb_create(bus, name);
>      if (!dev) {
> +        error_report("Failed to create USB device '%s'", name);
>          return NULL;
>      }
>      s = DO_UPCAST(struct USBBtState, dev, dev);
> -    s->dev.opaque = s;
> -
>      s->hci = hci;
> -    s->hci->opaque = s;
> -    s->hci->evt_recv = usb_bt_out_hci_packet_event;
> -    s->hci->acl_recv = usb_bt_out_hci_packet_acl;
> -
> -    usb_bt_handle_reset(&s->dev);
> +    if (qdev_init(&dev->qdev) < 0) {
> +        error_report("Failed to initialize USB device '%s'", name);
> +        return NULL;
> +    }
>
>      return dev;
>  }
>

Perfect!  My comment about inlining usb_create_simple was a bit cryptic, 
but you got what I meant.  Thanks. :)

Not really trivial, but you've CCed Gerd too.

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

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

* Re: [Qemu-devel] [PATCHv2] usb: Fix usb-bt-dongle initialization.
  2014-06-17 23:23 [Qemu-devel] [PATCHv2] usb: Fix usb-bt-dongle initialization Hani Benhabiles
  2014-06-18  9:32 ` Paolo Bonzini
@ 2014-06-19  9:38 ` Gerd Hoffmann
  1 sibling, 0 replies; 3+ messages in thread
From: Gerd Hoffmann @ 2014-06-19  9:38 UTC (permalink / raw)
  To: Hani Benhabiles; +Cc: qemu-trivial, pbonzini, qemu-devel, qemu-stable

On Mi, 2014-06-18 at 00:23 +0100, Hani Benhabiles wrote:
> Due to an incomplete initialization, adding a usb-bt-dongle device through HMP
> or QMP will cause a segmentation fault.

Added to usb patch queue.

thanks,
  Gerd

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

end of thread, other threads:[~2014-06-19  9:39 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-06-17 23:23 [Qemu-devel] [PATCHv2] usb: Fix usb-bt-dongle initialization Hani Benhabiles
2014-06-18  9:32 ` Paolo Bonzini
2014-06-19  9:38 ` Gerd Hoffmann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).