mac80211: brcmfmac: fix lockup related to P2P interface
[openwrt.git] / package / kernel / mac80211 / patches / 353-brcmfmac-slightly-simplify-building-interface-combin.patch
1 From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <zajec5@gmail.com>
2 Date: Tue, 7 Jun 2016 21:10:18 +0200
3 Subject: [PATCH] brcmfmac: slightly simplify building interface combinations
4 MIME-Version: 1.0
5 Content-Type: text/plain; charset=UTF-8
6 Content-Transfer-Encoding: 8bit
7
8 This change reorders some operations in brcmf_setup_ifmodes in hope to
9 make it simpler:
10 1) It allocates arrays right before filling them. This way it's easier
11    to follow requested array length as it's immediately followed by
12    code filling it. It's easier to check e.g. why we need 4 entries for
13    P2P. Other than that it deduplicates some checks (e.g. for P2P).
14 2) It reorders code to first prepare limits and then define a new combo.
15    Previously this was mixed (e.g. we were setting num of channels
16    before preparing limits).
17 3) It modifies mbss code to use i variable just like other combos do.
18
19 Signed-off-by: Rafał Miłecki <zajec5@gmail.com>
20 Acked-by: Arend van Spriel <arend.vanspriel@broadcom.com>
21 Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
22 ---
23
24 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c
25 +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c
26 @@ -6224,29 +6224,15 @@ static int brcmf_setup_ifmodes(struct wi
27         if (!combo)
28                 goto err;
29  
30 -       c0_limits = kcalloc(p2p ? 3 : 2, sizeof(*c0_limits), GFP_KERNEL);
31 -       if (!c0_limits)
32 -               goto err;
33 -
34 -       if (p2p) {
35 -               p2p_limits = kcalloc(4, sizeof(*p2p_limits), GFP_KERNEL);
36 -               if (!p2p_limits)
37 -                       goto err;
38 -       }
39 -
40 -       if (mbss) {
41 -               mbss_limits = kcalloc(1, sizeof(*mbss_limits), GFP_KERNEL);
42 -               if (!mbss_limits)
43 -                       goto err;
44 -       }
45 -
46         wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
47                                  BIT(NL80211_IFTYPE_ADHOC) |
48                                  BIT(NL80211_IFTYPE_AP);
49  
50         c = 0;
51         i = 0;
52 -       combo[c].num_different_channels = 1;
53 +       c0_limits = kcalloc(p2p ? 3 : 2, sizeof(*c0_limits), GFP_KERNEL);
54 +       if (!c0_limits)
55 +               goto err;
56         c0_limits[i].max = 1;
57         c0_limits[i++].types = BIT(NL80211_IFTYPE_STATION);
58         if (p2p) {
59 @@ -6264,6 +6250,7 @@ static int brcmf_setup_ifmodes(struct wi
60                 c0_limits[i].max = 1;
61                 c0_limits[i++].types = BIT(NL80211_IFTYPE_AP);
62         }
63 +       combo[c].num_different_channels = 1;
64         combo[c].max_interfaces = i;
65         combo[c].n_limits = i;
66         combo[c].limits = c0_limits;
67 @@ -6271,7 +6258,9 @@ static int brcmf_setup_ifmodes(struct wi
68         if (p2p) {
69                 c++;
70                 i = 0;
71 -               combo[c].num_different_channels = 1;
72 +               p2p_limits = kcalloc(4, sizeof(*p2p_limits), GFP_KERNEL);
73 +               if (!p2p_limits)
74 +                       goto err;
75                 p2p_limits[i].max = 1;
76                 p2p_limits[i++].types = BIT(NL80211_IFTYPE_STATION);
77                 p2p_limits[i].max = 1;
78 @@ -6280,6 +6269,7 @@ static int brcmf_setup_ifmodes(struct wi
79                 p2p_limits[i++].types = BIT(NL80211_IFTYPE_P2P_CLIENT);
80                 p2p_limits[i].max = 1;
81                 p2p_limits[i++].types = BIT(NL80211_IFTYPE_P2P_DEVICE);
82 +               combo[c].num_different_channels = 1;
83                 combo[c].max_interfaces = i;
84                 combo[c].n_limits = i;
85                 combo[c].limits = p2p_limits;
86 @@ -6287,14 +6277,19 @@ static int brcmf_setup_ifmodes(struct wi
87  
88         if (mbss) {
89                 c++;
90 +               i = 0;
91 +               mbss_limits = kcalloc(1, sizeof(*mbss_limits), GFP_KERNEL);
92 +               if (!mbss_limits)
93 +                       goto err;
94 +               mbss_limits[i].max = 4;
95 +               mbss_limits[i++].types = BIT(NL80211_IFTYPE_AP);
96                 combo[c].beacon_int_infra_match = true;
97                 combo[c].num_different_channels = 1;
98 -               mbss_limits[0].max = 4;
99 -               mbss_limits[0].types = BIT(NL80211_IFTYPE_AP);
100                 combo[c].max_interfaces = 4;
101 -               combo[c].n_limits = 1;
102 +               combo[c].n_limits = i;
103                 combo[c].limits = mbss_limits;
104         }
105 +
106         wiphy->n_iface_combinations = n_combos;
107         wiphy->iface_combinations = combo;
108         return 0;