[tools] fix segfault when using the maxlen argument (#4359)
[openwrt.git] / package / mac80211 / patches / 408-ath9k-serialize-ath9k_ps_-wakeup-restore-calls.patch
1 From 7446da6910f1368273a55ca99acba18828306a6e Mon Sep 17 00:00:00 2001
2 From: Gabor Juhos <juhosg@openwrt.org>
3 Date: Sun, 21 Jun 2009 16:59:53 +0200
4 Subject: [PATCH 3/3] ath9k: serialize ath9k_ps_{wakeup,restore} calls
5
6 These functions are changing the power mode of the chip, but this may
7 have unpredictable effects, if another code are trying to set the power
8 mode via 'ath9k_hw_setpower' in the same time from another context.
9
10 Changes-licensed-under: ISC
11 Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
12 ---
13 drivers/net/wireless/ath/ath9k/ath9k.h | 2 +-
14 drivers/net/wireless/ath/ath9k/hw.c | 42 ++++++++++++++++++++++----------
15 2 files changed, 30 insertions(+), 14 deletions(-)
16
17 --- a/drivers/net/wireless/ath/ath9k/ath9k.h
18 +++ b/drivers/net/wireless/ath/ath9k/ath9k.h
19 @@ -561,7 +561,7 @@ struct ath_softc {
20 u32 keymax;
21 DECLARE_BITMAP(keymap, ATH_KEYMAX);
22 u8 splitmic;
23 - atomic_t ps_usecount;
24 + unsigned long ps_usecount;
25 enum ath9k_int imask;
26 enum ath9k_ht_extprotspacing ht_extprotspacing;
27 enum ath9k_ht_macmode tx_chan_width;
28 --- a/drivers/net/wireless/ath/ath9k/hw.c
29 +++ b/drivers/net/wireless/ath/ath9k/hw.c
30 @@ -2787,23 +2787,39 @@ bool ath9k_hw_setpower(struct ath_hw *ah
31
32 void ath9k_ps_wakeup(struct ath_softc *sc)
33 {
34 - if (atomic_inc_return(&sc->ps_usecount) == 1)
35 - if (sc->sc_ah->power_mode != ATH9K_PM_AWAKE) {
36 - sc->sc_ah->restore_mode = sc->sc_ah->power_mode;
37 - ath9k_hw_setpower(sc->sc_ah, ATH9K_PM_AWAKE);
38 - }
39 + unsigned long flags;
40 +
41 + spin_lock_irqsave(&sc->sc_pm_lock, flags);
42 + if (++sc->ps_usecount != 1)
43 + goto unlock;
44 +
45 + if (sc->sc_ah->power_mode != ATH9K_PM_AWAKE) {
46 + sc->sc_ah->restore_mode = sc->sc_ah->power_mode;
47 + ath9k_hw_setpower_nolock(sc->sc_ah, ATH9K_PM_AWAKE);
48 + }
49 +
50 + unlock:
51 + spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
52 }
53
54 void ath9k_ps_restore(struct ath_softc *sc)
55 {
56 - if (atomic_dec_and_test(&sc->ps_usecount))
57 - if ((sc->hw->conf.flags & IEEE80211_CONF_PS) &&
58 - !(sc->sc_flags & (SC_OP_WAIT_FOR_BEACON |
59 - SC_OP_WAIT_FOR_CAB |
60 - SC_OP_WAIT_FOR_PSPOLL_DATA |
61 - SC_OP_WAIT_FOR_TX_ACK)))
62 - ath9k_hw_setpower(sc->sc_ah,
63 - sc->sc_ah->restore_mode);
64 + unsigned long flags;
65 +
66 + spin_lock_irqsave(&sc->sc_pm_lock, flags);
67 + if (--sc->ps_usecount != 0)
68 + goto unlock;
69 +
70 + if ((sc->hw->conf.flags & IEEE80211_CONF_PS) &&
71 + !(sc->sc_flags & (SC_OP_WAIT_FOR_BEACON |
72 + SC_OP_WAIT_FOR_CAB |
73 + SC_OP_WAIT_FOR_PSPOLL_DATA |
74 + SC_OP_WAIT_FOR_TX_ACK)))
75 + ath9k_hw_setpower_nolock(sc->sc_ah,
76 + sc->sc_ah->restore_mode);
77 +
78 + unlock:
79 + spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
80 }
81
82 /*
This page took 0.047811 seconds and 5 git commands to generate.