wok-current diff broadcom-wl-pae/stuff/017-get-rid-of-get_fs-set_fs-calls.patch @ rev 25643

Update broadcom-wl driver for kernel 4.x
author Stanislas Leduc <shann@slitaz.org>
date Fri Jan 19 12:44:23 2024 +0000 (5 months ago)
parents
children
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/broadcom-wl-pae/stuff/017-get-rid-of-get_fs-set_fs-calls.patch	Fri Jan 19 12:44:23 2024 +0000
     1.3 @@ -0,0 +1,207 @@
     1.4 +From: Joan Bruguera <joanbrugueram@gmail.com>
     1.5 +Date: Sun, 13 Sep 2020 07:33:32 +0200
     1.6 +Subject: Get rid of get_fs/set_fs calls in Broadcom WL driver.
     1.7 +Origin: https://gist.github.com/joanbm/5c640ac074d27fd1d82c74a5b67a1290
     1.8 +
     1.9 +Fixes linux-next where get_fs/set_fs is already removed for some architectures.
    1.10 +
    1.11 +NB: Some checks in wlc_ioctl_internal are likely superfluous,
    1.12 +    but I'm not familiar enough with the driver to remove them with confidence.
    1.13 +
    1.14 +See also: https://lwn.net/Articles/722267/
    1.15 +          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
    1.16 +          https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/commit/include/linux/uaccess.h?h=next-20200911&id=5e6e9852d6f76e01b2e6803c74258afa5b432bc5
    1.17 +
    1.18 +Signed-off-by: Joan Bruguera <joanbrugueram@gmail.com>
    1.19 +---
    1.20 + amd64/src/wl/sys/wl_cfg80211_hybrid.c | 29 ++-----------------------
    1.21 + amd64/src/wl/sys/wl_iw.c              | 25 ++--------------------
    1.22 + amd64/src/wl/sys/wl_linux.c           | 40 ++++++++++++++++++++++++++++++-----
    1.23 + amd64/src/wl/sys/wl_linux.h           |  2 ++
    1.24 + amd64/src/wl/sys/wlc_pub.h            |  1 +
    1.25 + 5 files changed, 42 insertions(+), 55 deletions(-)
    1.26 +
    1.27 +diff --git a/amd64/src/wl/sys/wl_cfg80211_hybrid.c b/amd64/src/wl/sys/wl_cfg80211_hybrid.c
    1.28 +index 8e01841..111ec5a 100644
    1.29 +--- a/amd64/src/wl/sys/wl_cfg80211_hybrid.c
    1.30 ++++ b/amd64/src/wl/sys/wl_cfg80211_hybrid.c
    1.31 +@@ -41,6 +41,7 @@
    1.32 + #include <wlioctl.h>
    1.33 + #include <proto/802.11.h>
    1.34 + #include <wl_cfg80211_hybrid.h>
    1.35 ++#include <wl_linux.h>
    1.36 + 
    1.37 + #define EVENT_TYPE(e) dtoh32((e)->event_type)
    1.38 + #define EVENT_FLAGS(e) dtoh16((e)->flags)
    1.39 +@@ -442,30 +443,8 @@
    1.40 + static s32
    1.41 + wl_dev_ioctl(struct net_device *dev, u32 cmd, void *arg, u32 len)
    1.42 + {
    1.43 +-	struct ifreq ifr;
    1.44 +-	struct wl_ioctl ioc;
    1.45 +-	mm_segment_t fs;
    1.46 +-	s32 err = 0;
    1.47 +-
    1.48 + 	BUG_ON(len < sizeof(int));
    1.49 +-
    1.50 +-	memset(&ioc, 0, sizeof(ioc));
    1.51 +-	ioc.cmd = cmd;
    1.52 +-	ioc.buf = arg;
    1.53 +-	ioc.len = len;
    1.54 +-	strcpy(ifr.ifr_name, dev->name);
    1.55 +-	ifr.ifr_data = (caddr_t)&ioc;
    1.56 +-
    1.57 +-	fs = get_fs();
    1.58 +-	set_fs(get_ds());
    1.59 +-#if defined(WL_USE_NETDEV_OPS)
    1.60 +-	err = dev->netdev_ops->ndo_do_ioctl(dev, &ifr, SIOCDEVPRIVATE);
    1.61 +-#else
    1.62 +-	err = dev->do_ioctl(dev, &ifr, SIOCDEVPRIVATE);
    1.63 +-#endif
    1.64 +-	set_fs(fs);
    1.65 +-
    1.66 +-	return err;
    1.67 ++	return wlc_ioctl_internal(dev, cmd, arg, len);
    1.68 + }
    1.69 + 
    1.70 + static s32
    1.71 +diff --git a/amd64/src/wl/sys/wl_iw.c b/amd64/src/wl/sys/wl_iw.c
    1.72 +index c4c610b..e346b15 100644
    1.73 +--- a/amd64/src/wl/sys/wl_iw.c
    1.74 ++++ b/amd64/src/wl/sys/wl_iw.c
    1.75 +@@ -37,6 +37,7 @@ typedef const struct si_pub	si_t;
    1.76 + 
    1.77 + #include <wl_dbg.h>
    1.78 + #include <wl_iw.h>
    1.79 ++#include <wl_linux.h>
    1.80 + 
    1.81 + extern bool wl_iw_conn_status_str(uint32 event_type, uint32 status,
    1.82 + 	uint32 reason, char* stringBuf, uint buflen);
    1.83 +@@ -103,29 +104,7 @@ dev_wlc_ioctl(
    1.84 + 	int len
    1.85 + )
    1.86 + {
    1.87 +-	struct ifreq ifr;
    1.88 +-	wl_ioctl_t ioc;
    1.89 +-	mm_segment_t fs;
    1.90 +-	int ret;
    1.91 +-
    1.92 +-	memset(&ioc, 0, sizeof(ioc));
    1.93 +-	ioc.cmd = cmd;
    1.94 +-	ioc.buf = arg;
    1.95 +-	ioc.len = len;
    1.96 +-
    1.97 +-	strcpy(ifr.ifr_name, dev->name);
    1.98 +-	ifr.ifr_data = (caddr_t) &ioc;
    1.99 +-
   1.100 +-	fs = get_fs();
   1.101 +-	set_fs(get_ds());
   1.102 +-#if defined(WL_USE_NETDEV_OPS)
   1.103 +-	ret = dev->netdev_ops->ndo_do_ioctl(dev, &ifr, SIOCDEVPRIVATE);
   1.104 +-#else
   1.105 +-	ret = dev->do_ioctl(dev, &ifr, SIOCDEVPRIVATE);
   1.106 +-#endif
   1.107 +-	set_fs(fs);
   1.108 +-
   1.109 +-	return ret;
   1.110 ++	return wlc_ioctl_internal(dev, cmd, arg, len);
   1.111 + }
   1.112 + 
   1.113 + static int
   1.114 +diff --git a/amd64/src/wl/sys/wl_linux.c b/amd64/src/wl/sys/wl_linux.c
   1.115 +index 66069d4..cc01d2b 100644
   1.116 +--- a/amd64/src/wl/sys/wl_linux.c
   1.117 ++++ b/amd64/src/wl/sys/wl_linux.c
   1.118 +@@ -1661,10 +1661,7 @@ wl_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
   1.119 + 		goto done2;
   1.120 + 	}
   1.121 + 
   1.122 +-	if (segment_eq(get_fs(), KERNEL_DS))
   1.123 +-		buf = ioc.buf;
   1.124 +-
   1.125 +-	else if (ioc.buf) {
   1.126 ++	if (ioc.buf) {
   1.127 + 		if (!(buf = (void *) MALLOC(wl->osh, MAX(ioc.len, WLC_IOCTL_MAXLEN)))) {
   1.128 + 			bcmerror = BCME_NORESOURCE;
   1.129 + 			goto done2;
   1.130 +@@ -1681,7 +1678,7 @@ wl_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
   1.131 + 	WL_UNLOCK(wl);
   1.132 + 
   1.133 + done1:
   1.134 +-	if (ioc.buf && (ioc.buf != buf)) {
   1.135 ++	if (ioc.buf) {
   1.136 + 		if (copy_to_user(ioc.buf, buf, ioc.len))
   1.137 + 			bcmerror = BCME_BADADDR;
   1.138 + 		MFREE(wl->osh, buf, MAX(ioc.len, WLC_IOCTL_MAXLEN));
   1.139 +@@ -1694,6 +1691,39 @@ done2:
   1.140 + 	return (OSL_ERROR(bcmerror));
   1.141 + }
   1.142 + 
   1.143 ++int
   1.144 ++wlc_ioctl_internal(struct net_device *dev, int cmd, void *buf, int len)
   1.145 ++{
   1.146 ++	wl_info_t *wl;
   1.147 ++	wl_if_t *wlif;
   1.148 ++	int bcmerror;
   1.149 ++
   1.150 ++	if (!dev)
   1.151 ++		return -ENETDOWN;
   1.152 ++
   1.153 ++	wl = WL_INFO(dev);
   1.154 ++	wlif = WL_DEV_IF(dev);
   1.155 ++	if (wlif == NULL || wl == NULL || wl->dev == NULL)
   1.156 ++		return -ENETDOWN;
   1.157 ++
   1.158 ++	bcmerror = 0;
   1.159 ++
   1.160 ++	WL_TRACE(("wl%d: wlc_ioctl_internal: cmd 0x%x\n", wl->pub->unit, cmd));
   1.161 ++
   1.162 ++	WL_LOCK(wl);
   1.163 ++	if (!capable(CAP_NET_ADMIN)) {
   1.164 ++		bcmerror = BCME_EPERM;
   1.165 ++	} else {
   1.166 ++		bcmerror = wlc_ioctl(wl->wlc, cmd, buf, len, wlif->wlcif);
   1.167 ++	}
   1.168 ++	WL_UNLOCK(wl);
   1.169 ++
   1.170 ++	ASSERT(VALID_BCMERROR(bcmerror));
   1.171 ++	if (bcmerror != 0)
   1.172 ++		wl->pub->bcmerror = bcmerror;
   1.173 ++	return (OSL_ERROR(bcmerror));
   1.174 ++}
   1.175 ++
   1.176 + static struct net_device_stats*
   1.177 + wl_get_stats(struct net_device *dev)
   1.178 + {
   1.179 +diff --git a/amd64/src/wl/sys/wl_linux.h b/amd64/src/wl/sys/wl_linux.h
   1.180 +index 5b1048e..c8c1f41 100644
   1.181 +--- a/amd64/src/wl/sys/wl_linux.h
   1.182 ++++ b/amd64/src/wl/sys/wl_linux.h
   1.183 +@@ -22,6 +22,7 @@
   1.184 + #define _wl_linux_h_
   1.185 + 
   1.186 + #include <wlc_types.h>
   1.187 ++#include <wlc_pub.h>
   1.188 + 
   1.189 + typedef struct wl_timer {
   1.190 + 	struct timer_list 	timer;
   1.191 +@@ -187,6 +188,7 @@ extern irqreturn_t wl_isr(int irq, void *dev_id, struct pt_regs *ptregs);
   1.192 + extern int __devinit wl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent);
   1.193 + extern void wl_free(wl_info_t *wl);
   1.194 + extern int  wl_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd);
   1.195 ++extern int wlc_ioctl_internal(struct net_device *dev, int cmd, void *buf, int len);
   1.196 + extern struct net_device * wl_netdev_get(wl_info_t *wl);
   1.197 + 
   1.198 + #endif 
   1.199 +diff --git a/amd64/src/wl/sys/wlc_pub.h b/amd64/src/wl/sys/wlc_pub.h
   1.200 +index 53a98b8..2b5a029 100644
   1.201 +--- a/amd64/src/wl/sys/wlc_pub.h
   1.202 ++++ b/amd64/src/wl/sys/wlc_pub.h
   1.203 +@@ -24,6 +24,7 @@
   1.204 + 
   1.205 + #include <wlc_types.h>
   1.206 + #include <wlc_utils.h>
   1.207 ++#include <siutils.h>
   1.208 + #include "proto/802.11.h"
   1.209 + #include "proto/bcmevent.h"
   1.210 +