[RFC] USB: let both new_id and remove_id show dynamic id list

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This enables the current list of dynamic IDs to be read out through
either new_id or remove_id.

Signed-off-by: Bjørn Mork <bjorn@xxxxxxx>
---

> BTW, another wishlist item is the ability to view the dynamic
> device list.  Any objections against providing a read method
> for the new_id (and maybe also remove_id) file?

So, how about something like this?  Bad idea?  Good idea?

The background for this is not only my failing memory, but that there
are userspace tools (usb_modeswitch is one example) which will add
device IDs to drivers on behalf of the user. Being able to read out
the list is very useful in such cases.


Bjørn


 drivers/usb/core/driver.c |   16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/core/driver.c b/drivers/usb/core/driver.c
index 112a7ae..629b9c0 100644
--- a/drivers/usb/core/driver.c
+++ b/drivers/usb/core/driver.c
@@ -79,6 +79,18 @@ 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)
+{
+	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)
+		count += scnprintf(&buf[count], PAGE_SIZE - count, "%04x %04x\n",
+				   dynid->id.idVendor, dynid->id.idProduct);
+	return count;
+}
+
 static ssize_t store_new_id(struct device_driver *driver,
 			    const char *buf, size_t count)
 {
@@ -86,7 +98,7 @@ static ssize_t store_new_id(struct device_driver *driver,
 
 	return usb_store_new_id(&usb_drv->dynids, driver, buf, count);
 }
-static DRIVER_ATTR(new_id, S_IWUSR, NULL, store_new_id);
+static DRIVER_ATTR(new_id, S_IRUGO | S_IWUSR, show_dynids, store_new_id);
 
 /**
  * store_remove_id - remove a USB device ID from this driver
@@ -127,7 +139,7 @@ store_remove_id(struct device_driver *driver, const char *buf, size_t count)
 		return retval;
 	return count;
 }
-static DRIVER_ATTR(remove_id, S_IWUSR, NULL, store_remove_id);
+static DRIVER_ATTR(remove_id, S_IRUGO | S_IWUSR, show_dynids, store_remove_id);
 
 static int usb_create_newid_files(struct usb_driver *usb_drv)
 {
-- 
1.7.10

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux