aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb
diff options
context:
space:
mode:
authorAlan Stern <stern@rowland.harvard.edu>2007-11-06 15:01:52 -0500
committerGreg Kroah-Hartman <gregkh@suse.de>2007-11-28 16:58:35 -0500
commit4a9bee8256a2dec26290a3bfff86ab86b8992547 (patch)
tree8e30db88d70d67d6be81f0b0bdd5e52d618f8ba0 /drivers/usb
parent7e61559f6199bb387037abfc7d10a893973561fc (diff)
USB: uevent environment key fix
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>
Diffstat (limited to 'drivers/usb')
-rw-r--r--drivers/usb/core/driver.c11
-rw-r--r--drivers/usb/core/message.c24
-rw-r--r--drivers/usb/core/usb.c25
3 files changed, 25 insertions, 35 deletions
diff --git a/drivers/usb/core/driver.c b/drivers/usb/core/driver.c
index 8586817698ad..c51f8e9312e0 100644
--- a/drivers/usb/core/driver.c
+++ b/drivers/usb/core/driver.c
@@ -585,9 +585,6 @@ static int usb_uevent(struct device *dev, struct kobj_uevent_env *env)
585{ 585{
586 struct usb_device *usb_dev; 586 struct usb_device *usb_dev;
587 587
588 if (!dev)
589 return -ENODEV;
590
591 /* driver is often null here; dev_dbg() would oops */ 588 /* driver is often null here; dev_dbg() would oops */
592 pr_debug ("usb %s: uevent\n", dev->bus_id); 589 pr_debug ("usb %s: uevent\n", dev->bus_id);
593 590
@@ -631,14 +628,6 @@ static int usb_uevent(struct device *dev, struct kobj_uevent_env *env)
631 usb_dev->descriptor.bDeviceProtocol)) 628 usb_dev->descriptor.bDeviceProtocol))
632 return -ENOMEM; 629 return -ENOMEM;
633 630
634 if (add_uevent_var(env, "BUSNUM=%03d",
635 usb_dev->bus->busnum))
636 return -ENOMEM;
637
638 if (add_uevent_var(env, "DEVNUM=%03d",
639 usb_dev->devnum))
640 return -ENOMEM;
641
642 return 0; 631 return 0;
643} 632}
644 633
diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
index 40fd39de5bf9..fcd40ecbeecc 100644
--- a/drivers/usb/core/message.c
+++ b/drivers/usb/core/message.c
@@ -1346,34 +1346,10 @@ static int usb_if_uevent(struct device *dev, struct kobj_uevent_env *env)
1346 struct usb_interface *intf; 1346 struct usb_interface *intf;
1347 struct usb_host_interface *alt; 1347 struct usb_host_interface *alt;
1348 1348
1349 if (!dev)
1350 return -ENODEV;
1351
1352 /* driver is often null here; dev_dbg() would oops */
1353 pr_debug ("usb %s: uevent\n", dev->bus_id);
1354
1355 intf = to_usb_interface(dev); 1349 intf = to_usb_interface(dev);
1356 usb_dev = interface_to_usbdev(intf); 1350 usb_dev = interface_to_usbdev(intf);
1357 alt = intf->cur_altsetting; 1351 alt = intf->cur_altsetting;
1358 1352
1359#ifdef CONFIG_USB_DEVICEFS
1360 if (add_uevent_var(env, "DEVICE=/proc/bus/usb/%03d/%03d",
1361 usb_dev->bus->busnum, usb_dev->devnum))
1362 return -ENOMEM;
1363#endif
1364
1365 if (add_uevent_var(env, "PRODUCT=%x/%x/%x",
1366 le16_to_cpu(usb_dev->descriptor.idVendor),
1367 le16_to_cpu(usb_dev->descriptor.idProduct),
1368 le16_to_cpu(usb_dev->descriptor.bcdDevice)))
1369 return -ENOMEM;
1370
1371 if (add_uevent_var(env, "TYPE=%d/%d/%d",
1372 usb_dev->descriptor.bDeviceClass,
1373 usb_dev->descriptor.bDeviceSubClass,
1374 usb_dev->descriptor.bDeviceProtocol))
1375 return -ENOMEM;
1376
1377 if (add_uevent_var(env, "INTERFACE=%d/%d/%d", 1353 if (add_uevent_var(env, "INTERFACE=%d/%d/%d",
1378 alt->desc.bInterfaceClass, 1354 alt->desc.bInterfaceClass,
1379 alt->desc.bInterfaceSubClass, 1355 alt->desc.bInterfaceSubClass,
diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
index c4a6f1095b8b..8f142370103d 100644
--- a/drivers/usb/core/usb.c
+++ b/drivers/usb/core/usb.c
@@ -192,9 +192,34 @@ static void usb_release_dev(struct device *dev)
192 kfree(udev); 192 kfree(udev);
193} 193}
194 194
195#ifdef CONFIG_HOTPLUG
196static int usb_dev_uevent(struct device *dev, struct kobj_uevent_env *env)
197{
198 struct usb_device *usb_dev;
199
200 usb_dev = to_usb_device(dev);
201
202 if (add_uevent_var(env, "BUSNUM=%03d", usb_dev->bus->busnum))
203 return -ENOMEM;
204
205 if (add_uevent_var(env, "DEVNUM=%03d", usb_dev->devnum))
206 return -ENOMEM;
207
208 return 0;
209}
210
211#else
212
213static int usb_dev_uevent(struct device *dev, struct kobj_uevent_env *env)
214{
215 return -ENODEV;
216}
217#endif /* CONFIG_HOTPLUG */
218
195struct device_type usb_device_type = { 219struct device_type usb_device_type = {
196 .name = "usb_device", 220 .name = "usb_device",
197 .release = usb_release_dev, 221 .release = usb_release_dev,
222 .uevent = usb_dev_uevent,
198}; 223};
199 224
200#ifdef CONFIG_PM 225#ifdef CONFIG_PM