Skip to content

Commit

Permalink
Revert "rfkill: Add rfkill-any LED trigger"
Browse files Browse the repository at this point in the history
This reverts commit 73f4f76.

As Mike reported, and I should've seen in review, we can't call
the new LED functions, which acquire the mutex, from places like
rfkill_set_sw_state() that are documented to be callable from
any context the user likes to use. For Mike's case it led to a
deadlock, but other scenarios are possible.

Reported-by: Михаил Кринкин <[email protected]>
Signed-off-by: Johannes Berg <[email protected]>
  • Loading branch information
jmberg-intel committed Dec 20, 2016
1 parent e77a8be commit 7b85498
Showing 1 changed file with 1 addition and 74 deletions.
75 changes: 1 addition & 74 deletions net/rfkill/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,47 +176,6 @@ static void rfkill_led_trigger_unregister(struct rfkill *rfkill)
{
led_trigger_unregister(&rfkill->led_trigger);
}

static struct led_trigger rfkill_any_led_trigger;

static void __rfkill_any_led_trigger_event(void)
{
enum led_brightness brightness = LED_OFF;
struct rfkill *rfkill;

list_for_each_entry(rfkill, &rfkill_list, node) {
if (!(rfkill->state & RFKILL_BLOCK_ANY)) {
brightness = LED_FULL;
break;
}
}

led_trigger_event(&rfkill_any_led_trigger, brightness);
}

static void rfkill_any_led_trigger_event(void)
{
mutex_lock(&rfkill_global_mutex);
__rfkill_any_led_trigger_event();
mutex_unlock(&rfkill_global_mutex);
}

static void rfkill_any_led_trigger_activate(struct led_classdev *led_cdev)
{
rfkill_any_led_trigger_event();
}

static int rfkill_any_led_trigger_register(void)
{
rfkill_any_led_trigger.name = "rfkill-any";
rfkill_any_led_trigger.activate = rfkill_any_led_trigger_activate;
return led_trigger_register(&rfkill_any_led_trigger);
}

static void rfkill_any_led_trigger_unregister(void)
{
led_trigger_unregister(&rfkill_any_led_trigger);
}
#else
static void rfkill_led_trigger_event(struct rfkill *rfkill)
{
Expand All @@ -230,23 +189,6 @@ static inline int rfkill_led_trigger_register(struct rfkill *rfkill)
static inline void rfkill_led_trigger_unregister(struct rfkill *rfkill)
{
}

static void __rfkill_any_led_trigger_event(void)
{
}

static void rfkill_any_led_trigger_event(void)
{
}

static int rfkill_any_led_trigger_register(void)
{
return 0;
}

static void rfkill_any_led_trigger_unregister(void)
{
}
#endif /* CONFIG_RFKILL_LEDS */

static void rfkill_fill_event(struct rfkill_event *ev, struct rfkill *rfkill,
Expand Down Expand Up @@ -355,7 +297,6 @@ static void rfkill_set_block(struct rfkill *rfkill, bool blocked)
spin_unlock_irqrestore(&rfkill->lock, flags);

rfkill_led_trigger_event(rfkill);
__rfkill_any_led_trigger_event();

if (prev != curr)
rfkill_event(rfkill);
Expand Down Expand Up @@ -536,7 +477,6 @@ bool rfkill_set_hw_state(struct rfkill *rfkill, bool blocked)
spin_unlock_irqrestore(&rfkill->lock, flags);

rfkill_led_trigger_event(rfkill);
rfkill_any_led_trigger_event();

if (rfkill->registered && prev != blocked)
schedule_work(&rfkill->uevent_work);
Expand Down Expand Up @@ -580,7 +520,6 @@ bool rfkill_set_sw_state(struct rfkill *rfkill, bool blocked)
schedule_work(&rfkill->uevent_work);

rfkill_led_trigger_event(rfkill);
rfkill_any_led_trigger_event();

return blocked;
}
Expand Down Expand Up @@ -630,7 +569,6 @@ void rfkill_set_states(struct rfkill *rfkill, bool sw, bool hw)
schedule_work(&rfkill->uevent_work);

rfkill_led_trigger_event(rfkill);
rfkill_any_led_trigger_event();
}
}
EXPORT_SYMBOL(rfkill_set_states);
Expand Down Expand Up @@ -874,10 +812,8 @@ static int rfkill_resume(struct device *dev)
rfkill->suspended = false;

if (!rfkill->persistent) {
mutex_lock(&rfkill_global_mutex);
cur = !!(rfkill->state & RFKILL_BLOCK_SW);
rfkill_set_block(rfkill, cur);
mutex_unlock(&rfkill_global_mutex);
}

if (rfkill->ops->poll && !rfkill->polling_paused)
Expand Down Expand Up @@ -1049,7 +985,6 @@ int __must_check rfkill_register(struct rfkill *rfkill)
#endif
}

__rfkill_any_led_trigger_event();
rfkill_send_events(rfkill, RFKILL_OP_ADD);

mutex_unlock(&rfkill_global_mutex);
Expand Down Expand Up @@ -1082,7 +1017,6 @@ void rfkill_unregister(struct rfkill *rfkill)
mutex_lock(&rfkill_global_mutex);
rfkill_send_events(rfkill, RFKILL_OP_DEL);
list_del_init(&rfkill->node);
__rfkill_any_led_trigger_event();
mutex_unlock(&rfkill_global_mutex);

rfkill_led_trigger_unregister(rfkill);
Expand Down Expand Up @@ -1335,10 +1269,6 @@ static int __init rfkill_init(void)
if (error)
goto error_misc;

error = rfkill_any_led_trigger_register();
if (error)
goto error_led_trigger;

#ifdef CONFIG_RFKILL_INPUT
error = rfkill_handler_init();
if (error)
Expand All @@ -1349,10 +1279,8 @@ static int __init rfkill_init(void)

#ifdef CONFIG_RFKILL_INPUT
error_input:
rfkill_any_led_trigger_unregister();
#endif
error_led_trigger:
misc_deregister(&rfkill_miscdev);
#endif
error_misc:
class_unregister(&rfkill_class);
error_class:
Expand All @@ -1365,7 +1293,6 @@ static void __exit rfkill_exit(void)
#ifdef CONFIG_RFKILL_INPUT
rfkill_handler_exit();
#endif
rfkill_any_led_trigger_unregister();
misc_deregister(&rfkill_miscdev);
class_unregister(&rfkill_class);
}
Expand Down

0 comments on commit 7b85498

Please sign in to comment.