[PATCH 07/18] driver: Add unregister_driver()
Ahmad Fatoum
a.fatoum at pengutronix.de
Mon Mar 20 08:43:08 PDT 2023
On 20.03.23 16:29, Sascha Hauer wrote:
> Registering drivers is one thing, getting rid of them another. Add
> unregister_driver() which is used in the coming USB gadget update.
>
> Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
> ---
> drivers/base/driver.c | 16 ++++++++++++++++
> include/driver.h | 2 ++
> 2 files changed, 18 insertions(+)
>
> diff --git a/drivers/base/driver.c b/drivers/base/driver.c
> index efbffcdddb..719920ec67 100644
> --- a/drivers/base/driver.c
> +++ b/drivers/base/driver.c
> @@ -405,6 +405,22 @@ int register_driver(struct driver *drv)
> }
> EXPORT_SYMBOL(register_driver);
>
> +void unregister_driver(struct driver *drv)
> +{
> + struct device *dev;
> +
> + list_del(&drv->list);
> + list_del(&drv->bus_list);
> +
> + bus_for_each_device(drv->bus, dev) {
> + if (dev->driver == drv) {
> + drv->bus->remove(dev);
I think drv->bus->remove may be NULL here and you need to guard against that.
While at it, could you switch commands/devunbind.c to use this new function?
Thanks,
Ahmad
> + dev->driver = NULL;
> + list_del(&dev->active);
> + }
> + }
> +}
> +
> struct resource *dev_get_resource(struct device *dev, unsigned long type,
> int num)
> {
> diff --git a/include/driver.h b/include/driver.h
> index 2cf0190699..5605a3db24 100644
> --- a/include/driver.h
> +++ b/include/driver.h
> @@ -137,6 +137,8 @@ struct driver {
> /* Register devices and drivers.
> */
> int register_driver(struct driver *);
> +void unregister_driver(struct driver *drv);
> +
> int register_device(struct device *);
>
> /* manualy probe a device
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
More information about the barebox
mailing list