Message ID | 1287484411-13611-3-git-send-email-alevy@redhat.com |
---|---|
State | New |
Headers | show |
> +USBDevice *usb_device_by_id(const char* id) > +{ > + USBBus *bus; > + DeviceState *qdev; > + USBDevice *dev; > + > + QTAILQ_FOREACH(bus,&busses, next) { > + qdev = qdev_find_recursive(&bus->qbus, id); > + if (qdev != NULL) { > + dev = DO_UPCAST(USBDevice, qdev, qdev); > + return dev; > + } > + } You don't need qdev_find_recursive here. Have a look at the usb_info() code to see how to loop over all usb devices. Then compare id with USBDevice->qdev.id. cheers, Gerd
diff --git a/hw/usb-bus.c b/hw/usb-bus.c index b692503..d732bd3 100644 --- a/hw/usb-bus.c +++ b/hw/usb-bus.c @@ -189,6 +189,22 @@ int usb_device_detach(USBDevice *dev) return 0; } +USBDevice *usb_device_by_id(const char* id) +{ + USBBus *bus; + DeviceState *qdev; + USBDevice *dev; + + QTAILQ_FOREACH(bus, &busses, next) { + qdev = qdev_find_recursive(&bus->qbus, id); + if (qdev != NULL) { + dev = DO_UPCAST(USBDevice, qdev, qdev); + return dev; + } + } + return NULL; +} + int usb_device_delete_addr(int busnr, int addr) { USBBus *bus; diff --git a/hw/usb.h b/hw/usb.h index 00d2802..e70fccd 100644 --- a/hw/usb.h +++ b/hw/usb.h @@ -317,6 +317,7 @@ void usb_unregister_port(USBBus *bus, USBPort *port); int usb_device_attach(USBDevice *dev); int usb_device_detach(USBDevice *dev); int usb_device_delete_addr(int busnr, int addr); +USBDevice *usb_device_by_id(const char* id); static inline USBBus *usb_bus_from_device(USBDevice *d) {