mac80211: backport today's brcmfmac changes
[openwrt/openwrt.git] / package / kernel / mac80211 / patches / 376-brcmfmac-simplify-check-finding-NVRAM-v1-device-path.patch
1 From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <zajec5@gmail.com>
2 Date: Wed, 20 May 2015 11:01:08 +0200
3 Subject: [PATCH] brcmfmac: simplify check finding NVRAM v1 device path
4 MIME-Version: 1.0
5 Content-Type: text/plain; charset=UTF-8
6 Content-Transfer-Encoding: 8bit
7
8 With a simple use of snprintf and small buffer we can compare NVRAM
9 entry value with a full string. This way we avoid checking random chars
10 at magic offsets.
11 Tested on BCM43602 with NVRAM hacked to use v1 format.
12
13 Signed-off-by: Rafał Miłecki <zajec5@gmail.com>
14 Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
15 ---
16
17 --- a/drivers/net/wireless/brcm80211/brcmfmac/firmware.c
18 +++ b/drivers/net/wireless/brcm80211/brcmfmac/firmware.c
19 @@ -222,6 +222,10 @@ static int brcmf_init_nvram_parser(struc
20 static void brcmf_fw_strip_multi_v1(struct nvram_parser *nvp, u16 domain_nr,
21 u16 bus_nr)
22 {
23 + /* Device path with a leading '=' key-value separator */
24 + char pcie_path[] = "=pcie/?/?";
25 + size_t pcie_len;
26 +
27 u32 i, j;
28 bool found;
29 u8 *nvram;
30 @@ -238,6 +242,9 @@ static void brcmf_fw_strip_multi_v1(stru
31 /* First search for the devpathX and see if it is the configuration
32 * for domain_nr/bus_nr. Search complete nvp
33 */
34 + snprintf(pcie_path, sizeof(pcie_path), "=pcie/%d/%d", domain_nr,
35 + bus_nr);
36 + pcie_len = strlen(pcie_path);
37 found = false;
38 i = 0;
39 while (i < nvp->nvram_len - BRCMF_FW_NVRAM_DEVPATH_LEN) {
40 @@ -245,13 +252,10 @@ static void brcmf_fw_strip_multi_v1(stru
41 * Y = domain_nr, Z = bus_nr, X = virtual ID
42 */
43 if ((strncmp(&nvp->nvram[i], "devpath", 7) == 0) &&
44 - (strncmp(&nvp->nvram[i + 8], "=pcie/", 6) == 0)) {
45 - if (((nvp->nvram[i + 14] - '0') == domain_nr) &&
46 - ((nvp->nvram[i + 16] - '0') == bus_nr)) {
47 - id = nvp->nvram[i + 7] - '0';
48 - found = true;
49 - break;
50 - }
51 + (strncmp(&nvp->nvram[i + 8], pcie_path, pcie_len) == 0)) {
52 + id = nvp->nvram[i + 7] - '0';
53 + found = true;
54 + break;
55 }
56 while (nvp->nvram[i] != 0)
57 i++;