summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoland Dreier <roland@topspin.com>2004-09-29 03:26:15 -0700
committerGreg Kroah-Hartman <greg@kroah.com>2004-09-29 03:26:15 -0700
commit6e20f10823dcecd65019dc42ef7e63f392abe4ed (patch)
treeb93b02264f4d23a5f1ceca949e019068091cbdab
parente2661e66605c57210ea9e689b51fc63ac001c8b3 (diff)
[PATCH] USB: use add_hotplug_env_var() in core/usb.c
Use the new add_hotplug_env_var() function in drivers/usb/core/usb.c. In addition to cleaning up the code, this fixes a (probably harmless) bug here: for each value added to the environment, the code did length += sprintf(...); and then scratch += length; which means that we skip the sum of the lengths of all the values we've put so far, rather than just the length of the value we just put. This is probably harmless since we're unlikely to run out of space but if nothing else it's setting a bad example.... I've tested this on a system with USB floppy and CD-ROM; hotplug gets the same environment with the patch as without. Signed-off-by: Roland Dreier <roland@topspin.com> Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
-rw-r--r--drivers/usb/core/usb.c59
1 files changed, 23 insertions, 36 deletions
diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
index df461b120612..138541225604 100644
--- a/drivers/usb/core/usb.c
+++ b/drivers/usb/core/usb.c
@@ -566,7 +566,6 @@ static int usb_hotplug (struct device *dev, char **envp, int num_envp,
{
struct usb_interface *intf;
struct usb_device *usb_dev;
- char *scratch;
int i = 0;
int length = 0;
@@ -593,8 +592,6 @@ static int usb_hotplug (struct device *dev, char **envp, int num_envp,
return -ENODEV;
}
- scratch = buffer;
-
#ifdef CONFIG_USB_DEVICEFS
/* If this is available, userspace programs can directly read
* all the device descriptors we don't tell them about. Or
@@ -602,37 +599,30 @@ static int usb_hotplug (struct device *dev, char **envp, int num_envp,
*
* FIXME reduce hardwired intelligence here
*/
- envp [i++] = scratch;
- length += snprintf (scratch, buffer_size - length,
- "DEVICE=/proc/bus/usb/%03d/%03d",
- usb_dev->bus->busnum, usb_dev->devnum);
- if ((buffer_size - length <= 0) || (i >= num_envp))
+ if (add_hotplug_env_var(envp, num_envp, &i,
+ buffer, buffer_size, &length,
+ "DEVICE=/proc/bus/usb/%03d/%03d",
+ usb_dev->bus->busnum, usb_dev->devnum))
return -ENOMEM;
- ++length;
- scratch += length;
#endif
/* per-device configurations are common */
- envp [i++] = scratch;
- length += snprintf (scratch, buffer_size - length, "PRODUCT=%x/%x/%x",
- usb_dev->descriptor.idVendor,
- usb_dev->descriptor.idProduct,
- usb_dev->descriptor.bcdDevice);
- if ((buffer_size - length <= 0) || (i >= num_envp))
+ if (add_hotplug_env_var(envp, num_envp, &i,
+ buffer, buffer_size, &length,
+ "PRODUCT=%x/%x/%x",
+ usb_dev->descriptor.idVendor,
+ usb_dev->descriptor.idProduct,
+ usb_dev->descriptor.bcdDevice))
return -ENOMEM;
- ++length;
- scratch += length;
/* class-based driver binding models */
- envp [i++] = scratch;
- length += snprintf (scratch, buffer_size - length, "TYPE=%d/%d/%d",
- usb_dev->descriptor.bDeviceClass,
- usb_dev->descriptor.bDeviceSubClass,
- usb_dev->descriptor.bDeviceProtocol);
- if ((buffer_size - length <= 0) || (i >= num_envp))
+ if (add_hotplug_env_var(envp, num_envp, &i,
+ buffer, buffer_size, &length,
+ "TYPE=%d/%d/%d",
+ usb_dev->descriptor.bDeviceClass,
+ usb_dev->descriptor.bDeviceSubClass,
+ usb_dev->descriptor.bDeviceProtocol))
return -ENOMEM;
- ++length;
- scratch += length;
if (usb_dev->descriptor.bDeviceClass == 0) {
struct usb_host_interface *alt = intf->cur_altsetting;
@@ -641,18 +631,15 @@ static int usb_hotplug (struct device *dev, char **envp, int num_envp,
* agents are called for all interfaces, and can use
* $DEVPATH/bInterfaceNumber if necessary.
*/
- envp [i++] = scratch;
- length += snprintf (scratch, buffer_size - length,
- "INTERFACE=%d/%d/%d",
- alt->desc.bInterfaceClass,
- alt->desc.bInterfaceSubClass,
- alt->desc.bInterfaceProtocol);
- if ((buffer_size - length <= 0) || (i >= num_envp))
+ if (add_hotplug_env_var(envp, num_envp, &i,
+ buffer, buffer_size, &length,
+ "INTERFACE=%d/%d/%d",
+ alt->desc.bInterfaceClass,
+ alt->desc.bInterfaceSubClass,
+ alt->desc.bInterfaceProtocol))
return -ENOMEM;
- ++length;
- scratch += length;
-
}
+
envp[i++] = NULL;
return 0;