mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-07-22 13:57:33 -04:00
All buses have been converted from driver_set_override() to the generic
driver_override infrastructure introduced in commit cb3d1049f4
("driver core: generalize driver_override in struct device").
Buses now either opt into the generic sysfs callbacks via the
bus_type::driver_override flag, or use device_set_driver_override() /
__device_set_driver_override() directly.
Thus, remove the now-unused driver_set_override() helper.
Link: https://bugzilla.kernel.org/show_bug.cgi?id=220789
Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Link: https://patch.msgid.link/20260505133935.3772495-6-dakr@kernel.org
Signed-off-by: Danilo Krummrich <dakr@kernel.org>
205 lines
5.1 KiB
C
205 lines
5.1 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
/*
|
|
* driver.c - centralized device driver management
|
|
*
|
|
* Copyright (c) 2002-3 Patrick Mochel
|
|
* Copyright (c) 2002-3 Open Source Development Labs
|
|
* Copyright (c) 2007 Greg Kroah-Hartman <gregkh@suse.de>
|
|
* Copyright (c) 2007 Novell Inc.
|
|
*/
|
|
|
|
#include <linux/device/driver.h>
|
|
#include <linux/device.h>
|
|
#include <linux/module.h>
|
|
#include <linux/errno.h>
|
|
#include <linux/slab.h>
|
|
#include <linux/string.h>
|
|
#include <linux/sysfs.h>
|
|
#include "base.h"
|
|
|
|
static struct device *next_device(struct klist_iter *i)
|
|
{
|
|
struct klist_node *n = klist_next(i);
|
|
struct device *dev = NULL;
|
|
struct device_private *dev_prv;
|
|
|
|
if (n) {
|
|
dev_prv = to_device_private_driver(n);
|
|
dev = dev_prv->device;
|
|
}
|
|
return dev;
|
|
}
|
|
|
|
/**
|
|
* driver_for_each_device - Iterator for devices bound to a driver.
|
|
* @drv: Driver we're iterating.
|
|
* @start: Device to begin with
|
|
* @data: Data to pass to the callback.
|
|
* @fn: Function to call for each device.
|
|
*
|
|
* Iterate over the @drv's list of devices calling @fn for each one.
|
|
*/
|
|
int driver_for_each_device(struct device_driver *drv, struct device *start,
|
|
void *data, device_iter_t fn)
|
|
{
|
|
struct klist_iter i;
|
|
struct device *dev;
|
|
int error = 0;
|
|
|
|
if (!drv)
|
|
return -EINVAL;
|
|
|
|
klist_iter_init_node(&drv->p->klist_devices, &i,
|
|
start ? &start->p->knode_driver : NULL);
|
|
while (!error && (dev = next_device(&i)))
|
|
error = fn(dev, data);
|
|
klist_iter_exit(&i);
|
|
return error;
|
|
}
|
|
EXPORT_SYMBOL_GPL(driver_for_each_device);
|
|
|
|
/**
|
|
* driver_find_device - device iterator for locating a particular device.
|
|
* @drv: The device's driver
|
|
* @start: Device to begin with
|
|
* @data: Data to pass to match function
|
|
* @match: Callback function to check device
|
|
*
|
|
* This is similar to the driver_for_each_device() function above, but
|
|
* it returns a reference to a device that is 'found' for later use, as
|
|
* determined by the @match callback.
|
|
*
|
|
* The callback should return 0 if the device doesn't match and non-zero
|
|
* if it does. If the callback returns non-zero, this function will
|
|
* return to the caller and not iterate over any more devices.
|
|
*/
|
|
struct device *driver_find_device(const struct device_driver *drv,
|
|
struct device *start, const void *data,
|
|
device_match_t match)
|
|
{
|
|
struct klist_iter i;
|
|
struct device *dev;
|
|
|
|
if (!drv || !drv->p)
|
|
return NULL;
|
|
|
|
klist_iter_init_node(&drv->p->klist_devices, &i,
|
|
(start ? &start->p->knode_driver : NULL));
|
|
while ((dev = next_device(&i))) {
|
|
if (match(dev, data)) {
|
|
get_device(dev);
|
|
break;
|
|
}
|
|
}
|
|
klist_iter_exit(&i);
|
|
return dev;
|
|
}
|
|
EXPORT_SYMBOL_GPL(driver_find_device);
|
|
|
|
/**
|
|
* driver_create_file - create sysfs file for driver.
|
|
* @drv: driver.
|
|
* @attr: driver attribute descriptor.
|
|
*/
|
|
int driver_create_file(const struct device_driver *drv,
|
|
const struct driver_attribute *attr)
|
|
{
|
|
int error;
|
|
|
|
if (drv)
|
|
error = sysfs_create_file(&drv->p->kobj, &attr->attr);
|
|
else
|
|
error = -EINVAL;
|
|
return error;
|
|
}
|
|
EXPORT_SYMBOL_GPL(driver_create_file);
|
|
|
|
/**
|
|
* driver_remove_file - remove sysfs file for driver.
|
|
* @drv: driver.
|
|
* @attr: driver attribute descriptor.
|
|
*/
|
|
void driver_remove_file(const struct device_driver *drv,
|
|
const struct driver_attribute *attr)
|
|
{
|
|
if (drv)
|
|
sysfs_remove_file(&drv->p->kobj, &attr->attr);
|
|
}
|
|
EXPORT_SYMBOL_GPL(driver_remove_file);
|
|
|
|
int driver_add_groups(const struct device_driver *drv,
|
|
const struct attribute_group *const *groups)
|
|
{
|
|
return sysfs_create_groups(&drv->p->kobj, groups);
|
|
}
|
|
|
|
void driver_remove_groups(const struct device_driver *drv,
|
|
const struct attribute_group *const *groups)
|
|
{
|
|
sysfs_remove_groups(&drv->p->kobj, groups);
|
|
}
|
|
|
|
/**
|
|
* driver_register - register driver with bus
|
|
* @drv: driver to register
|
|
*
|
|
* We pass off most of the work to the bus_add_driver() call,
|
|
* since most of the things we have to do deal with the bus
|
|
* structures.
|
|
*/
|
|
int driver_register(struct device_driver *drv)
|
|
{
|
|
int ret;
|
|
struct device_driver *other;
|
|
|
|
if (!bus_is_registered(drv->bus)) {
|
|
pr_err("Driver '%s' was unable to register with bus_type '%s' because the bus was not initialized.\n",
|
|
drv->name, drv->bus->name);
|
|
return -EINVAL;
|
|
}
|
|
|
|
if ((drv->bus->probe && drv->probe) ||
|
|
(drv->bus->remove && drv->remove) ||
|
|
(drv->bus->shutdown && drv->shutdown))
|
|
pr_warn("Driver '%s' needs updating - please use "
|
|
"bus_type methods\n", drv->name);
|
|
|
|
other = driver_find(drv->name, drv->bus);
|
|
if (other) {
|
|
pr_err("Error: Driver '%s' is already registered, "
|
|
"aborting...\n", drv->name);
|
|
return -EBUSY;
|
|
}
|
|
|
|
ret = bus_add_driver(drv);
|
|
if (ret)
|
|
return ret;
|
|
ret = driver_add_groups(drv, drv->groups);
|
|
if (ret) {
|
|
bus_remove_driver(drv);
|
|
return ret;
|
|
}
|
|
kobject_uevent(&drv->p->kobj, KOBJ_ADD);
|
|
deferred_probe_extend_timeout();
|
|
|
|
return ret;
|
|
}
|
|
EXPORT_SYMBOL_GPL(driver_register);
|
|
|
|
/**
|
|
* driver_unregister - remove driver from system.
|
|
* @drv: driver.
|
|
*
|
|
* Again, we pass off most of the work to the bus-level call.
|
|
*/
|
|
void driver_unregister(struct device_driver *drv)
|
|
{
|
|
if (!drv || !drv->p) {
|
|
WARN(1, "Unexpected driver unregister!\n");
|
|
return;
|
|
}
|
|
driver_remove_groups(drv, drv->groups);
|
|
bus_remove_driver(drv);
|
|
}
|
|
EXPORT_SYMBOL_GPL(driver_unregister);
|