[PATCH 7/7]: Use notify call chain mechanism for usb notifiication

From: Chandra Seetharaman
Date: Wed Nov 23 2005 - 18:41:27 EST


Since the notifier chain was not protected, usb module was using its own
notifier mechanism which is very similar.

As we fixed the problem, moving usb notifier to use the basic notifier
chain mechanism.

Signed-off-by: Chandra Seetharaman <sekharan@xxxxxxxxxx>
Signed-off-by: Alan Stern <stern@xxxxxxxxxxxxxxxxxxx>
-----

drivers/usb/core/notify.c | 63 +++++-----------------------------------------
1 files changed, 7 insertions(+), 56 deletions(-)

Index: l2615-rc2-notifiers/drivers/usb/core/notify.c
===================================================================
--- l2615-rc2-notifiers.orig/drivers/usb/core/notify.c
+++ l2615-rc2-notifiers/drivers/usb/core/notify.c
@@ -16,56 +16,7 @@
#include "usb.h"


-static struct notifier_block *usb_notifier_list;
-static DECLARE_MUTEX(usb_notifier_lock);
-
-static void usb_notifier_chain_register(struct notifier_block **list,
- struct notifier_block *n)
-{
- down(&usb_notifier_lock);
- while (*list) {
- if (n->priority > (*list)->priority)
- break;
- list = &((*list)->next);
- }
- n->next = *list;
- *list = n;
- up(&usb_notifier_lock);
-}
-
-static void usb_notifier_chain_unregister(struct notifier_block **nl,
- struct notifier_block *n)
-{
- down(&usb_notifier_lock);
- while ((*nl)!=NULL) {
- if ((*nl)==n) {
- *nl = n->next;
- goto exit;
- }
- nl=&((*nl)->next);
- }
-exit:
- up(&usb_notifier_lock);
-}
-
-static int usb_notifier_call_chain(struct notifier_block **n,
- unsigned long val, void *v)
-{
- int ret=NOTIFY_DONE;
- struct notifier_block *nb = *n;
-
- down(&usb_notifier_lock);
- while (nb) {
- ret = nb->notifier_call(nb,val,v);
- if (ret&NOTIFY_STOP_MASK) {
- goto exit;
- }
- nb = nb->next;
- }
-exit:
- up(&usb_notifier_lock);
- return ret;
-}
+static BLOCKING_NOTIFIER_HEAD(usb_notifier_list);

/**
* usb_register_notify - register a notifier callback whenever a usb change happens
@@ -75,7 +26,7 @@ exit:
*/
void usb_register_notify(struct notifier_block *nb)
{
- usb_notifier_chain_register(&usb_notifier_list, nb);
+ notifier_chain_register(&usb_notifier_list, nb);
}
EXPORT_SYMBOL_GPL(usb_register_notify);

@@ -88,27 +39,27 @@ EXPORT_SYMBOL_GPL(usb_register_notify);
*/
void usb_unregister_notify(struct notifier_block *nb)
{
- usb_notifier_chain_unregister(&usb_notifier_list, nb);
+ notifier_chain_unregister(&usb_notifier_list, nb);
}
EXPORT_SYMBOL_GPL(usb_unregister_notify);


void usb_notify_add_device(struct usb_device *udev)
{
- usb_notifier_call_chain(&usb_notifier_list, USB_DEVICE_ADD, udev);
+ notifier_call_chain(&usb_notifier_list, USB_DEVICE_ADD, udev);
}

void usb_notify_remove_device(struct usb_device *udev)
{
- usb_notifier_call_chain(&usb_notifier_list, USB_DEVICE_REMOVE, udev);
+ notifier_call_chain(&usb_notifier_list, USB_DEVICE_REMOVE, udev);
}

void usb_notify_add_bus(struct usb_bus *ubus)
{
- usb_notifier_call_chain(&usb_notifier_list, USB_BUS_ADD, ubus);
+ notifier_call_chain(&usb_notifier_list, USB_BUS_ADD, ubus);
}

void usb_notify_remove_bus(struct usb_bus *ubus)
{
- usb_notifier_call_chain(&usb_notifier_list, USB_BUS_REMOVE, ubus);
+ notifier_call_chain(&usb_notifier_list, USB_BUS_REMOVE, ubus);
}

--

----------------------------------------------------------------------
Chandra Seetharaman | Be careful what you choose....
- sekharan@xxxxxxxxxx | .......you may get it.
----------------------------------------------------------------------


-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/