Skip to content

Commit

Permalink
USB: add read support to usb-serial/../new_id
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Bjørn Mork authored and Greg Kroah-Hartman committed May 14, 2012
1 parent e6bbcef commit ef206f3
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
13 changes: 10 additions & 3 deletions drivers/usb/core/driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
Expand Down
9 changes: 8 additions & 1 deletion drivers/usb/serial/bus.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

Expand Down
2 changes: 2 additions & 0 deletions include/linux/usb.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit ef206f3

Please sign in to comment.