344-0002-brcmfmac-Limit-memory-allocs-to-64K.patch 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. From: Hante Meuleman <meuleman@broadcom.com>
  2. Date: Wed, 17 Feb 2016 11:26:51 +0100
  3. Subject: [PATCH] brcmfmac: Limit memory allocs to <64K
  4. Some systems have problems with allocating memory allocation larger
  5. then 64K. Often on unload/load or suspend/resume a failure is
  6. reported: Could not allocate wiphy device. This patch makes the
  7. escan intermediate storage buf dynamically allocated, and smaller
  8. than 64K.
  9. Reviewed-by: Arend Van Spriel <arend@broadcom.com>
  10. Reviewed-by: Franky (Zhenhui) Lin <frankyl@broadcom.com>
  11. Reviewed-by: Pieter-Paul Giesberts <pieterpg@broadcom.com>
  12. Signed-off-by: Hante Meuleman <meuleman@broadcom.com>
  13. Signed-off-by: Arend van Spriel <arend@broadcom.com>
  14. Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
  15. ---
  16. --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c
  17. +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c
  18. @@ -1125,7 +1125,7 @@ brcmf_cfg80211_escan(struct wiphy *wiphy
  19. /* Arm scan timeout timer */
  20. mod_timer(&cfg->escan_timeout, jiffies +
  21. - WL_ESCAN_TIMER_INTERVAL_MS * HZ / 1000);
  22. + BRCMF_ESCAN_TIMER_INTERVAL_MS * HZ / 1000);
  23. return 0;
  24. @@ -3020,7 +3020,7 @@ brcmf_cfg80211_escan_handler(struct brcm
  25. list = (struct brcmf_scan_results *)
  26. cfg->escan_info.escan_buf;
  27. - if (bi_length > WL_ESCAN_BUF_SIZE - list->buflen) {
  28. + if (bi_length > BRCMF_ESCAN_BUF_SIZE - list->buflen) {
  29. brcmf_err("Buffer is too small: ignoring\n");
  30. goto exit;
  31. }
  32. @@ -3033,8 +3033,8 @@ brcmf_cfg80211_escan_handler(struct brcm
  33. bss_info_le))
  34. goto exit;
  35. }
  36. - memcpy(&(cfg->escan_info.escan_buf[list->buflen]),
  37. - bss_info_le, bi_length);
  38. + memcpy(&cfg->escan_info.escan_buf[list->buflen], bss_info_le,
  39. + bi_length);
  40. list->version = le32_to_cpu(bss_info_le->version);
  41. list->buflen += bi_length;
  42. list->count++;
  43. @@ -5402,14 +5402,14 @@ static void brcmf_deinit_priv_mem(struct
  44. {
  45. kfree(cfg->conf);
  46. cfg->conf = NULL;
  47. - kfree(cfg->escan_ioctl_buf);
  48. - cfg->escan_ioctl_buf = NULL;
  49. kfree(cfg->extra_buf);
  50. cfg->extra_buf = NULL;
  51. kfree(cfg->wowl.nd);
  52. cfg->wowl.nd = NULL;
  53. kfree(cfg->wowl.nd_info);
  54. cfg->wowl.nd_info = NULL;
  55. + kfree(cfg->escan_info.escan_buf);
  56. + cfg->escan_info.escan_buf = NULL;
  57. }
  58. static s32 brcmf_init_priv_mem(struct brcmf_cfg80211_info *cfg)
  59. @@ -5417,9 +5417,6 @@ static s32 brcmf_init_priv_mem(struct br
  60. cfg->conf = kzalloc(sizeof(*cfg->conf), GFP_KERNEL);
  61. if (!cfg->conf)
  62. goto init_priv_mem_out;
  63. - cfg->escan_ioctl_buf = kzalloc(BRCMF_DCMD_MEDLEN, GFP_KERNEL);
  64. - if (!cfg->escan_ioctl_buf)
  65. - goto init_priv_mem_out;
  66. cfg->extra_buf = kzalloc(WL_EXTRA_BUF_MAX, GFP_KERNEL);
  67. if (!cfg->extra_buf)
  68. goto init_priv_mem_out;
  69. @@ -5431,6 +5428,9 @@ static s32 brcmf_init_priv_mem(struct br
  70. GFP_KERNEL);
  71. if (!cfg->wowl.nd_info)
  72. goto init_priv_mem_out;
  73. + cfg->escan_info.escan_buf = kzalloc(BRCMF_ESCAN_BUF_SIZE, GFP_KERNEL);
  74. + if (!cfg->escan_info.escan_buf)
  75. + goto init_priv_mem_out;
  76. return 0;
  77. --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.h
  78. +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.h
  79. @@ -28,8 +28,11 @@
  80. #define WL_ROAM_TRIGGER_LEVEL -75
  81. #define WL_ROAM_DELTA 20
  82. -#define WL_ESCAN_BUF_SIZE (1024 * 64)
  83. -#define WL_ESCAN_TIMER_INTERVAL_MS 10000 /* E-Scan timeout */
  84. +/* Keep BRCMF_ESCAN_BUF_SIZE below 64K (65536). Allocing over 64K can be
  85. + * problematic on some systems and should be avoided.
  86. + */
  87. +#define BRCMF_ESCAN_BUF_SIZE 65000
  88. +#define BRCMF_ESCAN_TIMER_INTERVAL_MS 10000 /* E-Scan timeout */
  89. #define WL_ESCAN_ACTION_START 1
  90. #define WL_ESCAN_ACTION_CONTINUE 2
  91. @@ -205,7 +208,7 @@ enum wl_escan_state {
  92. struct escan_info {
  93. u32 escan_state;
  94. - u8 escan_buf[WL_ESCAN_BUF_SIZE];
  95. + u8 *escan_buf;
  96. struct wiphy *wiphy;
  97. struct brcmf_if *ifp;
  98. s32 (*run)(struct brcmf_cfg80211_info *cfg, struct brcmf_if *ifp,
  99. @@ -278,7 +281,6 @@ struct brcmf_cfg80211_wowl {
  100. * @escan_info: escan information.
  101. * @escan_timeout: Timer for catch scan timeout.
  102. * @escan_timeout_work: scan timeout worker.
  103. - * @escan_ioctl_buf: dongle command buffer for escan commands.
  104. * @vif_list: linked list of vif instances.
  105. * @vif_cnt: number of vif instances.
  106. * @vif_event: vif event signalling.
  107. @@ -309,7 +311,6 @@ struct brcmf_cfg80211_info {
  108. struct escan_info escan_info;
  109. struct timer_list escan_timeout;
  110. struct work_struct escan_timeout_work;
  111. - u8 *escan_ioctl_buf;
  112. struct list_head vif_list;
  113. struct brcmf_cfg80211_vif_event vif_event;
  114. struct completion vif_disabled;