Commit e10e0dfe authored by Henrique de Moraes Holschuh's avatar Henrique de Moraes Holschuh Committed by John W. Linville

rfkill: protect suspended rfkill controllers

Guard rfkill controllers attached to a rfkill class against state changes
after class suspend has been issued.
Signed-off-by: default avatarHenrique de Moraes Holschuh <hmh@hmh.eng.br>
Acked-by: default avatarIvo van Doorn <IvDoorn@gmail.com>
Signed-off-by: default avatarJohn W. Linville <linville@tuxdriver.com>
parent aaa15535
...@@ -363,6 +363,11 @@ This rule exists because users of the rfkill subsystem expect to get (and set, ...@@ -363,6 +363,11 @@ This rule exists because users of the rfkill subsystem expect to get (and set,
when possible) the overall transmitter rfkill state, not of a particular rfkill when possible) the overall transmitter rfkill state, not of a particular rfkill
line. line.
5. During suspend, the rfkill class will attempt to soft-block the radio
through a call to rfkill->toggle_radio, and will try to restore its previous
state during resume. After a rfkill class is suspended, it will *not* call
rfkill->toggle_radio until it is resumed.
Example of a WLAN wireless driver connected to the rfkill subsystem: Example of a WLAN wireless driver connected to the rfkill subsystem:
-------------------------------------------------------------------- --------------------------------------------------------------------
......
...@@ -150,6 +150,8 @@ static void update_rfkill_state(struct rfkill *rfkill) ...@@ -150,6 +150,8 @@ static void update_rfkill_state(struct rfkill *rfkill)
* calls and handling all the red tape such as issuing notifications * calls and handling all the red tape such as issuing notifications
* if the call is successful. * if the call is successful.
* *
* Suspended devices are not touched at all, and -EAGAIN is returned.
*
* Note that the @force parameter cannot override a (possibly cached) * Note that the @force parameter cannot override a (possibly cached)
* state of RFKILL_STATE_HARD_BLOCKED. Any device making use of * state of RFKILL_STATE_HARD_BLOCKED. Any device making use of
* RFKILL_STATE_HARD_BLOCKED implements either get_state() or * RFKILL_STATE_HARD_BLOCKED implements either get_state() or
...@@ -168,6 +170,9 @@ static int rfkill_toggle_radio(struct rfkill *rfkill, ...@@ -168,6 +170,9 @@ static int rfkill_toggle_radio(struct rfkill *rfkill,
int retval = 0; int retval = 0;
enum rfkill_state oldstate, newstate; enum rfkill_state oldstate, newstate;
if (unlikely(rfkill->dev.power.power_state.event & PM_EVENT_SLEEP))
return -EBUSY;
oldstate = rfkill->state; oldstate = rfkill->state;
if (rfkill->get_state && !force && if (rfkill->get_state && !force &&
...@@ -214,7 +219,7 @@ static int rfkill_toggle_radio(struct rfkill *rfkill, ...@@ -214,7 +219,7 @@ static int rfkill_toggle_radio(struct rfkill *rfkill,
* *
* This function toggles the state of all switches of given type, * This function toggles the state of all switches of given type,
* unless a specific switch is claimed by userspace (in which case, * unless a specific switch is claimed by userspace (in which case,
* that switch is left alone). * that switch is left alone) or suspended.
*/ */
void rfkill_switch_all(enum rfkill_type type, enum rfkill_state state) void rfkill_switch_all(enum rfkill_type type, enum rfkill_state state)
{ {
...@@ -239,8 +244,8 @@ EXPORT_SYMBOL(rfkill_switch_all); ...@@ -239,8 +244,8 @@ EXPORT_SYMBOL(rfkill_switch_all);
/** /**
* rfkill_epo - emergency power off all transmitters * rfkill_epo - emergency power off all transmitters
* *
* This kicks all rfkill devices to RFKILL_STATE_SOFT_BLOCKED, ignoring * This kicks all non-suspended rfkill devices to RFKILL_STATE_SOFT_BLOCKED,
* everything in its path but rfkill_mutex and rfkill->mutex. * ignoring everything in its path but rfkill_mutex and rfkill->mutex.
*/ */
void rfkill_epo(void) void rfkill_epo(void)
{ {
...@@ -458,13 +463,14 @@ static int rfkill_resume(struct device *dev) ...@@ -458,13 +463,14 @@ static int rfkill_resume(struct device *dev)
if (dev->power.power_state.event != PM_EVENT_ON) { if (dev->power.power_state.event != PM_EVENT_ON) {
mutex_lock(&rfkill->mutex); mutex_lock(&rfkill->mutex);
dev->power.power_state.event = PM_EVENT_ON;
/* restore radio state AND notify everybody */ /* restore radio state AND notify everybody */
rfkill_toggle_radio(rfkill, rfkill->state, 1); rfkill_toggle_radio(rfkill, rfkill->state, 1);
mutex_unlock(&rfkill->mutex); mutex_unlock(&rfkill->mutex);
} }
dev->power.power_state = PMSG_ON;
return 0; return 0;
} }
#else #else
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment