309-02-brcmfmac-fix-sdio-sg-table-alloc-crash.patch 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. From: Hante Meuleman <meuleman@broadcom.com>
  2. Date: Tue, 19 Jan 2016 12:39:24 +0100
  3. Subject: [PATCH] brcmfmac: fix sdio sg table alloc crash
  4. With commit 7d34b0560567 ("brcmfmac: Move all module parameters to
  5. one place") a bug was introduced causing a null pointer exception.
  6. This patch fixes the bug by initializing the sg table till after
  7. the settings have been initialized.
  8. Fixes: 7d34b0560567 ("brcmfmac: Move all module parameters to one place")
  9. Reported-by: Marc Zyngier <marc.zyngier@arm.com>
  10. Tested-by: Marc Zyngier <marc.zyngier@arm.com>
  11. Reviewed-by: Arend Van Spriel <arend@broadcom.com>
  12. Reviewed-by: Franky (Zhenhui) Lin <frankyl@broadcom.com>
  13. Reviewed-by: Pieter-Paul Giesberts <pieterpg@broadcom.com>
  14. Signed-off-by: Hante Meuleman <meuleman@broadcom.com>
  15. Signed-off-by: Arend van Spriel <arend@broadcom.com>
  16. Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
  17. ---
  18. --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
  19. +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/bcmsdh.c
  20. @@ -879,11 +879,24 @@ int brcmf_sdiod_abort(struct brcmf_sdio_
  21. return 0;
  22. }
  23. -static void brcmf_sdiod_sgtable_alloc(struct brcmf_sdio_dev *sdiodev)
  24. +void brcmf_sdiod_sgtable_alloc(struct brcmf_sdio_dev *sdiodev)
  25. {
  26. + struct sdio_func *func;
  27. + struct mmc_host *host;
  28. + uint max_blocks;
  29. uint nents;
  30. int err;
  31. + func = sdiodev->func[2];
  32. + host = func->card->host;
  33. + sdiodev->sg_support = host->max_segs > 1;
  34. + max_blocks = min_t(uint, host->max_blk_count, 511u);
  35. + sdiodev->max_request_size = min_t(uint, host->max_req_size,
  36. + max_blocks * func->cur_blksize);
  37. + sdiodev->max_segment_count = min_t(uint, host->max_segs,
  38. + SG_MAX_SINGLE_ALLOC);
  39. + sdiodev->max_segment_size = host->max_seg_size;
  40. +
  41. if (!sdiodev->sg_support)
  42. return;
  43. @@ -1021,9 +1034,6 @@ static void brcmf_sdiod_host_fixup(struc
  44. static int brcmf_sdiod_probe(struct brcmf_sdio_dev *sdiodev)
  45. {
  46. - struct sdio_func *func;
  47. - struct mmc_host *host;
  48. - uint max_blocks;
  49. int ret = 0;
  50. sdiodev->num_funcs = 2;
  51. @@ -1054,26 +1064,6 @@ static int brcmf_sdiod_probe(struct brcm
  52. goto out;
  53. }
  54. - /*
  55. - * determine host related variables after brcmf_sdiod_probe()
  56. - * as func->cur_blksize is properly set and F2 init has been
  57. - * completed successfully.
  58. - */
  59. - func = sdiodev->func[2];
  60. - host = func->card->host;
  61. - sdiodev->sg_support = host->max_segs > 1;
  62. - max_blocks = min_t(uint, host->max_blk_count, 511u);
  63. - sdiodev->max_request_size = min_t(uint, host->max_req_size,
  64. - max_blocks * func->cur_blksize);
  65. - sdiodev->max_segment_count = min_t(uint, host->max_segs,
  66. - SG_MAX_SINGLE_ALLOC);
  67. - sdiodev->max_segment_size = host->max_seg_size;
  68. -
  69. - /* allocate scatter-gather table. sg support
  70. - * will be disabled upon allocation failure.
  71. - */
  72. - brcmf_sdiod_sgtable_alloc(sdiodev);
  73. -
  74. ret = brcmf_sdiod_freezer_attach(sdiodev);
  75. if (ret)
  76. goto out;
  77. @@ -1084,7 +1074,7 @@ static int brcmf_sdiod_probe(struct brcm
  78. ret = -ENODEV;
  79. goto out;
  80. }
  81. - brcmf_sdiod_host_fixup(host);
  82. + brcmf_sdiod_host_fixup(sdiodev->func[2]->card->host);
  83. out:
  84. if (ret)
  85. brcmf_sdiod_remove(sdiodev);
  86. --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c
  87. +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.c
  88. @@ -4114,6 +4114,11 @@ struct brcmf_sdio *brcmf_sdio_probe(stru
  89. goto fail;
  90. }
  91. + /* allocate scatter-gather table. sg support
  92. + * will be disabled upon allocation failure.
  93. + */
  94. + brcmf_sdiod_sgtable_alloc(bus->sdiodev);
  95. +
  96. /* Query the F2 block size, set roundup accordingly */
  97. bus->blocksize = bus->sdiodev->func[2]->cur_blksize;
  98. bus->roundup = min(max_roundup, bus->blocksize);
  99. --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.h
  100. +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/sdio.h
  101. @@ -342,6 +342,7 @@ int brcmf_sdiod_ramrw(struct brcmf_sdio_
  102. /* Issue an abort to the specified function */
  103. int brcmf_sdiod_abort(struct brcmf_sdio_dev *sdiodev, uint fn);
  104. +void brcmf_sdiod_sgtable_alloc(struct brcmf_sdio_dev *sdiodev);
  105. void brcmf_sdiod_change_state(struct brcmf_sdio_dev *sdiodev,
  106. enum brcmf_sdiod_state state);
  107. #ifdef CONFIG_PM_SLEEP