Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 /*
0003  * All the USB notify logic
0004  *
0005  * (C) Copyright 2005 Greg Kroah-Hartman <gregkh@suse.de>
0006  *
0007  * notifier functions originally based on those in kernel/sys.c
0008  * but fixed up to not be so broken.
0009  *
0010  * Released under the GPLv2 only.
0011  */
0012 
0013 
0014 #include <linux/kernel.h>
0015 #include <linux/export.h>
0016 #include <linux/notifier.h>
0017 #include <linux/usb.h>
0018 #include <linux/mutex.h>
0019 #include "usb.h"
0020 
0021 static BLOCKING_NOTIFIER_HEAD(usb_notifier_list);
0022 
0023 /**
0024  * usb_register_notify - register a notifier callback whenever a usb change happens
0025  * @nb: pointer to the notifier block for the callback events.
0026  *
0027  * These changes are either USB devices or busses being added or removed.
0028  */
0029 void usb_register_notify(struct notifier_block *nb)
0030 {
0031     blocking_notifier_chain_register(&usb_notifier_list, nb);
0032 }
0033 EXPORT_SYMBOL_GPL(usb_register_notify);
0034 
0035 /**
0036  * usb_unregister_notify - unregister a notifier callback
0037  * @nb: pointer to the notifier block for the callback events.
0038  *
0039  * usb_register_notify() must have been previously called for this function
0040  * to work properly.
0041  */
0042 void usb_unregister_notify(struct notifier_block *nb)
0043 {
0044     blocking_notifier_chain_unregister(&usb_notifier_list, nb);
0045 }
0046 EXPORT_SYMBOL_GPL(usb_unregister_notify);
0047 
0048 
0049 void usb_notify_add_device(struct usb_device *udev)
0050 {
0051     blocking_notifier_call_chain(&usb_notifier_list, USB_DEVICE_ADD, udev);
0052 }
0053 
0054 void usb_notify_remove_device(struct usb_device *udev)
0055 {
0056     blocking_notifier_call_chain(&usb_notifier_list,
0057             USB_DEVICE_REMOVE, udev);
0058 }
0059 
0060 void usb_notify_add_bus(struct usb_bus *ubus)
0061 {
0062     blocking_notifier_call_chain(&usb_notifier_list, USB_BUS_ADD, ubus);
0063 }
0064 
0065 void usb_notify_remove_bus(struct usb_bus *ubus)
0066 {
0067     blocking_notifier_call_chain(&usb_notifier_list, USB_BUS_REMOVE, ubus);
0068 }