Commit 891a3b1f authored by Alan Stern's avatar Alan Stern Committed by Greg Kroah-Hartman

USB: fix bug in serial driver unregistration

This patch (as1536) fixes a bug in the USB serial core.  Unloading and
reloading a serial driver while a serial device is plugged in causes
errors because of the code in usb_serial_disconnect() that tries to
make sure the port_remove method is called.  With the new order of
driver registration introduced in the 3.4 kernel, this is definitely
not the right thing to do (if indeed it ever was).

The patch removes that whole section code, along with the mechanism
for keeping track of each port's registration state, which is no
longer needed.  The driver core can handle all that stuff for us.

Note: This has been tested only with one or two USB serial drivers.
In theory, other drivers might still run into trouble.  But if they
do, it will be the fault of the drivers, not of this patch -- that is,
the drivers will need to be fixed.
Signed-off-by: default avatarAlan Stern <stern@rowland.harvard.edu>
Reported-and-tested-by: default avatarJohan Hovold <jhovold@gmail.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 3a450850
...@@ -60,8 +60,6 @@ static int usb_serial_device_probe(struct device *dev) ...@@ -60,8 +60,6 @@ static int usb_serial_device_probe(struct device *dev)
retval = -ENODEV; retval = -ENODEV;
goto exit; goto exit;
} }
if (port->dev_state != PORT_REGISTERING)
goto exit;
driver = port->serial->type; driver = port->serial->type;
if (driver->port_probe) { if (driver->port_probe) {
...@@ -98,9 +96,6 @@ static int usb_serial_device_remove(struct device *dev) ...@@ -98,9 +96,6 @@ static int usb_serial_device_remove(struct device *dev)
if (!port) if (!port)
return -ENODEV; return -ENODEV;
if (port->dev_state != PORT_UNREGISTERING)
return retval;
device_remove_file(&port->dev, &dev_attr_port_number); device_remove_file(&port->dev, &dev_attr_port_number);
driver = port->serial->type; driver = port->serial->type;
......
...@@ -1070,17 +1070,12 @@ int usb_serial_probe(struct usb_interface *interface, ...@@ -1070,17 +1070,12 @@ int usb_serial_probe(struct usb_interface *interface,
port = serial->port[i]; port = serial->port[i];
dev_set_name(&port->dev, "ttyUSB%d", port->number); dev_set_name(&port->dev, "ttyUSB%d", port->number);
dbg ("%s - registering %s", __func__, dev_name(&port->dev)); dbg ("%s - registering %s", __func__, dev_name(&port->dev));
port->dev_state = PORT_REGISTERING;
device_enable_async_suspend(&port->dev); device_enable_async_suspend(&port->dev);
retval = device_add(&port->dev); retval = device_add(&port->dev);
if (retval) { if (retval)
dev_err(&port->dev, "Error registering port device, " dev_err(&port->dev, "Error registering port device, "
"continuing\n"); "continuing\n");
port->dev_state = PORT_UNREGISTERED;
} else {
port->dev_state = PORT_REGISTERED;
}
} }
usb_serial_console_init(debug, minor); usb_serial_console_init(debug, minor);
...@@ -1124,22 +1119,8 @@ void usb_serial_disconnect(struct usb_interface *interface) ...@@ -1124,22 +1119,8 @@ void usb_serial_disconnect(struct usb_interface *interface)
} }
kill_traffic(port); kill_traffic(port);
cancel_work_sync(&port->work); cancel_work_sync(&port->work);
if (port->dev_state == PORT_REGISTERED) { if (device_is_registered(&port->dev))
/* Make sure the port is bound so that the
* driver's port_remove method is called.
*/
if (!port->dev.driver) {
int rc;
port->dev.driver =
&serial->type->driver;
rc = device_bind_driver(&port->dev);
}
port->dev_state = PORT_UNREGISTERING;
device_del(&port->dev); device_del(&port->dev);
port->dev_state = PORT_UNREGISTERED;
}
} }
} }
serial->type->disconnect(serial); serial->type->disconnect(serial);
......
...@@ -28,13 +28,6 @@ ...@@ -28,13 +28,6 @@
/* parity check flag */ /* parity check flag */
#define RELEVANT_IFLAG(iflag) (iflag & (IGNBRK|BRKINT|IGNPAR|PARMRK|INPCK)) #define RELEVANT_IFLAG(iflag) (iflag & (IGNBRK|BRKINT|IGNPAR|PARMRK|INPCK))
enum port_dev_state {
PORT_UNREGISTERED,
PORT_REGISTERING,
PORT_REGISTERED,
PORT_UNREGISTERING,
};
/* USB serial flags */ /* USB serial flags */
#define USB_SERIAL_WRITE_BUSY 0 #define USB_SERIAL_WRITE_BUSY 0
...@@ -124,7 +117,6 @@ struct usb_serial_port { ...@@ -124,7 +117,6 @@ struct usb_serial_port {
char throttle_req; char throttle_req;
unsigned long sysrq; /* sysrq timeout */ unsigned long sysrq; /* sysrq timeout */
struct device dev; struct device dev;
enum port_dev_state dev_state;
}; };
#define to_usb_serial_port(d) container_of(d, struct usb_serial_port, dev) #define to_usb_serial_port(d) container_of(d, struct usb_serial_port, dev)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment