mirror of
https://github.com/followmsi/android_kernel_google_msm.git
synced 2024-11-06 23:17:41 +00:00
ba5369ce52
commit ca4383a3947a83286bc9b9c598a1f55e867871d7 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: 1da177e4c3
("Linux-2.6.12-rc2")
Reported-by: Takashi Iwai <tiwai@suse.de>
Signed-off-by: Johan Hovold <johan@kernel.org>
Acked-by: Greg Kroah-Hartman <greg@kroah.com>
[lizf: Backported to 3.4:
- adjust context
- s/goto exit_with_autopm/goto exit]
Signed-off-by: Zefan Li <lizefan@huawei.com>
188 lines
4.2 KiB
C
188 lines
4.2 KiB
C
/*
|
|
* USB Serial Converter Bus specific functions
|
|
*
|
|
* Copyright (C) 2002 Greg Kroah-Hartman (greg@kroah.com)
|
|
*
|
|
* This program is free software; you can redistribute it and/or
|
|
* modify it under the terms of the GNU General Public License version
|
|
* 2 as published by the Free Software Foundation.
|
|
*/
|
|
|
|
#include <linux/kernel.h>
|
|
#include <linux/errno.h>
|
|
#include <linux/tty.h>
|
|
#include <linux/slab.h>
|
|
#include <linux/module.h>
|
|
#include <linux/usb.h>
|
|
#include <linux/usb/serial.h>
|
|
|
|
static int usb_serial_device_match(struct device *dev,
|
|
struct device_driver *drv)
|
|
{
|
|
struct usb_serial_driver *driver;
|
|
const struct usb_serial_port *port;
|
|
|
|
/*
|
|
* drivers are already assigned to ports in serial_probe so it's
|
|
* a simple check here.
|
|
*/
|
|
port = to_usb_serial_port(dev);
|
|
if (!port)
|
|
return 0;
|
|
|
|
driver = to_usb_serial_driver(drv);
|
|
|
|
if (driver == port->serial->type)
|
|
return 1;
|
|
|
|
return 0;
|
|
}
|
|
|
|
static ssize_t show_port_number(struct device *dev,
|
|
struct device_attribute *attr, char *buf)
|
|
{
|
|
struct usb_serial_port *port = to_usb_serial_port(dev);
|
|
|
|
return sprintf(buf, "%d\n", port->number - port->serial->minor);
|
|
}
|
|
|
|
static DEVICE_ATTR(port_number, S_IRUGO, show_port_number, NULL);
|
|
|
|
static int usb_serial_device_probe(struct device *dev)
|
|
{
|
|
struct usb_serial_driver *driver;
|
|
struct usb_serial_port *port;
|
|
struct device *tty_dev;
|
|
int retval = 0;
|
|
int minor;
|
|
|
|
port = to_usb_serial_port(dev);
|
|
if (!port) {
|
|
retval = -ENODEV;
|
|
goto exit;
|
|
}
|
|
|
|
driver = port->serial->type;
|
|
if (driver->port_probe) {
|
|
retval = driver->port_probe(port);
|
|
if (retval)
|
|
goto exit;
|
|
}
|
|
|
|
retval = device_create_file(dev, &dev_attr_port_number);
|
|
if (retval) {
|
|
if (driver->port_remove)
|
|
driver->port_remove(port);
|
|
goto exit;
|
|
}
|
|
|
|
minor = port->number;
|
|
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,
|
|
"%s converter now attached to ttyUSB%d\n",
|
|
driver->description, minor);
|
|
|
|
exit:
|
|
return retval;
|
|
}
|
|
|
|
static int usb_serial_device_remove(struct device *dev)
|
|
{
|
|
struct usb_serial_driver *driver;
|
|
struct usb_serial_port *port;
|
|
int retval = 0;
|
|
int minor;
|
|
|
|
port = to_usb_serial_port(dev);
|
|
if (!port)
|
|
return -ENODEV;
|
|
|
|
device_remove_file(&port->dev, &dev_attr_port_number);
|
|
|
|
driver = port->serial->type;
|
|
if (driver->port_remove)
|
|
retval = driver->port_remove(port);
|
|
|
|
minor = port->number;
|
|
tty_unregister_device(usb_serial_tty_driver, minor);
|
|
dev_info(dev, "%s converter now disconnected from ttyUSB%d\n",
|
|
driver->description, minor);
|
|
|
|
return retval;
|
|
}
|
|
|
|
#ifdef CONFIG_HOTPLUG
|
|
static ssize_t store_new_id(struct device_driver *driver,
|
|
const char *buf, size_t count)
|
|
{
|
|
struct usb_serial_driver *usb_drv = to_usb_serial_driver(driver);
|
|
ssize_t retval = usb_store_new_id(&usb_drv->dynids, driver, buf, count);
|
|
|
|
if (retval >= 0 && usb_drv->usb_driver != NULL)
|
|
retval = usb_store_new_id(&usb_drv->usb_driver->dynids,
|
|
&usb_drv->usb_driver->drvwrap.driver,
|
|
buf, count);
|
|
return retval;
|
|
}
|
|
|
|
static struct driver_attribute drv_attrs[] = {
|
|
__ATTR(new_id, S_IWUSR, NULL, store_new_id),
|
|
__ATTR_NULL,
|
|
};
|
|
|
|
static void free_dynids(struct usb_serial_driver *drv)
|
|
{
|
|
struct usb_dynid *dynid, *n;
|
|
|
|
spin_lock(&drv->dynids.lock);
|
|
list_for_each_entry_safe(dynid, n, &drv->dynids.list, node) {
|
|
list_del(&dynid->node);
|
|
kfree(dynid);
|
|
}
|
|
spin_unlock(&drv->dynids.lock);
|
|
}
|
|
|
|
#else
|
|
static struct driver_attribute drv_attrs[] = {
|
|
__ATTR_NULL,
|
|
};
|
|
static inline void free_dynids(struct usb_serial_driver *drv)
|
|
{
|
|
}
|
|
#endif
|
|
|
|
struct bus_type usb_serial_bus_type = {
|
|
.name = "usb-serial",
|
|
.match = usb_serial_device_match,
|
|
.probe = usb_serial_device_probe,
|
|
.remove = usb_serial_device_remove,
|
|
.drv_attrs = drv_attrs,
|
|
};
|
|
|
|
int usb_serial_bus_register(struct usb_serial_driver *driver)
|
|
{
|
|
int retval;
|
|
|
|
driver->driver.bus = &usb_serial_bus_type;
|
|
spin_lock_init(&driver->dynids.lock);
|
|
INIT_LIST_HEAD(&driver->dynids.list);
|
|
|
|
retval = driver_register(&driver->driver);
|
|
|
|
return retval;
|
|
}
|
|
|
|
void usb_serial_bus_deregister(struct usb_serial_driver *driver)
|
|
{
|
|
free_dynids(driver);
|
|
driver_unregister(&driver->driver);
|
|
}
|
|
|