File broadcom-wl.linux-5.9.patch of Package broadcom-wl
203
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
6
Fixes linux-next where get_fs/set_fs is already removed for some architectures.
7
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.
10
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
14
15
Signed-off-by: Joan Bruguera <joanbrugueram@gmail.com>
16
---
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(-)
23
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
27
28
#include <wlioctl.h>
29
#include <proto/802.11.h>
30
#include <wl_cfg80211_hybrid.h>
31
+#include <wl_linux.h>
32
33
#define EVENT_TYPE(e) dtoh32((e)->event_type)
34
#define EVENT_FLAGS(e) dtoh16((e)->flags)
35
36
static s32
37
wl_dev_ioctl(struct net_device *dev, u32 cmd, void *arg, u32 len)
38
{
39
- struct ifreq ifr;
40
- struct wl_ioctl ioc;
41
- mm_segment_t fs;
42
- s32 err = 0;
43
-
44
BUG_ON(len < sizeof(int));
45
-
46
- memset(&ioc, 0, sizeof(ioc));
47
- ioc.cmd = cmd;
48
- ioc.buf = arg;
49
- ioc.len = len;
50
- strcpy(ifr.ifr_name, dev->name);
51
- ifr.ifr_data = (caddr_t)&ioc;
52
-
53
- fs = get_fs();
54
- set_fs(get_ds());
55
-#if defined(WL_USE_NETDEV_OPS)
56
- err = dev->netdev_ops->ndo_do_ioctl(dev, &ifr, SIOCDEVPRIVATE);
57
-#else
58
- err = dev->do_ioctl(dev, &ifr, SIOCDEVPRIVATE);
59
-#endif
60
- set_fs(fs);
61
-
62
- return err;
63
+ return wlc_ioctl_internal(dev, cmd, arg, len);
64
}
65
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
71
72
#include <wl_dbg.h>
73
#include <wl_iw.h>
74
+#include <wl_linux.h>
75
76
extern bool wl_iw_conn_status_str(uint32 event_type, uint32 status,
77
uint32 reason, char* stringBuf, uint buflen);
78
79
int len
80
)
81
{
82
- struct ifreq ifr;
83
- wl_ioctl_t ioc;
84
- mm_segment_t fs;
85
- int ret;
86
-
87
- memset(&ioc, 0, sizeof(ioc));
88
- ioc.cmd = cmd;
89
- ioc.buf = arg;
90
- ioc.len = len;
91
-
92
- strcpy(ifr.ifr_name, dev->name);
93
- ifr.ifr_data = (caddr_t) &ioc;
94
-
95
- fs = get_fs();
96
- set_fs(get_ds());
97
-#if defined(WL_USE_NETDEV_OPS)
98
- ret = dev->netdev_ops->ndo_do_ioctl(dev, &ifr, SIOCDEVPRIVATE);
99
-#else
100
- ret = dev->do_ioctl(dev, &ifr, SIOCDEVPRIVATE);
101
-#endif
102
- set_fs(fs);
103
-
104
- return ret;
105
+ return wlc_ioctl_internal(dev, cmd, arg, len);
106
}
107
108
static int
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
113
goto done2;
114
}
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
125
WL_UNLOCK(wl);
126
127
done1:
128
- if (ioc.buf && (ioc.buf != buf)) {
129
+ if (ioc.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
134
ASSERT(VALID_BCMERROR(bcmerror));
135
if (bcmerror != 0)
136
wl->pub->bcmerror = bcmerror;
137
+ return (OSL_ERROR(bcmerror));
138
+}
139
+
140
+int
141
+wlc_ioctl_internal(struct net_device *dev, int cmd, void *buf, int len)
142
+{
143
+ wl_info_t *wl;
144
+ wl_if_t *wlif;
145
+ int bcmerror;
146
+
147
+ if (!dev)
148
+ return -ENETDOWN;
149
+
150
+ wl = WL_INFO(dev);
151
+ wlif = WL_DEV_IF(dev);
152
+ if (wlif == NULL || wl == NULL || wl->dev == NULL)
153
+ return -ENETDOWN;
154
+
155
+ bcmerror = 0;
156
+
157
+ WL_TRACE(("wl%d: wlc_ioctl_internal: cmd 0x%x\n", wl->pub->unit, cmd));
158
+
159
+ WL_LOCK(wl);
160
+ if (!capable(CAP_NET_ADMIN)) {
161
+ bcmerror = BCME_EPERM;
162
+ } else {
163
+ bcmerror = wlc_ioctl(wl->wlc, cmd, buf, len, wlif->wlcif);
164
+ }
165
+ WL_UNLOCK(wl);
166
+
167
+ ASSERT(VALID_BCMERROR(bcmerror));
168
+ if (bcmerror != 0)
169
+ wl->pub->bcmerror = bcmerror;
170
return (OSL_ERROR(bcmerror));
171
}
172
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
176
177
#define _wl_linux_h_
178
179
#include <wlc_types.h>
180
+#include <wlc_pub.h>
181
182
typedef struct wl_timer {
183
struct timer_list timer;
184
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);
190
191
#endif
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
195
196
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"
202
203