USB: add read support to usb-serial/../new_id
authorBjørn Mork <bjorn@mork.no>
Sun, 13 May 2012 10:35:00 +0000 (12:35 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 14 May 2012 16:30:40 +0000 (09:30 -0700)
Keep the usb-serial support for dynamic IDs in sync with the usb
support.  This enables readout of dynamic device IDs for
usb-serial drivers.  Common code is exported from the usb core
system and reused by the usb-serial bus driver.

Signed-off-by: Bjørn Mork <bjorn@mork.no>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/usb/core/driver.c
drivers/usb/serial/bus.c
include/linux/usb.h

index 69919b25777580bc79d397a0ab80bf9cd5260a86..f6f81c85c5cfb6e0c39953a62f87587cceccb65c 100644 (file)
@@ -79,13 +79,12 @@ ssize_t usb_store_new_id(struct usb_dynids *dynids,
 }
 EXPORT_SYMBOL_GPL(usb_store_new_id);
 
-static ssize_t show_dynids(struct device_driver *driver, char *buf)
+ssize_t usb_show_dynids(struct usb_dynids *dynids, char *buf)
 {
        struct usb_dynid *dynid;
-       struct usb_driver *usb_drv = to_usb_driver(driver);
        size_t count = 0;
 
-       list_for_each_entry(dynid, &usb_drv->dynids.list, node)
+       list_for_each_entry(dynid, &dynids->list, node)
                if (dynid->id.bInterfaceClass != 0)
                        count += scnprintf(&buf[count], PAGE_SIZE - count, "%04x %04x %02x\n",
                                           dynid->id.idVendor, dynid->id.idProduct,
@@ -95,6 +94,14 @@ static ssize_t show_dynids(struct device_driver *driver, char *buf)
                                           dynid->id.idVendor, dynid->id.idProduct);
        return count;
 }
+EXPORT_SYMBOL_GPL(usb_show_dynids);
+
+static ssize_t show_dynids(struct device_driver *driver, char *buf)
+{
+       struct usb_driver *usb_drv = to_usb_driver(driver);
+
+       return usb_show_dynids(&usb_drv->dynids, buf);
+}
 
 static ssize_t store_new_id(struct device_driver *driver,
                            const char *buf, size_t count)
index ed8adb052ca74f136a14a423dea5cbe397c4d381..f398d1e34474c34084b43dac6702a6378f71a970 100644 (file)
@@ -124,8 +124,15 @@ static ssize_t store_new_id(struct device_driver *driver,
        return retval;
 }
 
+static ssize_t show_dynids(struct device_driver *driver, char *buf)
+{
+       struct usb_serial_driver *usb_drv = to_usb_serial_driver(driver);
+
+       return usb_show_dynids(&usb_drv->dynids, buf);
+}
+
 static struct driver_attribute drv_attrs[] = {
-       __ATTR(new_id, S_IWUSR, NULL, store_new_id),
+       __ATTR(new_id, S_IRUGO | S_IWUSR, show_dynids, store_new_id),
        __ATTR_NULL,
 };
 
index 5483cd70390b780a9deb1df07164d9e628727239..14933451d21d7fa49860d306961200611853753f 100644 (file)
@@ -790,6 +790,8 @@ extern ssize_t usb_store_new_id(struct usb_dynids *dynids,
                                struct device_driver *driver,
                                const char *buf, size_t count);
 
+extern ssize_t usb_show_dynids(struct usb_dynids *dynids, char *buf);
+
 /**
  * struct usbdrv_wrap - wrapper for driver-model structure
  * @driver: The driver-model core driver structure.