Skip to contentSkip to conversation

usb: Fix usb-bt-dongle segfault.

PATCH Superseded Hani Benhabiles 2 participants 5 messages Jun 11, 2014 – Jun 17, 2014

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 usb: Fix usb-bt-dongle segfault.

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

---

Not sure about the exact policy of qemu-stable. CC'ing it as this bug results in a segfault.

 hw/usb/dev-bluetooth.c | 6 ++++++
 1 file changed, 6 insertions(+)
hw/usb/dev-bluetooth.c +6 -0
index a9661d2..6d02343 100644
@@ -506,6 +506,12 @@ static int usb_bt_initfn(USBDevice *dev)
 
     usb_desc_create_serial(dev);
     usb_desc_init(dev);
+    s->dev.opaque = s;
+    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;
Signature · 1 line
1.8.3.2
#1 lore raw

Il 11/06/2014 19:25, Hani Benhabiles ha scritto:

Quoted 17 lines

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

---

Not sure about the exact policy of qemu-stable. CC'ing it as this bug results in a segfault.

 hw/usb/dev-bluetooth.c | 6 ++++++
 1 file changed, 6 insertions(+)
hw/usb/dev-bluetooth.c +0 -0
index a9661d2..6d02343 100644

hw/usb/dev-bluetooth.c static int usb_bt_initfn(USBDevice *dev) · line 514

Quoted 9 lines
hw/usb/dev-bluetooth.c +6 -0
@@ -506,6 +506,12 @@ static int usb_bt_initfn(USBDevice *dev)
 
     usb_desc_create_serial(dev);
     usb_desc_init(dev);
+    s->dev.opaque = s;
+    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);

All lines but the s->hci assignment should be removed from usb_bt_init too.

As to s->hci, I suggest inlining usb_create_simple into usb_bt_init, and initializing s->hci there before doing the qdev_init() call.

Then here you can wrap the assignment under "if (!s->hci)".

Thanks for TLC of this little-used piece of code.

Paolo

Quoted 4 lines
hw/usb/dev-bluetooth.c +0 -0
     s->intr = usb_ep_get(dev, USB_TOKEN_IN, USB_EVT_EP);
 
     return 0;
#2 lore raw
Quoted 31 lines · Paolo Bonzini

Il 11/06/2014 19:25, Hani Benhabiles ha scritto:

Quoted 17 lines

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

---

Not sure about the exact policy of qemu-stable. CC'ing it as this bug results in a segfault.

hw/usb/dev-bluetooth.c | 6 ++++++

1 file changed, 6 insertions(+)
hw/usb/dev-bluetooth.c +0 -0
index a9661d2..6d02343 100644

hw/usb/dev-bluetooth.c static int usb_bt_initfn(USBDevice *dev) · line 514

Quoted 9 lines
hw/usb/dev-bluetooth.c +6 -0
@@ -506,6 +506,12 @@ static int usb_bt_initfn(USBDevice *dev)
 
    usb_desc_create_serial(dev);
    usb_desc_init(dev);
+    s->dev.opaque = s;
+    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);

All lines but the s->hci assignment should be removed from usb_bt_init too.

Quoted 4 lines

As to s->hci, I suggest inlining usb_create_simple into usb_bt_init, and initializing s->hci there before doing the qdev_init() call.

Then here you can wrap the assignment under "if (!s->hci)".

I am afraid I don't quite understand what you want to achieve with this and why.

Could you please explain how is usb_bt_init() relevant to this case ?

Thanks

Quoted 10 lines

Thanks for TLC of this little-used piece of code.

Paolo

Quoted 4 lines
hw/usb/dev-bluetooth.c +0 -0
    s->intr = usb_ep_get(dev, USB_TOKEN_IN, USB_EVT_EP);
 
    return 0;
#3 lore raw

Il 15/06/2014 23:37, Hani Benhabiles ha scritto:

Quoted 18 lines
Quoted 18 lines
Quoted 5 lines
hw/usb/dev-bluetooth.c +0 -0
index a9661d2..6d02343 100644

hw/usb/dev-bluetooth.c static int usb_bt_initfn(USBDevice *dev) · line 514

Quoted 9 lines
hw/usb/dev-bluetooth.c +6 -0
@@ -506,6 +506,12 @@ static int usb_bt_initfn(USBDevice *dev)
 
    usb_desc_create_serial(dev);
    usb_desc_init(dev);
+    s->dev.opaque = s;
+    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);

All lines but the s->hci assignment should be removed from usb_bt_init too.

Quoted 8 lines
Quoted 4 lines

As to s->hci, I suggest inlining usb_create_simple into usb_bt_init, and initializing s->hci there before doing the qdev_init() call.

Then here you can wrap the assignment under "if (!s->hci)".

I am afraid I don't quite understand what you want to achieve with this and why.

Could you please explain how is usb_bt_init() relevant to this case ?

usb_bt_init() ends up calling usb_bt_initfn(), via usb_create_simple. So if you add code to usb_bt_initfn() you can remove the corresponding lines in usb_bt_init().

Paolo

#4 lore raw
Quoted 24 lines · Paolo Bonzini

Il 15/06/2014 23:37, Hani Benhabiles ha scritto:

Quoted 23 lines
Quoted 22 lines
Quoted 5 lines
hw/usb/dev-bluetooth.c +0 -0
index a9661d2..6d02343 100644

hw/usb/dev-bluetooth.c static int usb_bt_initfn(USBDevice *dev) · line 514

Quoted 9 lines
hw/usb/dev-bluetooth.c +6 -0
@@ -506,6 +506,12 @@ static int usb_bt_initfn(USBDevice *dev)
 
   usb_desc_create_serial(dev);
   usb_desc_init(dev);
+    s->dev.opaque = s;
+    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);

All lines but the s->hci assignment should be removed from usb_bt_init too.

As to s->hci, I suggest inlining usb_create_simple into usb_bt_init, and initializing s->hci there before doing the qdev_init() call.

Then here you can wrap the assignment under "if (!s->hci)".

Quoted 7 lines
Quoted 3 lines

I am afraid I don't quite understand what you want to achieve with this and why.

Could you please explain how is usb_bt_init() relevant to this case ?

usb_bt_init() ends up calling usb_bt_initfn(), via usb_create_simple. So if you add code to usb_bt_initfn() you can remove the corresponding lines in usb_bt_init().

Thanks for the clarification. I forgot about -usbdevice bt, will send v2 shortly.