forked from Minki/linux
fc7a6209d5
The driver core ignores the return value of this callback because there is only little it can do when a device disappears. This is the final bit of a long lasting cleanup quest where several buses were converted to also return void from their remove callback. Additionally some resource leaks were fixed that were caused by drivers returning an error code in the expectation that the driver won't go away. With struct bus_type::remove returning void it's prevented that newly implemented buses return an ignored error code and so don't anticipate wrong expectations for driver authors. Reviewed-by: Tom Rix <trix@redhat.com> (For fpga) Reviewed-by: Mathieu Poirier <mathieu.poirier@linaro.org> Reviewed-by: Cornelia Huck <cohuck@redhat.com> (For drivers/s390 and drivers/vfio) Acked-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk> (For ARM, Amba and related parts) Acked-by: Mark Brown <broonie@kernel.org> Acked-by: Chen-Yu Tsai <wens@csie.org> (for sunxi-rsb) Acked-by: Pali Rohár <pali@kernel.org> Acked-by: Mauro Carvalho Chehab <mchehab@kernel.org> (for media) Acked-by: Hans de Goede <hdegoede@redhat.com> (For drivers/platform) Acked-by: Alexandre Belloni <alexandre.belloni@bootlin.com> Acked-By: Vinod Koul <vkoul@kernel.org> Acked-by: Juergen Gross <jgross@suse.com> (For xen) Acked-by: Lee Jones <lee.jones@linaro.org> (For mfd) Acked-by: Johannes Thumshirn <jth@kernel.org> (For mcb) Acked-by: Johan Hovold <johan@kernel.org> Acked-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org> (For slimbus) Acked-by: Kirti Wankhede <kwankhede@nvidia.com> (For vfio) Acked-by: Maximilian Luz <luzmaximilian@gmail.com> Acked-by: Heikki Krogerus <heikki.krogerus@linux.intel.com> (For ulpi and typec) Acked-by: Samuel Iglesias Gonsálvez <siglesias@igalia.com> (For ipack) Acked-by: Geoff Levand <geoff@infradead.org> (For ps3) Acked-by: Yehezkel Bernat <YehezkelShB@gmail.com> (For thunderbolt) Acked-by: Alexander Shishkin <alexander.shishkin@linux.intel.com> (For intel_th) Acked-by: Dominik Brodowski <linux@dominikbrodowski.net> (For pcmcia) Acked-by: Rafael J. Wysocki <rafael@kernel.org> (For ACPI) Acked-by: Bjorn Andersson <bjorn.andersson@linaro.org> (rpmsg and apr) Acked-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com> (For intel-ish-hid) Acked-by: Dan Williams <dan.j.williams@intel.com> (For CXL, DAX, and NVDIMM) Acked-by: William Breathitt Gray <vilhelm.gray@gmail.com> (For isa) Acked-by: Stefan Richter <stefanr@s5r6.in-berlin.de> (For firewire) Acked-by: Benjamin Tissoires <benjamin.tissoires@redhat.com> (For hid) Acked-by: Thorsten Scherer <t.scherer@eckelmann.de> (For siox) Acked-by: Sven Van Asbroeck <TheSven73@gmail.com> (For anybuss) Acked-by: Ulf Hansson <ulf.hansson@linaro.org> (For MMC) Acked-by: Wolfram Sang <wsa@kernel.org> # for I2C Acked-by: Sudeep Holla <sudeep.holla@arm.com> Acked-by: Geert Uytterhoeven <geert@linux-m68k.org> Acked-by: Dmitry Torokhov <dmitry.torokhov@gmail.com> Acked-by: Finn Thain <fthain@linux-m68k.org> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Link: https://lore.kernel.org/r/20210713193522.1770306-6-u.kleine-koenig@pengutronix.de Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
174 lines
4.1 KiB
C
174 lines
4.1 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
/*
|
|
* USB Serial Converter Bus specific functions
|
|
*
|
|
* Copyright (C) 2002 Greg Kroah-Hartman (greg@kroah.com)
|
|
*/
|
|
|
|
#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)
|
|
{
|
|
const struct usb_serial_port *port = to_usb_serial_port(dev);
|
|
struct usb_serial_driver *driver = to_usb_serial_driver(drv);
|
|
|
|
/*
|
|
* drivers are already assigned to ports in serial_probe so it's
|
|
* a simple check here.
|
|
*/
|
|
if (driver == port->serial->type)
|
|
return 1;
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int usb_serial_device_probe(struct device *dev)
|
|
{
|
|
struct usb_serial_port *port = to_usb_serial_port(dev);
|
|
struct usb_serial_driver *driver;
|
|
struct device *tty_dev;
|
|
int retval = 0;
|
|
int minor;
|
|
|
|
/* make sure suspend/resume doesn't race against port_probe */
|
|
retval = usb_autopm_get_interface(port->serial->interface);
|
|
if (retval)
|
|
return retval;
|
|
|
|
driver = port->serial->type;
|
|
if (driver->port_probe) {
|
|
retval = driver->port_probe(port);
|
|
if (retval)
|
|
goto err_autopm_put;
|
|
}
|
|
|
|
minor = port->minor;
|
|
tty_dev = tty_port_register_device(&port->port, usb_serial_tty_driver,
|
|
minor, dev);
|
|
if (IS_ERR(tty_dev)) {
|
|
retval = PTR_ERR(tty_dev);
|
|
goto err_port_remove;
|
|
}
|
|
|
|
usb_autopm_put_interface(port->serial->interface);
|
|
|
|
dev_info(&port->serial->dev->dev,
|
|
"%s converter now attached to ttyUSB%d\n",
|
|
driver->description, minor);
|
|
|
|
return 0;
|
|
|
|
err_port_remove:
|
|
if (driver->port_remove)
|
|
driver->port_remove(port);
|
|
err_autopm_put:
|
|
usb_autopm_put_interface(port->serial->interface);
|
|
|
|
return retval;
|
|
}
|
|
|
|
static void usb_serial_device_remove(struct device *dev)
|
|
{
|
|
struct usb_serial_port *port = to_usb_serial_port(dev);
|
|
struct usb_serial_driver *driver;
|
|
int minor;
|
|
int autopm_err;
|
|
|
|
/*
|
|
* Make sure suspend/resume doesn't race against port_remove.
|
|
*
|
|
* Note that no further runtime PM callbacks will be made if
|
|
* autopm_get fails.
|
|
*/
|
|
autopm_err = usb_autopm_get_interface(port->serial->interface);
|
|
|
|
minor = port->minor;
|
|
tty_unregister_device(usb_serial_tty_driver, minor);
|
|
|
|
driver = port->serial->type;
|
|
if (driver->port_remove)
|
|
driver->port_remove(port);
|
|
|
|
dev_info(dev, "%s converter now disconnected from ttyUSB%d\n",
|
|
driver->description, minor);
|
|
|
|
if (!autopm_err)
|
|
usb_autopm_put_interface(port->serial->interface);
|
|
}
|
|
|
|
static ssize_t new_id_store(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, usb_drv->id_table,
|
|
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->id_table,
|
|
&usb_drv->usb_driver->drvwrap.driver,
|
|
buf, count);
|
|
return retval;
|
|
}
|
|
|
|
static ssize_t new_id_show(struct device_driver *driver, char *buf)
|
|
{
|
|
struct usb_serial_driver *usb_drv = to_usb_serial_driver(driver);
|
|
|
|
return usb_show_dynids(&usb_drv->dynids, buf);
|
|
}
|
|
static DRIVER_ATTR_RW(new_id);
|
|
|
|
static struct attribute *usb_serial_drv_attrs[] = {
|
|
&driver_attr_new_id.attr,
|
|
NULL,
|
|
};
|
|
ATTRIBUTE_GROUPS(usb_serial_drv);
|
|
|
|
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);
|
|
}
|
|
|
|
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_groups = usb_serial_drv_groups,
|
|
};
|
|
|
|
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);
|
|
}
|
|
|