mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-12-17 07:54:54 +08:00
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>
183 lines
3.8 KiB
C
183 lines
3.8 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
/*
|
|
* ISA bus.
|
|
*/
|
|
|
|
#include <linux/device.h>
|
|
#include <linux/kernel.h>
|
|
#include <linux/slab.h>
|
|
#include <linux/module.h>
|
|
#include <linux/init.h>
|
|
#include <linux/dma-mapping.h>
|
|
#include <linux/isa.h>
|
|
|
|
static struct device isa_bus = {
|
|
.init_name = "isa"
|
|
};
|
|
|
|
struct isa_dev {
|
|
struct device dev;
|
|
struct device *next;
|
|
unsigned int id;
|
|
};
|
|
|
|
#define to_isa_dev(x) container_of((x), struct isa_dev, dev)
|
|
|
|
static int isa_bus_match(struct device *dev, struct device_driver *driver)
|
|
{
|
|
struct isa_driver *isa_driver = to_isa_driver(driver);
|
|
|
|
if (dev->platform_data == isa_driver) {
|
|
if (!isa_driver->match ||
|
|
isa_driver->match(dev, to_isa_dev(dev)->id))
|
|
return 1;
|
|
dev->platform_data = NULL;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
static int isa_bus_probe(struct device *dev)
|
|
{
|
|
struct isa_driver *isa_driver = dev->platform_data;
|
|
|
|
if (isa_driver && isa_driver->probe)
|
|
return isa_driver->probe(dev, to_isa_dev(dev)->id);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static void isa_bus_remove(struct device *dev)
|
|
{
|
|
struct isa_driver *isa_driver = dev->platform_data;
|
|
|
|
if (isa_driver && isa_driver->remove)
|
|
isa_driver->remove(dev, to_isa_dev(dev)->id);
|
|
}
|
|
|
|
static void isa_bus_shutdown(struct device *dev)
|
|
{
|
|
struct isa_driver *isa_driver = dev->platform_data;
|
|
|
|
if (isa_driver && isa_driver->shutdown)
|
|
isa_driver->shutdown(dev, to_isa_dev(dev)->id);
|
|
}
|
|
|
|
static int isa_bus_suspend(struct device *dev, pm_message_t state)
|
|
{
|
|
struct isa_driver *isa_driver = dev->platform_data;
|
|
|
|
if (isa_driver && isa_driver->suspend)
|
|
return isa_driver->suspend(dev, to_isa_dev(dev)->id, state);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int isa_bus_resume(struct device *dev)
|
|
{
|
|
struct isa_driver *isa_driver = dev->platform_data;
|
|
|
|
if (isa_driver && isa_driver->resume)
|
|
return isa_driver->resume(dev, to_isa_dev(dev)->id);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static struct bus_type isa_bus_type = {
|
|
.name = "isa",
|
|
.match = isa_bus_match,
|
|
.probe = isa_bus_probe,
|
|
.remove = isa_bus_remove,
|
|
.shutdown = isa_bus_shutdown,
|
|
.suspend = isa_bus_suspend,
|
|
.resume = isa_bus_resume
|
|
};
|
|
|
|
static void isa_dev_release(struct device *dev)
|
|
{
|
|
kfree(to_isa_dev(dev));
|
|
}
|
|
|
|
void isa_unregister_driver(struct isa_driver *isa_driver)
|
|
{
|
|
struct device *dev = isa_driver->devices;
|
|
|
|
while (dev) {
|
|
struct device *tmp = to_isa_dev(dev)->next;
|
|
device_unregister(dev);
|
|
dev = tmp;
|
|
}
|
|
driver_unregister(&isa_driver->driver);
|
|
}
|
|
EXPORT_SYMBOL_GPL(isa_unregister_driver);
|
|
|
|
int isa_register_driver(struct isa_driver *isa_driver, unsigned int ndev)
|
|
{
|
|
int error;
|
|
unsigned int id;
|
|
|
|
isa_driver->driver.bus = &isa_bus_type;
|
|
isa_driver->devices = NULL;
|
|
|
|
error = driver_register(&isa_driver->driver);
|
|
if (error)
|
|
return error;
|
|
|
|
for (id = 0; id < ndev; id++) {
|
|
struct isa_dev *isa_dev;
|
|
|
|
isa_dev = kzalloc(sizeof *isa_dev, GFP_KERNEL);
|
|
if (!isa_dev) {
|
|
error = -ENOMEM;
|
|
break;
|
|
}
|
|
|
|
isa_dev->dev.parent = &isa_bus;
|
|
isa_dev->dev.bus = &isa_bus_type;
|
|
|
|
dev_set_name(&isa_dev->dev, "%s.%u",
|
|
isa_driver->driver.name, id);
|
|
isa_dev->dev.platform_data = isa_driver;
|
|
isa_dev->dev.release = isa_dev_release;
|
|
isa_dev->id = id;
|
|
|
|
isa_dev->dev.coherent_dma_mask = DMA_BIT_MASK(24);
|
|
isa_dev->dev.dma_mask = &isa_dev->dev.coherent_dma_mask;
|
|
|
|
error = device_register(&isa_dev->dev);
|
|
if (error) {
|
|
put_device(&isa_dev->dev);
|
|
break;
|
|
}
|
|
|
|
if (isa_dev->dev.platform_data) {
|
|
isa_dev->next = isa_driver->devices;
|
|
isa_driver->devices = &isa_dev->dev;
|
|
} else
|
|
device_unregister(&isa_dev->dev);
|
|
}
|
|
|
|
if (!error && !isa_driver->devices)
|
|
error = -ENODEV;
|
|
|
|
if (error)
|
|
isa_unregister_driver(isa_driver);
|
|
|
|
return error;
|
|
}
|
|
EXPORT_SYMBOL_GPL(isa_register_driver);
|
|
|
|
static int __init isa_bus_init(void)
|
|
{
|
|
int error;
|
|
|
|
error = bus_register(&isa_bus_type);
|
|
if (!error) {
|
|
error = device_register(&isa_bus);
|
|
if (error)
|
|
bus_unregister(&isa_bus_type);
|
|
}
|
|
return error;
|
|
}
|
|
|
|
postcore_initcall(isa_bus_init);
|