mac80211: backport today's brcmfmac changes
[openwrt/svn-archive/archive.git] / package / kernel / mac80211 / patches / 375-brcmfmac-simplify-check-stripping-v2-NVRAM.patch
1 From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <zajec5@gmail.com>
2 Date: Wed, 20 May 2015 09:34:21 +0200
3 Subject: [PATCH] brcmfmac: simplify check stripping v2 NVRAM
4 MIME-Version: 1.0
5 Content-Type: text/plain; charset=UTF-8
6 Content-Transfer-Encoding: 8bit
7
8 Comparing NVRAM entry with a full filtering string is simpler than
9 comparing it with a short prefix and then checking random chars at magic
10 offsets. The cost of snprintf relatively low, we execute it just once.
11 Tested on BCM43602 with NVRAM hacked to use V2 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 @@ -25,7 +25,7 @@
20
21 #define BRCMF_FW_MAX_NVRAM_SIZE 64000
22 #define BRCMF_FW_NVRAM_DEVPATH_LEN 19 /* devpath0=pcie/1/4/ */
23 -#define BRCMF_FW_NVRAM_PCIEDEV_LEN 9 /* pcie/1/4/ */
24 +#define BRCMF_FW_NVRAM_PCIEDEV_LEN 10 /* pcie/1/4/ + \0 */
25
26 char brcmf_firmware_path[BRCMF_FW_PATH_LEN];
27 module_param_string(firmware_path, brcmf_firmware_path,
28 @@ -297,6 +297,8 @@ fail:
29 static void brcmf_fw_strip_multi_v2(struct nvram_parser *nvp, u16 domain_nr,
30 u16 bus_nr)
31 {
32 + char prefix[BRCMF_FW_NVRAM_PCIEDEV_LEN];
33 + size_t len;
34 u32 i, j;
35 u8 *nvram;
36
37 @@ -308,14 +310,13 @@ static void brcmf_fw_strip_multi_v2(stru
38 * Valid entries are of type pcie/X/Y/ where X = domain_nr and
39 * Y = bus_nr.
40 */
41 + snprintf(prefix, sizeof(prefix), "pcie/%d/%d/", domain_nr, bus_nr);
42 + len = strlen(prefix);
43 i = 0;
44 j = 0;
45 - while (i < nvp->nvram_len - BRCMF_FW_NVRAM_PCIEDEV_LEN) {
46 - if ((strncmp(&nvp->nvram[i], "pcie/", 5) == 0) &&
47 - (nvp->nvram[i + 6] == '/') && (nvp->nvram[i + 8] == '/') &&
48 - ((nvp->nvram[i + 5] - '0') == domain_nr) &&
49 - ((nvp->nvram[i + 7] - '0') == bus_nr)) {
50 - i += BRCMF_FW_NVRAM_PCIEDEV_LEN;
51 + while (i < nvp->nvram_len - len) {
52 + if (strncmp(&nvp->nvram[i], prefix, len) == 0) {
53 + i += len;
54 while (nvp->nvram[i] != 0) {
55 nvram[j] = nvp->nvram[i];
56 i++;