Driver Core: usb: add nodename support for usb drivers.
authorKay Sievers <kay.sievers@vrfy.org>
Thu, 30 Apr 2009 13:23:42 +0000 (15:23 +0200)
committerGreg Kroah-Hartman <gregkh@suse.de>
Tue, 16 Jun 2009 04:30:25 +0000 (21:30 -0700)
This adds support for USB drivers to report their requested nodename to
userspace.  It also updates a number of USB drivers to provide the
needed subdirectory and device name to be used for them.

Signed-off-by: Kay Sievers <kay.sievers@vrfy.org>
Signed-off-by: Jan Blunck <jblunck@suse.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
drivers/hid/usbhid/hiddev.c
drivers/media/video/dabusb.c
drivers/usb/class/usblp.c
drivers/usb/core/file.c
drivers/usb/core/usb.c
drivers/usb/misc/iowarrior.c
drivers/usb/misc/legousbtower.c
include/linux/usb.h

index e9b436d2d94434c17fb1030d50528341edd71659..9e9421525fb9125fa962c2266550f67545855b39 100644 (file)
@@ -850,8 +850,14 @@ static const struct file_operations hiddev_fops = {
 #endif
 };
 
+static char *hiddev_nodename(struct device *dev)
+{
+       return kasprintf(GFP_KERNEL, "usb/%s", dev_name(dev));
+}
+
 static struct usb_class_driver hiddev_class = {
        .name =         "hiddev%d",
+       .nodename =     hiddev_nodename,
        .fops =         &hiddev_fops,
        .minor_base =   HIDDEV_MINOR_BASE,
 };
@@ -955,7 +961,6 @@ static int hiddev_usbd_probe(struct usb_interface *intf,
        return -ENODEV;
 }
 
-
 static /* const */ struct usb_driver hiddev_driver = {
        .name =         "hiddev",
        .probe =        hiddev_usbd_probe,
index ba3709bec3f0a42d84d34d2ba88e8bd62feb104a..ec2f45dde1643d72a849aa15004bbde91a1ff2c3 100644 (file)
@@ -747,8 +747,14 @@ static const struct file_operations dabusb_fops =
        .release =      dabusb_release,
 };
 
+static char *dabusb_nodename(struct device *dev)
+{
+       return kasprintf(GFP_KERNEL, "usb/%s", dev_name(dev));
+}
+
 static struct usb_class_driver dabusb_class = {
        .name =         "dabusb%d",
+       .nodename =     dabusb_nodename,
        .fops =         &dabusb_fops,
        .minor_base =   DABUSB_MINOR,
 };
index d2747a49b9744bacf2962abbe2ea1b8bd3b087b5..26c09f0257dbeff29a9c8f25f39eaf15453570c0 100644 (file)
@@ -1057,8 +1057,14 @@ static const struct file_operations usblp_fops = {
        .release =      usblp_release,
 };
 
+static char *usblp_nodename(struct device *dev)
+{
+       return kasprintf(GFP_KERNEL, "usb/%s", dev_name(dev));
+}
+
 static struct usb_class_driver usblp_class = {
        .name =         "lp%d",
+       .nodename =     usblp_nodename,
        .fops =         &usblp_fops,
        .minor_base =   USBLP_MINOR_BASE,
 };
index 997e659ff693eeb5ed083c2a8e76bdce76a33f97..5cef88929b3ee609af666c0d3e18772be10b1039 100644 (file)
@@ -67,6 +67,16 @@ static struct usb_class {
        struct class *class;
 } *usb_class;
 
+static char *usb_nodename(struct device *dev)
+{
+       struct usb_class_driver *drv;
+
+       drv = dev_get_drvdata(dev);
+       if (!drv || !drv->nodename)
+               return NULL;
+       return drv->nodename(dev);
+}
+
 static int init_usb_class(void)
 {
        int result = 0;
@@ -90,6 +100,7 @@ static int init_usb_class(void)
                kfree(usb_class);
                usb_class = NULL;
        }
