Skip to content

Commit 594c828

Browse files
Russell Kinggregkh
authored andcommitted
[PATCH] Add bus_type probe, remove, shutdown methods.
Add bus_type probe, remove and shutdown methods to replace the corresponding methods in struct device_driver. This matches the way we handle the suspend/resume methods. Since the bus methods override the device_driver methods, warn if a device driver is registered whose methods will not be called. The long-term idea is to remove the device_driver methods entirely. Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
1 parent bd37e5a commit 594c828

4 files changed

Lines changed: 22 additions & 3 deletions

File tree

‎drivers/base/dd.c‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,13 @@ int driver_probe_device(struct device_driver * drv, struct device * dev)
7878
pr_debug("%s: Matched Device %s with Driver %s\n",
7979
drv->bus->name, dev->bus_id, drv->name);
8080
dev->driver = drv;
81-
if (drv->probe) {
81+
if (dev->bus->probe) {
82+
ret = dev->bus->probe(dev);
83+
if (ret) {
84+
dev->driver = NULL;
85+
goto ProbeFailed;
86+
}
87+
} else if (drv->probe) {
8288
ret = drv->probe(dev);
8389
if (ret) {
8490
dev->driver = NULL;
@@ -203,7 +209,9 @@ static void __device_release_driver(struct device * dev)
203209
sysfs_remove_link(&dev->kobj, "driver");
204210
klist_remove(&dev->knode_driver);
205211

206-
if (drv->remove)
212+
if (dev->bus->remove)
213+
dev->bus->remove(dev);
214+
else if (drv->remove)
207215
drv->remove(dev);
208216
dev->driver = NULL;
209217
put_driver(drv);

‎drivers/base/driver.c‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,11 @@ static void klist_devices_put(struct klist_node *n)
171171
*/
172172
int driver_register(struct device_driver * drv)
173173
{
174+
if ((drv->bus->probe && drv->probe) ||
175+
(drv->bus->remove && drv->remove) ||
176+
(drv->bus->shutdown && drv->shutdown)) {
177+
printk(KERN_WARNING "Driver '%s' needs updating - please use bus_type methods\n", drv->name);
178+
}
174179
klist_init(&drv->klist_devices, klist_devices_get, klist_devices_put);
175180
init_completion(&drv->unloaded);
176181
return bus_add_driver(drv);

‎drivers/base/power/shutdown.c‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,10 @@ void device_shutdown(void)
4040
down_write(&devices_subsys.rwsem);
4141
list_for_each_entry_reverse(dev, &devices_subsys.kset.list,
4242
kobj.entry) {
43-
if (dev->driver && dev->driver->shutdown) {
43+
if (dev->bus && dev->bus->shutdown) {
44+
dev_dbg(dev, "shutdown\n");
45+
dev->bus->shutdown(dev);
46+
} else if (dev->driver && dev->driver->shutdown) {
4447
dev_dbg(dev, "shutdown\n");
4548
dev->driver->shutdown(dev);
4649
}

‎include/linux/device.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ struct bus_type {
4949
int (*match)(struct device * dev, struct device_driver * drv);
5050
int (*uevent)(struct device *dev, char **envp,
5151
int num_envp, char *buffer, int buffer_size);
52+
int (*probe)(struct device * dev);
53+
int (*remove)(struct device * dev);
54+
void (*shutdown)(struct device * dev);
5255
int (*suspend)(struct device * dev, pm_message_t state);
5356
int (*resume)(struct device * dev);
5457
};

0 commit comments

Comments
 (0)