kernel-5.9-buildfix.patch 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. From: Joan Bruguera <joanbrugueram@gmail.com>
  2. Date: Sun, 13 Sep 2020 07:33:32 +0200
  3. Subject: Get rid of get_fs/set_fs calls in Broadcom WL driver.
  4. Origin: https://gist.github.com/joanbm/5c640ac074d27fd1d82c74a5b67a1290
  5. Fixes linux-next where get_fs/set_fs is already removed for some architectures.
  6. NB: Some checks in wlc_ioctl_internal are likely superfluous,
  7. but I'm not familiar enough with the driver to remove them with confidence.
  8. See also: https://lwn.net/Articles/722267/
  9. https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/commit/arch/x86/include/asm/uaccess.h?h=next-20200911&id=47058bb54b57962b3958a936ddbc59355e4c5504
  10. https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/commit/include/linux/uaccess.h?h=next-20200911&id=5e6e9852d6f76e01b2e6803c74258afa5b432bc5
  11. Signed-off-by: Joan Bruguera <joanbrugueram@gmail.com>
  12. ---
  13. src/wl/sys/wl_cfg80211_hybrid.c | 29 ++-----------------------
  14. src/wl/sys/wl_iw.c | 25 ++--------------------
  15. src/wl/sys/wl_linux.c | 40 ++++++++++++++++++++++++++++++-----
  16. src/wl/sys/wl_linux.h | 2 ++
  17. src/wl/sys/wlc_pub.h | 1 +
  18. 5 files changed, 42 insertions(+), 55 deletions(-)
  19. diff --git a/src/wl/sys/wl_cfg80211_hybrid.c b/src/wl/sys/wl_cfg80211_hybrid.c
  20. index 8e01841..111ec5a 100644
  21. --- a/src/wl/sys/wl_cfg80211_hybrid.c
  22. +++ b/src/wl/sys/wl_cfg80211_hybrid.c
  23. @@ -41,6 +41,7 @@
  24. #include <wlioctl.h>
  25. #include <proto/802.11.h>
  26. #include <wl_cfg80211_hybrid.h>
  27. +#include <wl_linux.h>
  28. #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0)
  29. #include <linux/sched/signal.h>
  30. @@ -442,34 +443,8 @@ static void key_endian_to_host(struct wl_wsec_key *key)
  31. static s32
  32. wl_dev_ioctl(struct net_device *dev, u32 cmd, void *arg, u32 len)
  33. {
  34. - struct ifreq ifr;
  35. - struct wl_ioctl ioc;
  36. - mm_segment_t fs;
  37. - s32 err = 0;
  38. -
  39. BUG_ON(len < sizeof(int));
  40. -
  41. - memset(&ioc, 0, sizeof(ioc));
  42. - ioc.cmd = cmd;
  43. - ioc.buf = arg;
  44. - ioc.len = len;
  45. - strcpy(ifr.ifr_name, dev->name);
  46. - ifr.ifr_data = (caddr_t)&ioc;
  47. -
  48. - fs = get_fs();
  49. -#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 1, 0)
  50. - set_fs(KERNEL_DS);
  51. -#else
  52. - set_fs(get_ds());
  53. -#endif
  54. -#if defined(WL_USE_NETDEV_OPS)
  55. - err = dev->netdev_ops->ndo_do_ioctl(dev, &ifr, SIOCDEVPRIVATE);
  56. -#else
  57. - err = dev->do_ioctl(dev, &ifr, SIOCDEVPRIVATE);
  58. -#endif
  59. - set_fs(fs);
  60. -
  61. - return err;
  62. + return wlc_ioctl_internal(dev, cmd, arg, len);
  63. }
  64. static s32
  65. diff --git a/src/wl/sys/wl_iw.c b/src/wl/sys/wl_iw.c
  66. index c4c610b..e346b15 100644
  67. --- a/src/wl/sys/wl_iw.c
  68. +++ b/src/wl/sys/wl_iw.c
  69. @@ -37,6 +37,7 @@ typedef const struct si_pub si_t;
  70. #include <wl_dbg.h>
  71. #include <wl_iw.h>
  72. +#include <wl_linux.h>
  73. extern bool wl_iw_conn_status_str(uint32 event_type, uint32 status,
  74. uint32 reason, char* stringBuf, uint buflen);
  75. @@ -103,33 +104,7 @@ dev_wlc_ioctl(
  76. int len
  77. )
  78. {
  79. - struct ifreq ifr;
  80. - wl_ioctl_t ioc;
  81. - mm_segment_t fs;
  82. - int ret;
  83. -
  84. - memset(&ioc, 0, sizeof(ioc));
  85. - ioc.cmd = cmd;
  86. - ioc.buf = arg;
  87. - ioc.len = len;
  88. -
  89. - strcpy(ifr.ifr_name, dev->name);
  90. - ifr.ifr_data = (caddr_t) &ioc;
  91. -
  92. - fs = get_fs();
  93. -#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 1, 0)
  94. - set_fs(KERNEL_DS);
  95. -#else
  96. - set_fs(get_ds());
  97. -#endif
  98. -#if defined(WL_USE_NETDEV_OPS)
  99. - ret = dev->netdev_ops->ndo_do_ioctl(dev, &ifr, SIOCDEVPRIVATE);
  100. -#else
  101. - ret = dev->do_ioctl(dev, &ifr, SIOCDEVPRIVATE);
  102. -#endif
  103. - set_fs(fs);
  104. -
  105. - return ret;
  106. + return wlc_ioctl_internal(dev, cmd, arg, len);
  107. }
  108. static int
  109. diff --git a/src/wl/sys/wl_linux.c b/src/wl/sys/wl_linux.c
  110. index 66069d4..cc01d2b 100644
  111. --- a/src/wl/sys/wl_linux.c
  112. +++ b/src/wl/sys/wl_linux.c
  113. @@ -1661,10 +1661,7 @@ wl_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
  114. goto done2;
  115. }
  116. - if (segment_eq(get_fs(), KERNEL_DS))
  117. - buf = ioc.buf;
  118. -
  119. - else if (ioc.buf) {
  120. + if (ioc.buf) {
  121. if (!(buf = (void *) MALLOC(wl->osh, MAX(ioc.len, WLC_IOCTL_MAXLEN)))) {
  122. bcmerror = BCME_NORESOURCE;
  123. goto done2;
  124. @@ -1681,7 +1678,7 @@ wl_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
  125. WL_UNLOCK(wl);
  126. done1:
  127. - if (ioc.buf && (ioc.buf != buf)) {
  128. + if (ioc.buf) {
  129. if (copy_to_user(ioc.buf, buf, ioc.len))
  130. bcmerror = BCME_BADADDR;
  131. MFREE(wl->osh, buf, MAX(ioc.len, WLC_IOCTL_MAXLEN));
  132. @@ -1694,6 +1691,39 @@ done2:
  133. return (OSL_ERROR(bcmerror));
  134. }
  135. +int
  136. +wlc_ioctl_internal(struct net_device *dev, int cmd, void *buf, int len)
  137. +{
  138. + wl_info_t *wl;
  139. + wl_if_t *wlif;
  140. + int bcmerror;
  141. +
  142. + if (!dev)
  143. + return -ENETDOWN;
  144. +
  145. + wl = WL_INFO(dev);
  146. + wlif = WL_DEV_IF(dev);
  147. + if (wlif == NULL || wl == NULL || wl->dev == NULL)
  148. + return -ENETDOWN;
  149. +
  150. + bcmerror = 0;
  151. +
  152. + WL_TRACE(("wl%d: wlc_ioctl_internal: cmd 0x%x\n", wl->pub->unit, cmd));
  153. +
  154. + WL_LOCK(wl);
  155. + if (!capable(CAP_NET_ADMIN)) {
  156. + bcmerror = BCME_EPERM;
  157. + } else {
  158. + bcmerror = wlc_ioctl(wl->wlc, cmd, buf, len, wlif->wlcif);
  159. + }
  160. + WL_UNLOCK(wl);
  161. +
  162. + ASSERT(VALID_BCMERROR(bcmerror));
  163. + if (bcmerror != 0)
  164. + wl->pub->bcmerror = bcmerror;
  165. + return (OSL_ERROR(bcmerror));
  166. +}
  167. +
  168. static struct net_device_stats*
  169. wl_get_stats(struct net_device *dev)
  170. {
  171. diff --git a/src/wl/sys/wl_linux.h b/src/wl/sys/wl_linux.h
  172. index 5b1048e..c8c1f41 100644
  173. --- a/src/wl/sys/wl_linux.h
  174. +++ b/src/wl/sys/wl_linux.h
  175. @@ -22,6 +22,7 @@
  176. #define _wl_linux_h_
  177. #include <wlc_types.h>
  178. +#include <wlc_pub.h>
  179. typedef struct wl_timer {
  180. struct timer_list timer;
  181. @@ -187,6 +188,7 @@ extern irqreturn_t wl_isr(int irq, void *dev_id, struct pt_regs *ptregs);
  182. extern int __devinit wl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent);
  183. extern void wl_free(wl_info_t *wl);
  184. extern int wl_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd);
  185. +extern int wlc_ioctl_internal(struct net_device *dev, int cmd, void *buf, int len);
  186. extern struct net_device * wl_netdev_get(wl_info_t *wl);
  187. #endif
  188. diff --git a/src/wl/sys/wlc_pub.h b/src/wl/sys/wlc_pub.h
  189. index 53a98b8..2b5a029 100644
  190. --- a/src/wl/sys/wlc_pub.h
  191. +++ b/src/wl/sys/wlc_pub.h
  192. @@ -24,6 +24,7 @@
  193. #include <wlc_types.h>
  194. #include <wlc_utils.h>
  195. +#include <siutils.h>
  196. #include "proto/802.11.h"
  197. #include "proto/bcmevent.h"