device: protect device event broadcast against simultaneous deletions of multiple...
authorFelix Fietkau <nbd@openwrt.org>
Sun, 10 Feb 2013 18:14:35 +0000 (19:14 +0100)
committerFelix Fietkau <nbd@openwrt.org>
Sun, 10 Feb 2013 18:14:35 +0000 (19:14 +0100)
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
device.c
device.h

index 97fb27f1c8883e22b428c8b11d7dd8e8b7baf464..9ef444e88a233f615c320fe3f3ec65d7f10d2f0b 100644 (file)
--- a/device.c
+++ b/device.c
@@ -183,14 +183,27 @@ static void __init dev_init(void)
 
 static void __device_broadcast_event(struct list_head *head, enum device_event ev)
 {
-       struct device_user *dep, *tmp;
+       struct device_user *dep;
+       static uint8_t idx[__DEV_EVENT_MAX];
+       bool found;
 
-       list_for_each_entry_safe(dep, tmp, head, list) {
-               if (!dep->cb)
-                       continue;
+       idx[ev]++;
+       do {
+               found = false;
 
-               dep->cb(dep, ev);
-       }
+               list_for_each_entry(dep, head, list) {
+                       if (!dep->cb)
+                               continue;
+
+                       if (dep->ev_idx[ev] == idx[ev])
+                               continue;
+
+                       dep->cb(dep, ev);
+                       dep->ev_idx[ev] = idx[ev];
+                       found = true;
+                       break;
+               }
+       } while (found);
 }
 
 void device_broadcast_event(struct device *dev, enum device_event ev)
index 8cedfbae642827b1ff5f650c34cb4dfddb8e4034..1f852abe6c46a70ac6262b04e12bef2aa707ac8f 100644 (file)
--- a/device.h
+++ b/device.h
@@ -75,6 +75,8 @@ enum device_event {
 
        DEV_EVENT_LINK_UP,
        DEV_EVENT_LINK_DOWN,
+
+       __DEV_EVENT_MAX
 };
 
 /*
@@ -87,6 +89,8 @@ struct device_user {
        bool hotplug;
        bool alias;
 
+       uint8_t ev_idx[__DEV_EVENT_MAX];
+
        struct device *dev;
        void (*cb)(struct device_user *, enum device_event);
 };