Patchwork [2/3] usb: add public usb_device_by_id

login
register
mail settings
Submitter Alon Levy
Date Oct. 21, 2010, 6:36 a.m.
Message ID <1287642991-21114-3-git-send-email-alevy@redhat.com>
Download mbox | patch
Permalink /patch/68522/
State New
Headers show

Comments

Alon Levy - Oct. 21, 2010, 6:36 a.m.
---
 hw/usb-bus.c |   16 ++++++++++++++++
 hw/usb.h     |    1 +
 2 files changed, 17 insertions(+), 0 deletions(-)

Patch

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)
 {