]> err.no Git - linux-2.6/commitdiff
USB: uevent environment key fix
authorAlan Stern <stern@rowland.harvard.edu>
Tue, 6 Nov 2007 20:01:52 +0000 (15:01 -0500)
committerGreg Kroah-Hartman <gregkh@suse.de>
Wed, 28 Nov 2007 21:58:35 +0000 (13:58 -0800)
This patch (as1010) was written by both Kay Sievers and me.  It solves
the problem of duplicated keys in USB uevent structures by refactoring
the uevent subroutines, taking advantage of the way the hotplug core
calls uevent handlers for the device's bus and for the device's type.
Keys needed for both USB-device and USB-interface events are added in
usb_uevent(), which is the bus handler.  Keys appropriate only for
USB-device or USB-interface events are added in usb_dev_uevent() or
usb_if_uevent() respectively, the type handlers.

In addition, unnecessary tests for NULL pointers are removed as are
duplicated debugging log statements.

Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
Cc: Kay Sievers <kay.sievers@vrfy.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
drivers/usb/core/driver.c
drivers/usb/core/message.c
drivers/usb/core/usb.c

index 8586817698ad8db8f9abbee331075eef2c884077..c51f8e9312e055222f2c473039d7ffb19eb45451 100644 (file)
@@ -585,9 +585,6 @@ static int usb_uevent(struct device *dev, struct kobj_uevent_env *env)
 {
        struct usb_device *usb_dev;
 
-       if (!dev)
-               return -ENODEV;
-
        /* driver is often null here; dev_dbg() would oops */
        pr_debug ("usb %s: uevent\n", dev->bus_id);
 
@@ -631,14 +628,6 @@ static int usb_uevent(struct device *dev, struct kobj_uevent_env *env)
                           usb_dev->descriptor.bDeviceProtocol))
                return -ENOMEM;
 
-       if (add_uevent_var(env, "BUSNUM=%03d",
-                          usb_dev->bus->busnum))
-               return -ENOMEM;
-
-       if (add_uevent_var(env, "DEVNUM=%03d",
-                          usb_dev->devnum))
-               return -ENOMEM;
-
        return 0;
 }
 
index 40fd39de5bf972eea93f8f2de8d02e6f0ae1d5c2..fcd40ecbeecce3276a8a1ecb31a0f204c1bf54f5 100644 (file)
@@ -1346,34 +1346,10 @@ static int usb_if_uevent(struct device *dev, struct kobj_uevent_env *env)
        struct usb_interface *intf;
        struct usb_host_interface *alt;
 
-       if (!dev)
-               return -ENODEV;
-
-       /* driver is often null here; dev_dbg() would oops */
-       pr_debug ("usb %s: uevent\n", dev->bus_id);
-
        intf = to_usb_interface(dev);
        usb_dev = interface_to_usbdev(intf);
        alt = intf->cur_altsetting;
 
-#ifdef CONFIG_USB_DEVICEFS
-       if (add_uevent_var(env, "DEVICE=/proc/bus/usb/%03d/%03d",
-                          usb_dev->bus->busnum, usb_dev->devnum))
-               return -ENOMEM;
-#endif
-
-       if (add_uevent_var(env, "PRODUCT=%x/%x/%x",
-                          le16_to_cpu(usb_dev->descriptor.idVendor),
-                          le16_to_cpu(usb_dev->descriptor.idProduct),
-                          le16_to_cpu(usb_dev->descriptor.bcdDevice)))
-               return -ENOMEM;
-
-       if (add_uevent_var(env, "TYPE=%d/%d/%d",
-                          usb_dev->descriptor.bDeviceClass,
-                          usb_dev->descriptor.bDeviceSubClass,
-                          usb_dev->descriptor.bDeviceProtocol))
-               return -ENOMEM;
-
        if (add_uevent_var(env, "INTERFACE=%d/%d/%d",
                   alt->desc.bInterfaceClass,
                   alt->desc.bInterfaceSubClass,
index c4a6f1095b8b636f89e80267713b0c35fb3018a7..8f142370103d48400d3adb6cb6b6f36eab5e4070 100644 (file)
@@ -192,9 +192,34 @@ static void usb_release_dev(struct device *dev)
        kfree(udev);
 }
 
+#ifdef CONFIG_HOTPLUG
+static int usb_dev_uevent(struct device *dev, struct kobj_uevent_env *env)
+{
+       struct usb_device *usb_dev;
+
+       usb_dev = to_usb_device(dev);
+
+       if (add_uevent_var(env, "BUSNUM=%03d", usb_dev->bus->busnum))
+               return -ENOMEM;
+
+       if (add_uevent_var(env, "DEVNUM=%03d", usb_dev->devnum))
+               return -ENOMEM;
+
+       return 0;
+}
+
+#else
+
+static int usb_dev_uevent(struct device *dev, struct kobj_uevent_env *env)
+{
+       return -ENODEV;
+}
+#endif /* CONFIG_HOTPLUG */
+
 struct device_type usb_device_type = {
        .name =         "usb_device",
        .release =      usb_release_dev,
+       .uevent =       usb_dev_uevent,
 };
 
 #ifdef CONFIG_PM