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
6 Fixes linux-next where get_fs/set_fs is already removed for some architectures.
8 NB: Some checks in wlc_ioctl_internal are likely superfluous,
9 but I'm not familiar enough with the driver to remove them with confidence.
11 See also: https://lwn.net/Articles/722267/
12 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
13 https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/commit/include/linux/uaccess.h?h=next-20200911&id=5e6e9852d6f76e01b2e6803c74258afa5b432bc5
15 Signed-off-by: Joan Bruguera <joanbrugueram@gmail.com>
17 src/wl/sys/wl_cfg80211_hybrid.c | 29 ++-----------------------
18 src/wl/sys/wl_iw.c | 25 ++--------------------
19 src/wl/sys/wl_linux.c | 40 ++++++++++++++++++++++++++++++-----
20 src/wl/sys/wl_linux.h | 2 ++
21 src/wl/sys/wlc_pub.h | 1 +
22 5 files changed, 42 insertions(+), 55 deletions(-)
24 diff -rup a/src/wl/sys/wl_cfg80211_hybrid.c b/src/wl/sys/wl_cfg80211_hybrid.c
25 --- a/src/wl/sys/wl_cfg80211_hybrid.c 2020-11-13 08:38:56.883599679 +0100
26 +++ b/src/wl/sys/wl_cfg80211_hybrid.c 2020-11-13 08:42:07.944320760 +0100
29 #include <proto/802.11.h>
30 #include <wl_cfg80211_hybrid.h>
31 +#include <wl_linux.h>
33 #define EVENT_TYPE(e) dtoh32((e)->event_type)
34 #define EVENT_FLAGS(e) dtoh16((e)->flags)
35 @@ -436,30 +437,8 @@ static void key_endian_to_host(struct wl
37 wl_dev_ioctl(struct net_device *dev, u32 cmd, void *arg, u32 len)
40 - struct wl_ioctl ioc;
44 BUG_ON(len < sizeof(int));
46 - memset(&ioc, 0, sizeof(ioc));
50 - strcpy(ifr.ifr_name, dev->name);
51 - ifr.ifr_data = (caddr_t)&ioc;
55 -#if defined(WL_USE_NETDEV_OPS)
56 - err = dev->netdev_ops->ndo_do_ioctl(dev, &ifr, SIOCDEVPRIVATE);
58 - err = dev->do_ioctl(dev, &ifr, SIOCDEVPRIVATE);
63 + return wlc_ioctl_internal(dev, cmd, arg, len);
66 #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0)
67 diff -rup a/src/wl/sys/wl_iw.c b/src/wl/sys/wl_iw.c
68 --- a/src/wl/sys/wl_iw.c 2020-11-13 08:38:56.891599715 +0100
69 +++ b/src/wl/sys/wl_iw.c 2020-11-13 08:40:14.803914270 +0100
70 @@ -37,6 +37,7 @@ typedef const struct si_pub si_t;
74 +#include <wl_linux.h>
76 extern bool wl_iw_conn_status_str(uint32 event_type, uint32 status,
77 uint32 reason, char* stringBuf, uint buflen);
78 @@ -106,29 +107,7 @@ dev_wlc_ioctl(
87 - memset(&ioc, 0, sizeof(ioc));
92 - strcpy(ifr.ifr_name, dev->name);
93 - ifr.ifr_data = (caddr_t) &ioc;
97 -#if defined(WL_USE_NETDEV_OPS)
98 - ret = dev->netdev_ops->ndo_do_ioctl(dev, &ifr, SIOCDEVPRIVATE);
100 - ret = dev->do_ioctl(dev, &ifr, SIOCDEVPRIVATE);
105 + return wlc_ioctl_internal(dev, cmd, arg, len);
109 diff -rup a/src/wl/sys/wl_linux.c b/src/wl/sys/wl_linux.c
110 --- a/src/wl/sys/wl_linux.c 2020-11-13 08:39:05.659639371 +0100
111 +++ b/src/wl/sys/wl_linux.c 2020-11-13 08:40:14.803914270 +0100
112 @@ -1649,10 +1649,7 @@ wl_ioctl(struct net_device *dev, struct
116 - if (segment_eq(get_fs(), KERNEL_DS))
119 - else if (ioc.buf) {
121 if (!(buf = (void *) MALLOC(wl->osh, MAX(ioc.len, WLC_IOCTL_MAXLEN)))) {
122 bcmerror = BCME_NORESOURCE;
124 @@ -1673,7 +1670,7 @@ wl_ioctl(struct net_device *dev, struct
128 - if (ioc.buf && (ioc.buf != buf)) {
130 if (copy_to_user(ioc.buf, buf, ioc.len))
131 bcmerror = BCME_BADADDR;
132 MFREE(wl->osh, buf, MAX(ioc.len, WLC_IOCTL_MAXLEN));
133 @@ -1683,6 +1680,39 @@ done2:
134 ASSERT(VALID_BCMERROR(bcmerror));
136 wl->pub->bcmerror = bcmerror;
137 + return (OSL_ERROR(bcmerror));
141 +wlc_ioctl_internal(struct net_device *dev, int cmd, void *buf, int len)
151 + wlif = WL_DEV_IF(dev);
152 + if (wlif == NULL || wl == NULL || wl->dev == NULL)
157 + WL_TRACE(("wl%d: wlc_ioctl_internal: cmd 0x%x\n", wl->pub->unit, cmd));
160 + if (!capable(CAP_NET_ADMIN)) {
161 + bcmerror = BCME_EPERM;
163 + bcmerror = wlc_ioctl(wl->wlc, cmd, buf, len, wlif->wlcif);
167 + ASSERT(VALID_BCMERROR(bcmerror));
169 + wl->pub->bcmerror = bcmerror;
170 return (OSL_ERROR(bcmerror));
173 diff -rup a/src/wl/sys/wl_linux.h b/src/wl/sys/wl_linux.h
174 --- a/src/wl/sys/wl_linux.h 2015-09-19 00:47:30.000000000 +0200
175 +++ b/src/wl/sys/wl_linux.h 2020-11-13 08:40:14.803914270 +0100
179 #include <wlc_types.h>
180 +#include <wlc_pub.h>
182 typedef struct wl_timer {
183 struct timer_list timer;
184 @@ -187,6 +188,7 @@ extern irqreturn_t wl_isr(int irq, void
185 extern int __devinit wl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent);
186 extern void wl_free(wl_info_t *wl);
187 extern int wl_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd);
188 +extern int wlc_ioctl_internal(struct net_device *dev, int cmd, void *buf, int len);
189 extern struct net_device * wl_netdev_get(wl_info_t *wl);
192 diff -rup a/src/wl/sys/wlc_pub.h b/src/wl/sys/wlc_pub.h
193 --- a/src/wl/sys/wlc_pub.h 2015-09-19 00:47:30.000000000 +0200
194 +++ b/src/wl/sys/wlc_pub.h 2020-11-13 08:40:14.803914270 +0100
197 #include <wlc_types.h>
198 #include <wlc_utils.h>
199 +#include <siutils.h>
200 #include "proto/802.11.h"
201 #include "proto/bcmevent.h"