Patchwork [3/5] usb: Allow overriding of usb_desc at the device level

login
register
mail settings
Submitter Hans de Goede
Date Nov. 17, 2012, 11:47 a.m.
Message ID <1353152838-26886-4-git-send-email-hdegoede@redhat.com>
Download mbox | patch
Permalink /patch/199841/
State New
Headers show

Comments

Hans de Goede - Nov. 17, 2012, 11:47 a.m.
This allows devices to present a different set of descriptors based on
device properties.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
 hw/usb.h     | 1 +
 hw/usb/bus.c | 3 +++
 2 files changed, 4 insertions(+)

Patch

diff --git a/hw/usb.h b/hw/usb.h
index 58f812f..268e653 100644
--- a/hw/usb.h
+++ b/hw/usb.h
@@ -230,6 +230,7 @@  struct USBDevice {
     USBEndpoint ep_out[USB_MAX_ENDPOINTS];
 
     QLIST_HEAD(, USBDescString) strings;
+    const USBDesc *usb_desc; /* Overrides class usb_desc if not NULL */
     const USBDescDevice *device;
 
     int configuration;
diff --git a/hw/usb/bus.c b/hw/usb/bus.c
index 99aac7a..fe26998 100644
--- a/hw/usb/bus.c
+++ b/hw/usb/bus.c
@@ -166,6 +166,9 @@  const char *usb_device_get_product_desc(USBDevice *dev)
 const USBDesc *usb_device_get_usb_desc(USBDevice *dev)
 {
     USBDeviceClass *klass = USB_DEVICE_GET_CLASS(dev);
+    if (dev->usb_desc) {
+        return dev->usb_desc;
+    }
     return klass->usb_desc;
 }