375-brcmfmac-simplify-check-stripping-v2-NVRAM.patch 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <[email protected]>
  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. Comparing NVRAM entry with a full filtering string is simpler than
  8. comparing it with a short prefix and then checking random chars at magic
  9. offsets. The cost of snprintf relatively low, we execute it just once.
  10. Tested on BCM43602 with NVRAM hacked to use V2 format.
  11. Signed-off-by: Rafał Miłecki <[email protected]>
  12. Signed-off-by: Kalle Valo <[email protected]>
  13. ---
  14. --- a/drivers/net/wireless/brcm80211/brcmfmac/firmware.c
  15. +++ b/drivers/net/wireless/brcm80211/brcmfmac/firmware.c
  16. @@ -25,7 +25,7 @@
  17. #define BRCMF_FW_MAX_NVRAM_SIZE 64000
  18. #define BRCMF_FW_NVRAM_DEVPATH_LEN 19 /* devpath0=pcie/1/4/ */
  19. -#define BRCMF_FW_NVRAM_PCIEDEV_LEN 9 /* pcie/1/4/ */
  20. +#define BRCMF_FW_NVRAM_PCIEDEV_LEN 10 /* pcie/1/4/ + \0 */
  21. char brcmf_firmware_path[BRCMF_FW_PATH_LEN];
  22. module_param_string(firmware_path, brcmf_firmware_path,
  23. @@ -297,6 +297,8 @@ fail:
  24. static void brcmf_fw_strip_multi_v2(struct nvram_parser *nvp, u16 domain_nr,
  25. u16 bus_nr)
  26. {
  27. + char prefix[BRCMF_FW_NVRAM_PCIEDEV_LEN];
  28. + size_t len;
  29. u32 i, j;
  30. u8 *nvram;
  31. @@ -308,14 +310,13 @@ static void brcmf_fw_strip_multi_v2(stru
  32. * Valid entries are of type pcie/X/Y/ where X = domain_nr and
  33. * Y = bus_nr.
  34. */
  35. + snprintf(prefix, sizeof(prefix), "pcie/%d/%d/", domain_nr, bus_nr);
  36. + len = strlen(prefix);
  37. i = 0;
  38. j = 0;
  39. - while (i < nvp->nvram_len - BRCMF_FW_NVRAM_PCIEDEV_LEN) {
  40. - if ((strncmp(&nvp->nvram[i], "pcie/", 5) == 0) &&
  41. - (nvp->nvram[i + 6] == '/') && (nvp->nvram[i + 8] == '/') &&
  42. - ((nvp->nvram[i + 5] - '0') == domain_nr) &&
  43. - ((nvp->nvram[i + 7] - '0') == bus_nr)) {
  44. - i += BRCMF_FW_NVRAM_PCIEDEV_LEN;
  45. + while (i < nvp->nvram_len - len) {
  46. + if (strncmp(&nvp->nvram[i], prefix, len) == 0) {
  47. + i += len;
  48. while (nvp->nvram[i] != 0) {
  49. nvram[j] = nvp->nvram[i];
  50. i++;