xref: /openbmc/linux/drivers/usb/core/notify.c (revision 0898782247ae533d1f4e47a06bc5d4870931b284)
1*aa1f3bb5SGreg Kroah-Hartman // SPDX-License-Identifier: GPL-2.0
23099e75aSGreg Kroah-Hartman /*
33099e75aSGreg Kroah-Hartman  * All the USB notify logic
43099e75aSGreg Kroah-Hartman  *
53099e75aSGreg Kroah-Hartman  * (C) Copyright 2005 Greg Kroah-Hartman <gregkh@suse.de>
63099e75aSGreg Kroah-Hartman  *
73099e75aSGreg Kroah-Hartman  * notifier functions originally based on those in kernel/sys.c
83099e75aSGreg Kroah-Hartman  * but fixed up to not be so broken.
93099e75aSGreg Kroah-Hartman  *
10b65fba3dSGreg Kroah-Hartman  * Released under the GPLv2 only.
113099e75aSGreg Kroah-Hartman  */
123099e75aSGreg Kroah-Hartman 
133099e75aSGreg Kroah-Hartman 
143099e75aSGreg Kroah-Hartman #include <linux/kernel.h>
15f940fcd8SPaul Gortmaker #include <linux/export.h>
163099e75aSGreg Kroah-Hartman #include <linux/notifier.h>
173099e75aSGreg Kroah-Hartman #include <linux/usb.h>
184186ecf8SArjan van de Ven #include <linux/mutex.h>
193099e75aSGreg Kroah-Hartman #include "usb.h"
203099e75aSGreg Kroah-Hartman 
21e041c683SAlan Stern static BLOCKING_NOTIFIER_HEAD(usb_notifier_list);
223099e75aSGreg Kroah-Hartman 
233099e75aSGreg Kroah-Hartman /**
243099e75aSGreg Kroah-Hartman  * usb_register_notify - register a notifier callback whenever a usb change happens
253099e75aSGreg Kroah-Hartman  * @nb: pointer to the notifier block for the callback events.
263099e75aSGreg Kroah-Hartman  *
273099e75aSGreg Kroah-Hartman  * These changes are either USB devices or busses being added or removed.
283099e75aSGreg Kroah-Hartman  */
usb_register_notify(struct notifier_block * nb)293099e75aSGreg Kroah-Hartman void usb_register_notify(struct notifier_block *nb)
303099e75aSGreg Kroah-Hartman {
31e041c683SAlan Stern 	blocking_notifier_chain_register(&usb_notifier_list, nb);
323099e75aSGreg Kroah-Hartman }
333099e75aSGreg Kroah-Hartman EXPORT_SYMBOL_GPL(usb_register_notify);
343099e75aSGreg Kroah-Hartman 
353099e75aSGreg Kroah-Hartman /**
363099e75aSGreg Kroah-Hartman  * usb_unregister_notify - unregister a notifier callback
373099e75aSGreg Kroah-Hartman  * @nb: pointer to the notifier block for the callback events.
383099e75aSGreg Kroah-Hartman  *
39da287623SManish Katiyar  * usb_register_notify() must have been previously called for this function
403099e75aSGreg Kroah-Hartman  * to work properly.
413099e75aSGreg Kroah-Hartman  */
usb_unregister_notify(struct notifier_block * nb)423099e75aSGreg Kroah-Hartman void usb_unregister_notify(struct notifier_block *nb)
433099e75aSGreg Kroah-Hartman {
44e041c683SAlan Stern 	blocking_notifier_chain_unregister(&usb_notifier_list, nb);
453099e75aSGreg Kroah-Hartman }
463099e75aSGreg Kroah-Hartman EXPORT_SYMBOL_GPL(usb_unregister_notify);
473099e75aSGreg Kroah-Hartman 
483099e75aSGreg Kroah-Hartman 
usb_notify_add_device(struct usb_device * udev)493099e75aSGreg Kroah-Hartman void usb_notify_add_device(struct usb_device *udev)
503099e75aSGreg Kroah-Hartman {
51e041c683SAlan Stern 	blocking_notifier_call_chain(&usb_notifier_list, USB_DEVICE_ADD, udev);
523099e75aSGreg Kroah-Hartman }
533099e75aSGreg Kroah-Hartman 
usb_notify_remove_device(struct usb_device * udev)543099e75aSGreg Kroah-Hartman void usb_notify_remove_device(struct usb_device *udev)
553099e75aSGreg Kroah-Hartman {
56e041c683SAlan Stern 	blocking_notifier_call_chain(&usb_notifier_list,
57e041c683SAlan Stern 			USB_DEVICE_REMOVE, udev);
583099e75aSGreg Kroah-Hartman }
593099e75aSGreg Kroah-Hartman 
usb_notify_add_bus(struct usb_bus * ubus)603099e75aSGreg Kroah-Hartman void usb_notify_add_bus(struct usb_bus *ubus)
613099e75aSGreg Kroah-Hartman {
62e041c683SAlan Stern 	blocking_notifier_call_chain(&usb_notifier_list, USB_BUS_ADD, ubus);
633099e75aSGreg Kroah-Hartman }
643099e75aSGreg Kroah-Hartman 
usb_notify_remove_bus(struct usb_bus * ubus)653099e75aSGreg Kroah-Hartman void usb_notify_remove_bus(struct usb_bus *ubus)
663099e75aSGreg Kroah-Hartman {
67e041c683SAlan Stern 	blocking_notifier_call_chain(&usb_notifier_list, USB_BUS_REMOVE, ubus);
683099e75aSGreg Kroah-Hartman }
69