Commit ba5369ce authored by Johan Hovold's avatar Johan Hovold Committed by Zefan Li

USB: serial: fix tty-device error handling at probe

commit ca4383a3 upstream.

Add missing error handling when registering the tty device at port
probe. This avoids trying to remove an uninitialised character device
when the port device is removed.

Fixes: 1da177e4 ("Linux-2.6.12-rc2")
Reported-by: default avatarTakashi Iwai <tiwai@suse.de>
Signed-off-by: default avatarJohan Hovold <johan@kernel.org>
Acked-by: default avatarGreg Kroah-Hartman <greg@kroah.com>
[lizf: Backported to 3.4:
 - adjust context
 - s/goto exit_with_autopm/goto exit]
Signed-off-by: default avatarZefan Li <lizefan@huawei.com>
parent 97d0aa6b
...@@ -52,6 +52,7 @@ static int usb_serial_device_probe(struct device *dev) ...@@ -52,6 +52,7 @@ static int usb_serial_device_probe(struct device *dev)
{ {
struct usb_serial_driver *driver; struct usb_serial_driver *driver;
struct usb_serial_port *port; struct usb_serial_port *port;
struct device *tty_dev;
int retval = 0; int retval = 0;
int minor; int minor;
...@@ -76,7 +77,15 @@ static int usb_serial_device_probe(struct device *dev) ...@@ -76,7 +77,15 @@ static int usb_serial_device_probe(struct device *dev)
} }
minor = port->number; minor = port->number;
tty_register_device(usb_serial_tty_driver, minor, dev); tty_dev = tty_register_device(usb_serial_tty_driver, minor, dev);
if (IS_ERR(tty_dev)) {
retval = PTR_ERR(tty_dev);
device_remove_file(dev, &dev_attr_port_number);
if (driver->port_remove)
driver->port_remove(port);
goto exit;
}
dev_info(&port->serial->dev->dev, dev_info(&port->serial->dev->dev,
"%s converter now attached to ttyUSB%d\n", "%s converter now attached to ttyUSB%d\n",
driver->description, minor); driver->description, minor);
......
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