Skip to contentSkip to conversation

USB Fixes for 2.6.0-test11

PATCH New Greg KH 1 participant 13 messages Dec 11, 2003

Subsystems (5)
lore
Share & tools
lore

Greg KH

author
#0 lore raw

PATCH 1/1 USB Fixes for 2.6.0-test11

Hi,

Here are some USB fixes for 2.6.0-test11. They all fix real bugs, and are 1-4 line fixes with the exception of the usb-serial close() fix, which is a bit larger, but has been well tested by a number of different users.

Please pull from: bk://linuxusb.bkbits.net/gregkh-2.6

Patches will be posted as a follow-up thread for those who want to see them.

thanks,

greg k-h

 drivers/usb/core/devio.c        |    2 -
 drivers/usb/core/hub.c          |   10 +++++---
 drivers/usb/core/usb.c          |    1 
 drivers/usb/image/Kconfig       |    4 ++-
 drivers/usb/misc/auerswald.c    |    4 +--
 drivers/usb/serial/usb-serial.c |   50 +++++++++++-----------------------------
 drivers/usb/storage/datafab.c   |    2 -
 drivers/usb/storage/jumpshot.c  |    2 -
 scripts/file2alias.c            |    7 +++++
 9 files changed, 37 insertions(+), 45 deletions(-)

-----

Alan Stern:
o USB: fix bug not setting device state following usb_device_reset()

Andrey Borzenkov:
o USB: prevent catch-all USB aliases in modules.alias

David Brownell:
o USB: fix remove device after set_configuration

Greg Kroah-Hartman:
o USB: fix bug for multiple opens on ttyUSB devices
o USB: fix race with hub devices disconnecting while stuff is still happening to them
o USB: register usb-serial ports in the proper place in sysfs

Herbert Xu:
o USB: Fix connect/disconnect race

Matthew Dharm:
o USB storage: fix for jumpshot and datafab devices

Oliver Neukum:
o USB: fix race with signal delivery in usbfs
o USB: fix sleping in interrupt bug in auerswald driver

Tom Rini:
o USB: mark the scanner driver as obsolete

author
#1 lore raw

PATCH 1/1 USB Fixes for 2.6.0-test11

ChangeSet 1.1516, 2003/12/08 11:10:51-08:00, [email protected]

[PATCH] USB: register usb-serial ports in the proper place in sysfs

They should be bound to the interface the driver is attached to, not the device.

 drivers/usb/serial/usb-serial.c |    2 +-
 1 files changed, 1 insertion(+), 1 deletion(-)
drivers/usb/serial/usb-serial.c +1 -1
diff -Nru a/drivers/usb/serial/usb-serial.c b/drivers/usb/serial/usb-serial.c
@@ -1242,7 +1242,7 @@
 	/* register all of the individual ports with the driver core */
 	for (i = 0; i < num_ports; ++i) {
 		port = serial->port[i];
-		port->dev.parent = &serial->dev->dev;
+		port->dev.parent = &interface->dev;
 		port->dev.driver = NULL;
 		port->dev.bus = &usb_serial_bus_type;
 		port->dev.release = &port_release;
author
#2 lore raw

ChangeSet 1.1517, 2003/12/08 13:28:46-08:00, [email protected]

[PATCH] USB: fix remove device after set_configuration

If a device can't be configured, the current test9 code forgets to clean it out of sysfs. This resolves that issue, so the retry in usb_new_device() stands a chance of working.

The enumeration code still doesn't handle such errors well, but at least this way that hub port can be used for another device.

 drivers/usb/core/usb.c |    1 +
 1 files changed, 1 insertion(+)
drivers/usb/core/usb.c +1 -0
diff -Nru a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
@@ -1120,6 +1120,7 @@
 	if (err) {
 		dev_err(&dev->dev, "can't set config #%d, error %d\n",
 			dev->config[0].desc.bConfigurationValue, err);
+		device_del(&dev->dev);
 		goto fail;
 	}
 
author
#3 lore raw

ChangeSet 1.1518, 2003/12/08 13:58:14-08:00, [email protected]

[PATCH] USB: fix race with hub devices disconnecting while stuff is still happening to them.

 drivers/usb/core/hub.c |    3 +++
 1 files changed, 3 insertions(+)
drivers/usb/core/hub.c +3 -0
diff -Nru a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
@@ -692,6 +692,9 @@
 	struct usb_hub *hub = usb_get_intfdata(dev->actconfig->interface[0]);
 	int ret;
 
+	if (!hub)
+		return -ENODEV;
+
 	ret = get_port_status(dev, port + 1, &hub->status->port);
 	if (ret < 0)
 		dev_err (hubdev (dev),
author
#4 lore raw

ChangeSet 1.1519, 2003/12/09 09:35:37-08:00, [email protected]

[PATCH] USB storage: fix for jumpshot and datafab devices

This patch fixes some obvious errors in the jumpshot and datafab drivers.

This should close out Bugzilla bug #1408

Quoted 6 lines

Date: Mon, 1 Dec 2003 12:14:53 -0500 (EST)
From: Alan Stern <[email protected]>
Subject: Patch from Eduard Hasenleithner
To: Matthew Dharm <[email protected]>
cc: USB Storage List <[email protected]>

Quoted 7 lines

Matt:

Did you see this patch? It was posted to the usb-development mailing list about a week ago, before I started making all my changes. It is clearly correct and necessary.

Alan Stern

 drivers/usb/storage/datafab.c  |    2 +-
 drivers/usb/storage/jumpshot.c |    2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/usb/storage/datafab.c +1 -1
diff -Nru a/drivers/usb/storage/datafab.c b/drivers/usb/storage/datafab.c
@@ -387,7 +387,7 @@
 
 	// we'll go ahead and extract the media capacity while we're here...
 	//
-	rc = datafab_bulk_read(us, reply, sizeof(reply));
+	rc = datafab_bulk_read(us, reply, 512);
 	if (rc == USB_STOR_XFER_GOOD) {
 		// capacity is at word offset 57-58
 		//
drivers/usb/storage/jumpshot.c +1 -1
diff -Nru a/drivers/usb/storage/jumpshot.c b/drivers/usb/storage/jumpshot.c
@@ -317,7 +317,7 @@
 	}
 
 	// read the reply
-	rc = jumpshot_bulk_read(us, reply, sizeof(reply));
+	rc = jumpshot_bulk_read(us, reply, 512);
 	if (rc != USB_STOR_XFER_GOOD) {
 		rc = USB_STOR_TRANSPORT_ERROR;
 		goto leave;
author
#5 lore raw

ChangeSet 1.1520, 2003/12/09 09:42:34-08:00, [email protected]

[PATCH] USB: mark the scanner driver as obsolete

Quoted 4 lines · Greg KH

Can't you use xsane without the scanner kernel driver? I thought the latest versions used libusb/usbfs to talk directly to the hardware. Because of this, the USB scanner driver is marked to be removed from the kernel sometime in the near future.

After a bit of mucking around (and possibly finding a bug with debian's libusb/xsane/hotplug interaction, nothing seems to run /etc/hotplug/usb/libusbscanner and thus only root can scan, anyone whose got this working please let me know), the problem does not exist if I only use libusb xsane.

How about the following:

 drivers/usb/image/Kconfig |    4 +++-
 1 files changed, 3 insertions(+), 1 deletion(-)
drivers/usb/image/Kconfig +3 -1
diff -Nru a/drivers/usb/image/Kconfig b/drivers/usb/image/Kconfig
@@ -18,12 +18,14 @@
 	  module will be called mdc800.
 
 config USB_SCANNER
-	tristate "USB Scanner support"
+	tristate "USB Scanner support (OBSOLETE)"
 	depends on USB
 	help
 	  Say Y here if you want to connect a USB scanner to your computer's
 	  USB port. Please read <file:Documentation/usb/scanner.txt> for more
 	  information.
+
+	  This driver has been obsoleted by support via libusb.
 
 	  To compile this driver as a module, choose M here: the
 	  module will be called scanner.
author
#6 lore raw

ChangeSet 1.1521, 2003/12/09 10:00:49-08:00, [email protected]

[PATCH] USB: fix sleping in interrupt bug in auerswald driver

this fixes two instances of GFP_KERNEL from completion handlers.

 drivers/usb/misc/auerswald.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
drivers/usb/misc/auerswald.c +2 -2
diff -Nru a/drivers/usb/misc/auerswald.c b/drivers/usb/misc/auerswald.c
@@ -324,7 +324,7 @@
                 urb    = acep->urbp;
                 dbg ("auerchain_complete: submitting next urb from chain");
 		urb->status = 0;	/* needed! */
-		result = usb_submit_urb(urb, GFP_KERNEL);
+		result = usb_submit_urb(urb, GFP_ATOMIC);
 
                 /* check for submit errors */
                 if (result) {
@@ -402,7 +402,7 @@
         if (acep) {
                 dbg("submitting urb immediate");
 		urb->status = 0;	/* needed! */
-                result = usb_submit_urb(urb, GFP_KERNEL);
+                result = usb_submit_urb(urb, GFP_ATOMIC);
                 /* check for submit errors */
                 if (result) {
                         urb->status = result;
author
#7 lore raw

ChangeSet 1.1522, 2003/12/09 10:18:07-08:00, [email protected]

[PATCH] USB: fix race with signal delivery in usbfs

apart from locking bugs, there are other races. This fixes one with signal delivery. The signal should be delivered _before_ the reciever is woken.

 drivers/usb/core/devio.c |    2 +-
 1 files changed, 1 insertion(+), 1 deletion(-)
drivers/usb/core/devio.c +1 -1
diff -Nru a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
@@ -261,7 +261,6 @@
         spin_lock(&ps->lock);
         list_move_tail(&as->asynclist, &ps->async_completed);
         spin_unlock(&ps->lock);
-        wake_up(&ps->wait);
 	if (as->signr) {
 		sinfo.si_signo = as->signr;
 		sinfo.si_errno = as->urb->status;
@@ -269,6 +268,7 @@
 		sinfo.si_addr = (void *)as->userurb;
 		send_sig_info(as->signr, &sinfo, as->task);
 	}
+        wake_up(&ps->wait);
 }
 
 static void destroy_async (struct dev_state *ps, struct list_head *list)
author
#8 lore raw

ChangeSet 1.1523, 2003/12/09 15:41:57-08:00, [email protected]

[PATCH] USB: fix bug not setting device state following usb_device_reset()

 drivers/usb/core/hub.c |    1 +
 1 files changed, 1 insertion(+)
drivers/usb/core/hub.c +1 -0
diff -Nru a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
@@ -1345,6 +1345,7 @@
 			dev->devpath, ret);
 		return ret;
 	}
+	dev->state = USB_STATE_CONFIGURED;
 
 	for (i = 0; i < dev->actconfig->desc.bNumInterfaces; i++) {
 		struct usb_interface *intf = dev->actconfig->interface[i];
author
#9 lore raw

ChangeSet 1.1524, 2003/12/09 17:40:44-08:00, [email protected]

[PATCH] USB: Fix connect/disconnect race

This patch was integrated by you in 2.4 six months ago. Unfortunately it never got into 2.5. Without it you can end up with crashes such as http://bugs.debian.org/218670

 drivers/usb/core/hub.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)
drivers/usb/core/hub.c +3 -3
diff -Nru a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
@@ -929,7 +929,6 @@
 			break;
 		}
 
-		hub->children[port] = dev;
 		dev->state = USB_STATE_POWERED;
 
 		/* Reset the device, and detect its speed */
@@ -982,8 +981,10 @@
 		dev->dev.parent = dev->parent->dev.parent->parent;
 
 		/* Run it through the hoops (find a driver, etc) */
-		if (!usb_new_device(dev, &hub->dev))
+		if (!usb_new_device(dev, &hub->dev)) {
+			hub->children[port] = dev;
 			goto done;
+		}
 
 		/* Free the configuration if there was an error */
 		usb_put_dev(dev);
@@ -992,7 +993,6 @@
 		delay = HUB_LONG_RESET_TIME;
 	}
 
-	hub->children[port] = NULL;
 	hub_port_disable(hub, port);
 done:
 	up(&usb_address0_sem);
author
#10 lore raw

ChangeSet 1.1525, 2003/12/10 14:39:48-08:00, [email protected]

[PATCH] USB: fix bug for multiple opens on ttyUSB devices.

This patch fixes the bug where running ppp over a ttyUSB device would fail.

 drivers/usb/serial/usb-serial.c |   48 ++++++++++------------------------------
 1 files changed, 13 insertions(+), 35 deletions(-)
drivers/usb/serial/usb-serial.c +13 -35
diff -Nru a/drivers/usb/serial/usb-serial.c b/drivers/usb/serial/usb-serial.c
@@ -493,12 +493,15 @@
 	return retval;
 }
 
-static void __serial_close(struct usb_serial_port *port, struct file *filp)
+static void serial_close(struct tty_struct *tty, struct file * filp)
 {
-	if (!port->open_count) {
-		dbg ("%s - port not opened", __FUNCTION__);
+	struct usb_serial_port *port = (struct usb_serial_port *) tty->driver_data;
+	struct usb_serial *serial = get_usb_serial (port, __FUNCTION__);
+
+	if (!serial)
 		return;
-	}
+
+	dbg("%s - port %d", __FUNCTION__, port->number);
 
 	--port->open_count;
 	if (port->open_count <= 0) {
@@ -506,30 +509,18 @@
 		 * port is being closed by the last owner */
 		port->serial->type->close(port, filp);
 		port->open_count = 0;
+
+		if (port->tty) {
+			if (port->tty->driver_data)
+				port->tty->driver_data = NULL;
+			port->tty = NULL;
+		}
 	}
 
 	module_put(port->serial->type->owner);
 	kobject_put(&port->serial->kobj);
 }
 
-static void serial_close(struct tty_struct *tty, struct file * filp)
-{
-	struct usb_serial_port *port = (struct usb_serial_port *) tty->driver_data;
-	struct usb_serial *serial = get_usb_serial (port, __FUNCTION__);
-
-	if (!serial)
-		return;
-
-	dbg("%s - port %d", __FUNCTION__, port->number);
-
-	/* if disconnect beat us to the punch here, there's nothing to do */
-	if (tty && tty->driver_data) {
-		__serial_close(port, filp);
-		tty->driver_data = NULL;
-	}
-	port->tty = NULL;
-}
-
 static int serial_write (struct tty_struct * tty, int from_user, const unsigned char *buf, int count)
 {
 	struct usb_serial_port *port = (struct usb_serial_port *) tty->driver_data;
@@ -848,19 +839,6 @@
 	dbg ("%s - %s", __FUNCTION__, kobj->name);
 
 	serial = to_usb_serial(kobj);
-
-	/* fail all future close/read/write/ioctl/etc calls */
-	for (i = 0; i < serial->num_ports; ++i) {
-		port = serial->port[i];
-		if (port->tty != NULL) {
-			port->tty->driver_data = NULL;
-			while (port->open_count > 0) {
-				__serial_close(port, NULL);
-			}
-			port->tty = NULL;
-		}
-	}
-
 	serial_shutdown (serial);
 
 	/* return the minor range that this device had */
author
#11 lore raw

ChangeSet 1.1526, 2003/12/10 16:00:53-08:00, [email protected]

[PATCH] USB: prevent catch-all USB aliases in modules.alias

visor.c defines one empty slot in USB ids table that can be filled in at runtime using module parameters. file2alias generates catch-all alias for it:

alias usb:v*p*dl*dh*dc*dsc*dp*ic*isc*ip* visor

patch adds the same sanity check as in depmod to scripts/file2alias.

 scripts/file2alias.c |    7 +++++++
 1 files changed, 7 insertions(+)
scripts/file2alias.c +7 -0
diff -Nru a/scripts/file2alias.c b/scripts/file2alias.c
@@ -52,6 +52,13 @@
 	id->bcdDevice_lo = TO_NATIVE(id->bcdDevice_lo);
 	id->bcdDevice_hi = TO_NATIVE(id->bcdDevice_hi);
 
+	/*
+	 * Some modules (visor) have empty slots as placeholder for
+	 * run-time specification that results in catch-all alias
+	 */
+	if (!(id->idVendor | id->bDeviceClass | id->bInterfaceClass))
+		return 1;
+
 	strcpy(alias, "usb:");
 	ADD(alias, "v", id->match_flags&USB_DEVICE_ID_MATCH_VENDOR,
 	    id->idVendor);
author
#12 lore raw

PATCH 1/1 Kobject Fix for 2.6.0-test11

In reply to Greg KH
Quoted 7 lines · Greg KH

Here are some USB fixes for 2.6.0-test11. They all fix real bugs, and are 1-4 line fixes with the exception of the usb-serial close() fix, which is a bit larger, but has been well tested by a number of different users.

Please pull from: bk://linuxusb.bkbits.net/gregkh-2.6

I've added the following patch to this repository. If you've already pulled from here, feel free to just apply this single patch. Or you can pull from that tree again, which ever is easier for you.

It fixes a kobject bug where the parent could be deleted before the child object, causing all sorts of badness later when we clean up the child object. It's been acked by Pat.

thanks,

greg k-h

Subject: kobject: fix bug where a parent could be deleted before a child device.

lib/kobject.c +7 -4
diff -Nru a/lib/kobject.c b/lib/kobject.c
@@ -236,8 +236,6 @@
 		list_del_init(&kobj->entry);
 		up_write(&kobj->kset->subsys->rwsem);
 	}
-	if (kobj->parent) 
-		kobject_put(kobj->parent);
 	kobject_put(kobj);
 }
 
@@ -274,9 +272,11 @@
 	kobj->parent = parent;
 
 	error = create_dir(kobj);
-	if (error)
+	if (error) {
 		unlink(kobj);
-	else {
+		if (parent)
+			kobject_put(parent);
+	} else {
 		/* If this kobj does not belong to a kset,
 		   try to find a parent that does. */
 		top_kobj = kobj;
@@ -452,6 +452,7 @@
 {
 	struct kobj_type * t = get_ktype(kobj);
 	struct kset * s = kobj->kset;
+	struct kobject * parent = kobj->parent;
 
 	pr_debug("kobject %s: cleaning up\n",kobject_name(kobj));
 	if (kobj->k_name != kobj->name)
@@ -461,6 +462,8 @@
 		t->release(kobj);
 	if (s)
 		kset_put(s);
+	if (parent) 
+		kobject_put(parent);
 }
 
 /**