+       usb_class->class->nodename = usb_nodename;
 
 exit:
        return result;
@@ -198,7 +209,7 @@ int usb_register_dev(struct usb_interface *intf,
        else
                temp = name;
        intf->usb_dev = device_create(usb_class->class, &intf->dev,
-                                     MKDEV(USB_MAJOR, minor), NULL,
+                                     MKDEV(USB_MAJOR, minor), class_driver,
                                      "%s", temp);
        if (IS_ERR(intf->usb_dev)) {
                down_write(&minor_rwsem);
index 7eee400d3e32cac6486cb7809234792012ed4689..927a27dd2f853cd84eeabd2660661bee481bdbc2 100644 (file)
@@ -305,10 +305,21 @@ static struct dev_pm_ops usb_device_pm_ops = {
 
 #endif /* CONFIG_PM */
 
+
+static char *usb_nodename(struct device *dev)
+{
+       struct usb_device *usb_dev;
+
+       usb_dev = to_usb_device(dev);
+       return kasprintf(GFP_KERNEL, "bus/usb/%03d/%03d",
+                        usb_dev->bus->busnum, usb_dev->devnum);
+}
+
 struct device_type usb_device_type = {
        .name =         "usb_device",
        .release =      usb_release_dev,
        .uevent =       usb_dev_uevent,
+       .nodename =     usb_nodename,
        .pm =           &usb_device_pm_ops,
 };
 
index a4ef77ef917d9bc6be7f2b29bff6a58ba6d105e1..3c5fe5cee05abab286dcc2f00d6cc1f70b031e06 100644 (file)
@@ -726,12 +726,18 @@ static const struct file_operations iowarrior_fops = {
        .poll = iowarrior_poll,
 };
 
+static char *iowarrior_nodename(struct device *dev)
+{
+       return kasprintf(GFP_KERNEL, "usb/%s", dev_name(dev));
+}
+
 /*
  * usb class driver info in order to get a minor number from the usb core,
  * and to have the device registered with devfs and the driver core
  */
 static struct usb_class_driver iowarrior_class = {
        .name = "iowarrior%d",
+       .nodename = iowarrior_nodename,
        .fops = &iowarrior_fops,
        .minor_base = IOWARRIOR_MINOR_BASE,
 };
index ab0f3226158b0d6ed735c041931a6b80ae869afb..c1e2433f640d133da219152b7f8ad7389ac51471 100644 (file)
@@ -266,12 +266,18 @@ static const struct file_operations tower_fops = {
        .llseek =       tower_llseek,
 };
 
+static char *legousbtower_nodename(struct device *dev)
+{
+       return kasprintf(GFP_KERNEL, "usb/%s", dev_name(dev));
+}
+
 /*
  * usb class driver info in order to get a minor number from the usb core,
  * and to have the device registered with the driver core
  */
 static struct usb_class_driver tower_class = {
        .name =         "legousbtower%d",
+       .nodename =     legousbtower_nodename,
        .fops =         &tower_fops,
        .minor_base =   LEGO_USB_TOWER_MINOR_BASE,
 };
index 3aa2cd1f8d082fd699a5fcfb672e2dd555ea7dcc..34cdfcac4555b580205a0ba0831b8c693f15fe38 100644 (file)
@@ -869,6 +869,8 @@ struct usb_driver {
  * struct usb_device_driver - identifies USB device driver to usbcore
  * @name: The driver name should be unique among USB drivers,
  *     and should normally be the same as the module name.
+ * @nodename: Callback to provide a naming hint for a possible
+ *     device node to create.
  * @probe: Called to see if the driver is willing to manage a particular
  *     device.  If it is, probe returns zero and uses dev_set_drvdata()
  *     to associate driver-specific data with the device.  If unwilling
@@ -912,6 +914,7 @@ extern struct bus_type usb_bus_type;
  */
 struct usb_class_driver {
        char *name;
+       char *(*nodename)(struct device *dev);
        const struct file_operations *fops;
        int minor_base;
 };