usb: Fix usb-bt-dongle initialization.
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> Reviewed-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
This commit is contained in:
parent
35e83d10f2
commit
c340a284f3
|
@ -19,6 +19,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "qemu-common.h"
|
#include "qemu-common.h"
|
||||||
|
#include "qemu/error-report.h"
|
||||||
#include "hw/usb.h"
|
#include "hw/usb.h"
|
||||||
#include "hw/usb/desc.h"
|
#include "hw/usb/desc.h"
|
||||||
#include "sysemu/bt.h"
|
#include "sysemu/bt.h"
|
||||||
|
@ -506,6 +507,14 @@ static int usb_bt_initfn(USBDevice *dev)
|
||||||
|
|
||||||
usb_desc_create_serial(dev);
|
usb_desc_create_serial(dev);
|
||||||
usb_desc_init(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);
|
s->intr = usb_ep_get(dev, USB_TOKEN_IN, USB_EVT_EP);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -516,6 +525,7 @@ static USBDevice *usb_bt_init(USBBus *bus, const char *cmdline)
|
||||||
USBDevice *dev;
|
USBDevice *dev;
|
||||||
struct USBBtState *s;
|
struct USBBtState *s;
|
||||||
HCIInfo *hci;
|
HCIInfo *hci;
|
||||||
|
const char *name = "usb-bt-dongle";
|
||||||
|
|
||||||
if (*cmdline) {
|
if (*cmdline) {
|
||||||
hci = hci_init(cmdline);
|
hci = hci_init(cmdline);
|
||||||
|
@ -525,19 +535,17 @@ static USBDevice *usb_bt_init(USBBus *bus, const char *cmdline)
|
||||||
|
|
||||||
if (!hci)
|
if (!hci)
|
||||||
return NULL;
|
return NULL;
|
||||||
dev = usb_create_simple(bus, "usb-bt-dongle");
|
dev = usb_create(bus, name);
|
||||||
if (!dev) {
|
if (!dev) {
|
||||||
|
error_report("Failed to create USB device '%s'", name);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
s = DO_UPCAST(struct USBBtState, dev, dev);
|
s = DO_UPCAST(struct USBBtState, dev, dev);
|
||||||
s->dev.opaque = s;
|
|
||||||
|
|
||||||
s->hci = hci;
|
s->hci = hci;
|
||||||
s->hci->opaque = s;
|
if (qdev_init(&dev->qdev) < 0) {
|
||||||
s->hci->evt_recv = usb_bt_out_hci_packet_event;
|
error_report("Failed to initialize USB device '%s'", name);
|
||||||
s->hci->acl_recv = usb_bt_out_hci_packet_acl;
|
return NULL;
|
||||||
|
}
|
||||||
usb_bt_handle_reset(&s->dev);
|
|
||||||
|
|
||||||
return dev;
|
return dev;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue