]> pilppa.com Git - linux-2.6-omap-h63xx.git/commitdiff
rfkill: detect bogus double-registering (v2)
authorHenrique de Moraes Holschuh <hmh@hmh.eng.br>
Sat, 2 Aug 2008 18:10:57 +0000 (15:10 -0300)
committerJohn W. Linville <linville@tuxdriver.com>
Fri, 22 Aug 2008 20:29:56 +0000 (16:29 -0400)
Detect and abort with -EEXIST if rfkill_register is called twice on the
same rfkill struct.  And WARN_ON(it) for good measure.

While at it, flag when we are adding the first switch of a type, we will
need that information later.

Signed-off-by: Henrique de Moraes Holschuh <hmh@hmh.eng.br>
Acked-by: Ivo van Doorn <IvDoorn@gmail.com>
Cc: Johannes Berg <johannes@sipsolutions.net>
Signed-off-by: John W. Linville <linville@tuxdriver.com>
net/rfkill/rfkill.c

index 35a9994e23397e70b7f099b1bd573ed28c361512..1f23de20a85e335b61fc506cbc14507ffdaa03ef 100644 (file)
@@ -525,17 +525,44 @@ static struct class rfkill_class = {
        .dev_uevent     = rfkill_dev_uevent,
 };
 
+static int rfkill_check_duplicity(const struct rfkill *rfkill)
+{
+       struct rfkill *p;
+       unsigned long seen[BITS_TO_LONGS(RFKILL_TYPE_MAX)];
+
+       memset(seen, 0, sizeof(seen));
+
+       list_for_each_entry(p, &rfkill_list, node) {
+               if (p == rfkill) {
+                       WARN_ON(1);
+                       return -EEXIST;
+               }
+               set_bit(p->type, seen);
+       }
+
+       /* 0: first switch of its kind */
+       return test_bit(rfkill->type, seen);
+}
+
 static int rfkill_add_switch(struct rfkill *rfkill)
 {
+       int error;
+
        mutex_lock(&rfkill_mutex);
 
+       error = rfkill_check_duplicity(rfkill);
+       if (error < 0)
+               goto unlock_out;
+
        rfkill_toggle_radio(rfkill, rfkill_states[rfkill->type], 0);
 
        list_add_tail(&rfkill->node, &rfkill_list);
 
+       error = 0;
+unlock_out:
        mutex_unlock(&rfkill_mutex);
 
-       return 0;
+       return error;
 }
 
 static void rfkill_remove_switch(struct rfkill *rfkill)