rfkill: fix minor typo in kernel doc
[safe/jmp/linux-2.6] / net / rfkill / rfkill.c
index c6a9412..f95081a 100644 (file)
 #include <linux/mutex.h>
 #include <linux/rfkill.h>
 
+/* Get declaration of rfkill_switch_all() to shut up sparse. */
+#include "rfkill-input.h"
+
+
 MODULE_AUTHOR("Ivo van Doorn <IvDoorn@gmail.com>");
 MODULE_VERSION("1.0");
 MODULE_DESCRIPTION("RF switch support");
@@ -56,11 +60,7 @@ static void rfkill_led_trigger(struct rfkill *rfkill,
 static int rfkill_toggle_radio(struct rfkill *rfkill,
                                enum rfkill_state state)
 {
-       int retval;
-
-       retval = mutex_lock_interruptible(&rfkill->mutex);
-       if (retval)
-               return retval;
+       int retval = 0;
 
        if (state != rfkill->state) {
                retval = rfkill->toggle_radio(rfkill->data, state);
@@ -70,7 +70,6 @@ static int rfkill_toggle_radio(struct rfkill *rfkill,
                }
        }
 
-       mutex_unlock(&rfkill->mutex);
        return retval;
 }
 
@@ -93,7 +92,7 @@ void rfkill_switch_all(enum rfkill_type type, enum rfkill_state state)
        rfkill_states[type] = state;
 
        list_for_each_entry(rfkill, &rfkill_list, node) {
-               if (!rfkill->user_claim)
+               if ((!rfkill->user_claim) && (rfkill->type == type))
                        rfkill_toggle_radio(rfkill, state);
        }
 
@@ -127,6 +126,9 @@ static ssize_t rfkill_type_show(struct device *dev,
        case RFKILL_TYPE_UWB:
                type = "ultrawideband";
                break;
+       case RFKILL_TYPE_WIMAX:
+               type = "wimax";
+               break;
        default:
                BUG();
        }
@@ -154,12 +156,13 @@ static ssize_t rfkill_state_store(struct device *dev,
        if (!capable(CAP_NET_ADMIN))
                return -EPERM;
 
+       if (mutex_lock_interruptible(&rfkill->mutex))
+               return -ERESTARTSYS;
        error = rfkill_toggle_radio(rfkill,
                        state ? RFKILL_STATE_ON : RFKILL_STATE_OFF);
-       if (error)
-               return error;
+       mutex_unlock(&rfkill->mutex);
 
-       return count;
+       return error ? error : count;
 }
 
 static ssize_t rfkill_claim_show(struct device *dev,
@@ -229,7 +232,7 @@ static int rfkill_suspend(struct device *dev, pm_message_t state)
        struct rfkill *rfkill = to_rfkill(dev);
 
        if (dev->power.power_state.event != state.event) {
-               if (state.event == PM_EVENT_SUSPEND) {
+               if (state.event & PM_EVENT_SLEEP) {
                        mutex_lock(&rfkill->mutex);
 
                        if (rfkill->state == RFKILL_STATE_ON)
@@ -276,21 +279,17 @@ static struct class rfkill_class = {
 
 static int rfkill_add_switch(struct rfkill *rfkill)
 {
-       int retval;
-
-       retval = mutex_lock_interruptible(&rfkill_mutex);
-       if (retval)
-               return retval;
+       int error;
 
-       retval = rfkill_toggle_radio(rfkill, rfkill_states[rfkill->type]);
-       if (retval)
-               goto out;
+       mutex_lock(&rfkill_mutex);
 
-       list_add_tail(&rfkill->node, &rfkill_list);
+       error = rfkill_toggle_radio(rfkill, rfkill_states[rfkill->type]);
+       if (!error)
+               list_add_tail(&rfkill->node, &rfkill_list);
 
- out:
        mutex_unlock(&rfkill_mutex);
-       return retval;
+
+       return error;
 }
 
 static void rfkill_remove_switch(struct rfkill *rfkill)
@@ -341,7 +340,7 @@ EXPORT_SYMBOL(rfkill_allocate);
  * rfkill_free - Mark rfkill structure for deletion
  * @rfkill: rfkill structure to be destroyed
  *
- * Decrements reference count of rfkill structure so it is destoryed.
+ * Decrements reference count of rfkill structure so it is destroyed.
  * Note that rfkill_free() should _not_ be called after rfkill_unregister().
  */
 void rfkill_free(struct rfkill *rfkill)
@@ -387,6 +386,8 @@ int rfkill_register(struct rfkill *rfkill)
 
        if (!rfkill->toggle_radio)
                return -EINVAL;
+       if (rfkill->type >= RFKILL_TYPE_MAX)
+               return -EINVAL;
 
        snprintf(dev->bus_id, sizeof(dev->bus_id),
                 "rfkill%ld", (long)atomic_inc_return(&rfkill_no) - 1);
@@ -394,11 +395,14 @@ int rfkill_register(struct rfkill *rfkill)
        rfkill_led_trigger_register(rfkill);
 
        error = rfkill_add_switch(rfkill);
-       if (error)
+       if (error) {
+               rfkill_led_trigger_unregister(rfkill);
                return error;
+       }
 
        error = device_add(dev);
        if (error) {
+               rfkill_led_trigger_unregister(rfkill);
                rfkill_remove_switch(rfkill);
                return error;
        }
@@ -408,7 +412,7 @@ int rfkill_register(struct rfkill *rfkill)
 EXPORT_SYMBOL(rfkill_register);
 
 /**
- * rfkill_unregister - Uegister a rfkill structure.
+ * rfkill_unregister - Unregister a rfkill structure.
  * @rfkill: rfkill structure to be unregistered
  *
  * This function should be called by the network driver during device
@@ -449,5 +453,5 @@ static void __exit rfkill_exit(void)
        class_unregister(&rfkill_class);
 }
 
-module_init(rfkill_init);
+subsys_initcall(rfkill_init);
 module_exit(rfkill_exit);