linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Greg KH <greg@kroah.com>
To: linux-kernel@vger.kernel.org
Subject: Re: [PATCH] Driver Core patches for 2.6.9
Date: Tue, 19 Oct 2004 09:37:09 -0700	[thread overview]
Message-ID: <10982038294134@kroah.com> (raw)
In-Reply-To: <10982038272844@kroah.com>

ChangeSet 1.1994, 2004/09/29 17:26:15-07:00, roland@topspin.com

[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>


 drivers/usb/core/usb.c |   59 +++++++++++++++++++------------------------------
 1 files changed, 23 insertions(+), 36 deletions(-)


diff -Nru a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
--- a/drivers/usb/core/usb.c	2004-10-19 09:20:30 -07:00
+++ b/drivers/usb/core/usb.c	2004-10-19 09:20:30 -07:00
@@ -566,7 +566,6 @@
 {
 	struct usb_interface *intf;
 	struct usb_device *usb_dev;
-	char *scratch;
 	int i = 0;
 	int length = 0;
 
@@ -593,8 +592,6 @@
 		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 @@
 	 *
 	 * 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 @@
 		 * 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;


  reply	other threads:[~2004-10-19 17:00 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-10-19 16:34 [BK PATCH] Driver Core patches for 2.6.9 Greg KH
2004-10-19 16:35 ` [PATCH] " Greg KH
2004-10-19 16:35   ` Greg KH
2004-10-19 16:36     ` Greg KH
2004-10-19 16:36       ` Greg KH
2004-10-19 16:36         ` Greg KH
2004-10-19 16:36           ` Greg KH
2004-10-19 16:36             ` Greg KH
2004-10-19 16:36               ` Greg KH
2004-10-19 16:36                 ` Greg KH
2004-10-19 16:36                   ` Greg KH
2004-10-19 16:36                     ` Greg KH
2004-10-19 16:36                       ` Greg KH
2004-10-19 16:36                         ` Greg KH
2004-10-19 16:36                           ` Greg KH
2004-10-19 16:36                             ` Greg KH
2004-10-19 16:36                               ` Greg KH
2004-10-19 16:36                                 ` Greg KH
2004-10-19 16:36                                   ` Greg KH
2004-10-19 16:36                                     ` Greg KH
2004-10-19 16:36                                       ` Greg KH
2004-10-19 16:36                                         ` Greg KH
2004-10-19 16:36                                           ` Greg KH
2004-10-19 16:36                                             ` Greg KH
2004-10-19 16:36                                               ` Greg KH
2004-10-19 16:36                                                 ` Greg KH
2004-10-19 16:36                                                   ` Greg KH
2004-10-19 16:36                                                     ` Greg KH
2004-10-19 16:36                                                       ` Greg KH
2004-10-19 16:37                                                         ` Greg KH
2004-10-19 16:37                                                           ` Greg KH
2004-10-19 16:37                                                             ` Greg KH
2004-10-19 16:37                                                               ` Greg KH
2004-10-19 16:37                                                                 ` Greg KH [this message]
2004-10-19 16:37                                                                   ` Greg KH
2004-10-23 20:20                     ` Kronos
2004-10-23 20:34                       ` Greg KH
2004-10-23 21:46                         ` Kronos

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=10982038294134@kroah.com \
    --to=greg@kroah.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).