Skip to contentSkip to conversation

staging: prepare for const netdev->dev_addr

PATCH In review Jakub Kicinski 4 participants 16 messages Oct 19, 2021 – Nov 3, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover staging: prepare for const netdev->dev_addr

Hi Greg,

This set prepares staging for netdev->dev_addr being const. We need to sprinkle const around some variables and arguments and use appropriate helpers to write to netdev->dev_addr.

I'll do another pass over staging before the merge window, this set is based on what's already there in net-next.

Jakub Kicinski (8):
staging: use eth_hw_addr_set()
staging: use eth_hw_addr_set() instead of ether_addr_copy()
staging: use eth_hw_addr_set() for dev->addr_len cases
staging: qlge: use eth_hw_addr_set()
staging: rtl8712: prepare for const netdev->dev_addr
staging: unisys: use eth_hw_addr_set()
staging: rtl: use eth_hw_addr_set()
staging: use eth_hw_addr_set() in orphan drivers

 drivers/staging/gdm724x/gdm_lte.c              |  4 +++-
 drivers/staging/ks7010/ks_hostif.c             |  2 +-
 drivers/staging/ks7010/ks_wlan_net.c           |  4 ++--
 drivers/staging/most/net/net.c                 |  2 +-
 drivers/staging/octeon/ethernet.c              |  2 +-
 drivers/staging/qlge/qlge_main.c               | 18 +++++++-----------
 drivers/staging/qlge/qlge_mpi.c                |  2 +-
 drivers/staging/r8188eu/os_dep/osdep_service.c |  2 +-
 drivers/staging/r8188eu/os_dep/usb_intf.c      |  2 +-
 drivers/staging/rtl8192e/rtl8192e/r8192E_dev.c |  7 +++++--
 drivers/staging/rtl8192e/rtl8192e/rtl_cam.c    |  4 ++--
 drivers/staging/rtl8192e/rtl8192e/rtl_core.c   |  2 +-
 drivers/staging/rtl8192u/r8192U.h              |  3 ++-
 drivers/staging/rtl8192u/r8192U_core.c         | 15 +++++++++------
 drivers/staging/rtl8712/os_intfs.c             |  9 +++++----
 drivers/staging/rtl8712/rtl871x_cmd.c          |  2 +-
 drivers/staging/rtl8712/rtl871x_cmd.h          |  2 +-
 drivers/staging/rtl8712/usb_intf.c             |  2 +-
 drivers/staging/rtl8723bs/os_dep/os_intfs.c    |  4 ++--
 .../staging/rtl8723bs/os_dep/osdep_service.c   |  2 +-
 .../staging/unisys/visornic/visornic_main.c    |  5 +++--
 drivers/staging/wlan-ng/p80211netdev.c         |  2 +-
 drivers/staging/wlan-ng/prism2sta.c            |  4 +++-
 23 files changed, 55 insertions(+), 46 deletions(-)
Signature · 1 line
2.31.1
#1 lore raw

PATCH 1/8 staging: use eth_hw_addr_set()

Commit 406f42fa0d3c ("net-next: When a bond have a massive amount of VLANs...") introduced a rbtree for faster Ethernet address look up. To maintain netdev->dev_addr in this tree we need to make all the writes to it got through appropriate helpers.

Convert staging drivers from memcpy(... ETH_ADDR) to eth_hw_addr_set():

@@
expression dev, np;
@@
- memcpy(dev->dev_addr, np, ETH_ALEN)
+ eth_hw_addr_set(dev, np)
@@
- memcpy(dev->dev_addr, np, 6)
+ eth_hw_addr_set(dev, np)

---
 drivers/staging/r8188eu/os_dep/osdep_service.c   | 2 +-
 drivers/staging/r8188eu/os_dep/usb_intf.c        | 2 +-
 drivers/staging/rtl8192u/r8192U_core.c           | 2 +-
 drivers/staging/rtl8712/os_intfs.c               | 4 ++--
 drivers/staging/rtl8723bs/os_dep/os_intfs.c      | 2 +-
 drivers/staging/rtl8723bs/os_dep/osdep_service.c | 2 +-
 6 files changed, 7 insertions(+), 7 deletions(-)
drivers/staging/r8188eu/os_dep/osdep_service.c +1 -1
index d7d03c1417fd..6bee194fc35d 100644
@@ -175,7 +175,7 @@ int rtw_change_ifname(struct adapter *padapter, const char *ifname)
 
 	rtw_init_netdev_name(pnetdev, ifname);
 
-	memcpy(pnetdev->dev_addr, padapter->eeprompriv.mac_addr, ETH_ALEN);
+	eth_hw_addr_set(pnetdev, padapter->eeprompriv.mac_addr);
 
 	if (!rtnl_is_locked())
 		ret = register_netdev(pnetdev);
drivers/staging/r8188eu/os_dep/usb_intf.c +1 -1
index 4b8a3e821b74..40f2481afc6f 100644
@@ -406,7 +406,7 @@ static struct adapter *rtw_usb_if1_init(struct dvobj_priv *dvobj,
 	rtw_macaddr_cfg(padapter->eeprompriv.mac_addr);
 	rtw_init_wifidirect_addrs(padapter, padapter->eeprompriv.mac_addr,
 				  padapter->eeprompriv.mac_addr);
-	memcpy(pnetdev->dev_addr, padapter->eeprompriv.mac_addr, ETH_ALEN);
+	eth_hw_addr_set(pnetdev, padapter->eeprompriv.mac_addr);
 	DBG_88E("MAC Address from pnetdev->dev_addr =  %pM\n",
 		pnetdev->dev_addr);
 
drivers/staging/rtl8192u/r8192U_core.c +1 -1
index 594239990455..2aaba44d84e2 100644
@@ -2307,7 +2307,7 @@ static int rtl8192_read_eeprom_info(struct net_device *dev)
 			*(u16 *)(&dev->dev_addr[i]) = (u16)ret;
 		}
 	} else {
-		memcpy(dev->dev_addr, bMac_Tmp_Addr, 6);
+		eth_hw_addr_set(dev, bMac_Tmp_Addr);
 		/* should I set IDR0 here? */
 	}
 	RT_TRACE(COMP_EPROM, "MAC addr:%pM\n", dev->dev_addr);
drivers/staging/rtl8712/os_intfs.c +2 -2
index 9502f6aa5306..2d3233a650fc 100644
@@ -381,8 +381,8 @@ static int netdev_open(struct net_device *pnetdev)
 			goto netdev_open_error;
 		if (!r8712_initmac) {
 			/* Use the mac address stored in the Efuse */
-			memcpy(pnetdev->dev_addr,
-			       padapter->eeprompriv.mac_addr, ETH_ALEN);
+			eth_hw_addr_set(pnetdev,
+					padapter->eeprompriv.mac_addr);
 		} else {
 			/* We have to inform f/w to use user-supplied MAC
 			 * address.
drivers/staging/rtl8723bs/os_dep/os_intfs.c +1 -1
index 1b8b76f14740..719e75ee3fb2 100644
@@ -789,7 +789,7 @@ static int _rtw_drv_register_netdev(struct adapter *padapter, char *name)
 	if (rtw_init_netdev_name(pnetdev, name))
 		return _FAIL;
 
-	memcpy(pnetdev->dev_addr, padapter->eeprompriv.mac_addr, ETH_ALEN);
+	eth_hw_addr_set(pnetdev, padapter->eeprompriv.mac_addr);
 
 	/* Tell the network stack we exist */
 	if (register_netdev(pnetdev) != 0) {
drivers/staging/rtl8723bs/os_dep/osdep_service.c +1 -1
index d6bddf7b08e8..4fbfa75c05d7 100644
@@ -142,7 +142,7 @@ int rtw_change_ifname(struct adapter *padapter, const char *ifname)
 
 	rtw_init_netdev_name(pnetdev, ifname);
 
-	memcpy(pnetdev->dev_addr, padapter->eeprompriv.mac_addr, ETH_ALEN);
+	eth_hw_addr_set(pnetdev, padapter->eeprompriv.mac_addr);
 
 	if (!rtnl_is_locked())
 		ret = register_netdev(pnetdev);
Signature · 1 line
2.31.1
#2 lore raw

PATCH 2/8 staging: use eth_hw_addr_set() instead of ether_addr_copy()

In reply to Jakub Kicinski

Commit 406f42fa0d3c ("net-next: When a bond have a massive amount of VLANs...") introduced a rbtree for faster Ethernet address look up. To maintain netdev->dev_addr in this tree we need to make all the writes to it got through appropriate helpers.

Convert staging from ether_addr_copy() to eth_hw_addr_set():

@@
expression dev, np;
@@
- ether_addr_copy(dev->dev_addr, np)
+ eth_hw_addr_set(dev, np)

---
 drivers/staging/ks7010/ks_hostif.c             | 2 +-
 drivers/staging/ks7010/ks_wlan_net.c           | 2 +-
 drivers/staging/most/net/net.c                 | 2 +-
 drivers/staging/rtl8192e/rtl8192e/r8192E_dev.c | 2 +-
 drivers/staging/rtl8192e/rtl8192e/rtl_core.c   | 2 +-
 drivers/staging/rtl8192u/r8192U_core.c         | 2 +-
 drivers/staging/rtl8712/os_intfs.c             | 2 +-
 drivers/staging/rtl8712/usb_intf.c             | 2 +-
 8 files changed, 8 insertions(+), 8 deletions(-)
drivers/staging/ks7010/ks_hostif.c +1 -1
index eaa70893224a..1c63d595313d 100644
@@ -541,7 +541,7 @@ void hostif_mib_get_confirm(struct ks_wlan_private *priv)
 		hostif_sme_enqueue(priv, SME_GET_MAC_ADDRESS);
 		ether_addr_copy(priv->eth_addr, priv->rxp);
 		priv->mac_address_valid = true;
-		ether_addr_copy(dev->dev_addr, priv->eth_addr);
+		eth_hw_addr_set(dev, priv->eth_addr);
 		netdev_info(dev, "MAC ADDRESS = %pM\n", priv->eth_addr);
 		break;
 	case DOT11_PRODUCT_VERSION:
drivers/staging/ks7010/ks_wlan_net.c +1 -1
index 631ad769c3d5..61d8f40e2739 100644
@@ -2625,7 +2625,7 @@ int ks_wlan_net_start(struct net_device *dev)
 
 	/* dummy address set */
 	ether_addr_copy(priv->eth_addr, dummy_addr);
-	ether_addr_copy(dev->dev_addr, priv->eth_addr);
+	eth_hw_addr_set(dev, priv->eth_addr);
 
 	/* The ks_wlan-specific entries in the device structure. */
 	dev->netdev_ops = &ks_wlan_netdev_ops;
drivers/staging/most/net/net.c +1 -1
index a5fd14246046..47039f0d262f 100644
@@ -564,7 +564,7 @@ static void on_netinfo(struct most_interface *iface,
 	if (m && is_valid_ether_addr(m)) {
 		if (!is_valid_ether_addr(dev->dev_addr)) {
 			netdev_info(dev, "set mac %pM\n", m);
-			ether_addr_copy(dev->dev_addr, m);
+			eth_hw_addr_set(dev, m);
 			netif_dormant_off(dev);
 		} else if (!ether_addr_equal(dev->dev_addr, m)) {
 			netdev_warn(dev, "reject mac %pM\n", m);
drivers/staging/rtl8192e/rtl8192e/r8192E_dev.c +1 -1
index 358b629d2cc6..cfeaa9c1542f 100644
@@ -366,7 +366,7 @@ static void _rtl92e_read_eeprom_info(struct net_device *dev)
 			*(u16 *)(&dev->dev_addr[i]) = usValue;
 		}
 	} else {
-		ether_addr_copy(dev->dev_addr, bMac_Tmp_Addr);
+		eth_hw_addr_set(dev, bMac_Tmp_Addr);
 	}
 
 	RT_TRACE(COMP_INIT, "Permanent Address = %pM\n",
drivers/staging/rtl8192e/rtl8192e/rtl_core.c +1 -1
index a7dd1578b2c6..d2e9df60e9ba 100644
@@ -2235,7 +2235,7 @@ static int _rtl92e_set_mac_adr(struct net_device *dev, void *mac)
 
 	mutex_lock(&priv->wx_mutex);
 
-	ether_addr_copy(dev->dev_addr, addr->sa_data);
+	eth_hw_addr_set(dev, addr->sa_data);
 
 	schedule_work(&priv->reset_wq);
 	mutex_unlock(&priv->wx_mutex);
drivers/staging/rtl8192u/r8192U_core.c +1 -1
index 2aaba44d84e2..3718d72e217e 100644
@@ -3454,7 +3454,7 @@ static int r8192_set_mac_adr(struct net_device *dev, void *mac)
 
 	mutex_lock(&priv->wx_mutex);
 
-	ether_addr_copy(dev->dev_addr, addr->sa_data);
+	eth_hw_addr_set(dev, addr->sa_data);
 
 	schedule_work(&priv->reset_wq);
 	mutex_unlock(&priv->wx_mutex);
drivers/staging/rtl8712/os_intfs.c +1 -1
index 2d3233a650fc..beb9137c198c 100644
@@ -166,7 +166,7 @@ static int r871x_net_set_mac_address(struct net_device *pnetdev, void *p)
 	struct sockaddr *addr = p;
 
 	if (!padapter->bup)
-		ether_addr_copy(pnetdev->dev_addr, addr->sa_data);
+		eth_hw_addr_set(pnetdev, addr->sa_data);
 	return 0;
 }
 
drivers/staging/rtl8712/usb_intf.c +1 -1
index 505ebeb643dc..17e705411e64 100644
@@ -563,7 +563,7 @@ static int r871xu_drv_init(struct usb_interface *pusb_intf,
 			dev_info(&udev->dev,
 				"r8712u: MAC Address from efuse = %pM\n", mac);
 		}
-		ether_addr_copy(pnetdev->dev_addr, mac);
+		eth_hw_addr_set(pnetdev, mac);
 	}
 	/* step 6. Load the firmware asynchronously */
 	if (rtl871x_load_fw(padapter))
Signature · 1 line
2.31.1
#3 lore raw

PATCH 3/8 staging: use eth_hw_addr_set() for dev->addr_len cases

In reply to Jakub Kicinski

Convert all staging drivers from memcpy(... dev->addr_len) to eth_hw_addr_set():

@@
expression dev, np;
@@
- memcpy(dev->dev_addr, np, dev->addr_len)
+ eth_hw_addr_set(dev, np)

Manually confirmed these are all etherdevices.

---
 drivers/staging/ks7010/ks_wlan_net.c   |  2 +-
 drivers/staging/qlge/qlge_main.c       | 10 +++-------
 drivers/staging/wlan-ng/p80211netdev.c |  2 +-
 3 files changed, 5 insertions(+), 9 deletions(-)
drivers/staging/ks7010/ks_wlan_net.c +1 -1
index 61d8f40e2739..7e8d37c169f0 100644
@@ -2490,7 +2490,7 @@ int ks_wlan_set_mac_address(struct net_device *dev, void *addr)
 
 	if (netif_running(dev))
 		return -EBUSY;
-	memcpy(dev->dev_addr, mac_addr->sa_data, dev->addr_len);
+	eth_hw_addr_set(dev, mac_addr->sa_data);
 	ether_addr_copy(priv->eth_addr, mac_addr->sa_data);
 
 	priv->mac_address_valid = false;
drivers/staging/qlge/qlge_main.c +3 -7
index 8fcdf89da8aa..abb7844f92fb 100644
@@ -724,9 +724,7 @@ static int qlge_get_8000_flash_params(struct qlge_adapter *qdev)
 		goto exit;
 	}
 
-	memcpy(qdev->ndev->dev_addr,
-	       mac_addr,
-	       qdev->ndev->addr_len);
+	eth_hw_addr_set(qdev->ndev, mac_addr);
 
 exit:
 	qlge_sem_unlock(qdev, SEM_FLASH_MASK);
@@ -774,9 +772,7 @@ static int qlge_get_8012_flash_params(struct qlge_adapter *qdev)
 		goto exit;
 	}
 
-	memcpy(qdev->ndev->dev_addr,
-	       qdev->flash.flash_params_8012.mac_addr,
-	       qdev->ndev->addr_len);
+	eth_hw_addr_set(qdev->ndev, qdev->flash.flash_params_8012.mac_addr);
 
 exit:
 	qlge_sem_unlock(qdev, SEM_FLASH_MASK);
@@ -4214,7 +4210,7 @@ static int qlge_set_mac_address(struct net_device *ndev, void *p)
 
 	if (!is_valid_ether_addr(addr->sa_data))
 		return -EADDRNOTAVAIL;
-	memcpy(ndev->dev_addr, addr->sa_data, ndev->addr_len);
+	eth_hw_addr_set(ndev, addr->sa_data);
 	/* Update local copy of current mac address. */
 	memcpy(qdev->current_mac_addr, ndev->dev_addr, ndev->addr_len);
 
drivers/staging/wlan-ng/p80211netdev.c +1 -1
index 07ed6c4cfdcc..255500448ad3 100644
@@ -616,7 +616,7 @@ static int p80211knetdev_set_mac_address(struct net_device *dev, void *addr)
 		result = -EADDRNOTAVAIL;
 	} else {
 		/* everything's ok, change the addr in netdev */
-		memcpy(dev->dev_addr, new_addr->sa_data, dev->addr_len);
+		eth_hw_addr_set(dev, new_addr->sa_data);
 	}
 
 	return result;
Signature · 1 line
2.31.1
#4 lore raw

PATCH 4/8 staging: qlge: use eth_hw_addr_set()

In reply to Jakub Kicinski

Commit 406f42fa0d3c ("net-next: When a bond have a massive amount of VLANs...") introduced a rbtree for faster Ethernet address look up. To maintain netdev->dev_addr in this tree we need to make all the writes to it got through appropriate helpers.

---
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]

---
 drivers/staging/qlge/qlge_main.c | 8 ++++----
 drivers/staging/qlge/qlge_mpi.c  | 2 +-
 2 files changed, 5 insertions(+), 5 deletions(-)
drivers/staging/qlge/qlge_main.c +4 -4
index abb7844f92fb..ee6b49ca2ddf 100644
@@ -321,8 +321,8 @@ int qlge_get_mac_addr_reg(struct qlge_adapter *qdev, u32 type, u16 index,
 /* Set up a MAC, multicast or VLAN address for the
  * inbound frame matching.
  */
-static int qlge_set_mac_addr_reg(struct qlge_adapter *qdev, u8 *addr, u32 type,
-				 u16 index)
+static int qlge_set_mac_addr_reg(struct qlge_adapter *qdev, const u8 *addr,
+				 u32 type, u16 index)
 {
 	u32 offset = 0;
 	int status = 0;
@@ -441,7 +441,7 @@ static int qlge_set_mac_addr(struct qlge_adapter *qdev, int set)
 	status = qlge_sem_spinlock(qdev, SEM_MAC_ADDR_MASK);
 	if (status)
 		return status;
-	status = qlge_set_mac_addr_reg(qdev, (u8 *)addr,
+	status = qlge_set_mac_addr_reg(qdev, (const u8 *)addr,
 				       MAC_ADDR_TYPE_CAM_MAC,
 				       qdev->func * MAX_CQ);
 	qlge_sem_unlock(qdev, SEM_MAC_ADDR_MASK);
@@ -4217,7 +4217,7 @@ static int qlge_set_mac_address(struct net_device *ndev, void *p)
 	status = qlge_sem_spinlock(qdev, SEM_MAC_ADDR_MASK);
 	if (status)
 		return status;
-	status = qlge_set_mac_addr_reg(qdev, (u8 *)ndev->dev_addr,
+	status = qlge_set_mac_addr_reg(qdev, (const u8 *)ndev->dev_addr,
 				       MAC_ADDR_TYPE_CAM_MAC,
 				       qdev->func * MAX_CQ);
 	if (status)
drivers/staging/qlge/qlge_mpi.c +1 -1
index 2630ebf50341..96a4de6d2b34 100644
@@ -862,7 +862,7 @@ int qlge_mb_wol_set_magic(struct qlge_adapter *qdev, u32 enable_wol)
 	struct mbox_params mbc;
 	struct mbox_params *mbcp = &mbc;
 	int status;
-	u8 *addr = qdev->ndev->dev_addr;
+	const u8 *addr = qdev->ndev->dev_addr;
 
 	memset(mbcp, 0, sizeof(struct mbox_params));
 
Signature · 1 line
2.31.1
#5 lore raw

PATCH 5/8 staging: rtl8712: prepare for const netdev->dev_addr

In reply to Jakub Kicinski

netdev->dev_addr will be const soon, make sure the qualifier is respected by drivers.

---
 drivers/staging/rtl8712/os_intfs.c    | 3 ++-
 drivers/staging/rtl8712/rtl871x_cmd.c | 2 +-
 drivers/staging/rtl8712/rtl871x_cmd.h | 2 +-
 3 files changed, 4 insertions(+), 3 deletions(-)
drivers/staging/rtl8712/os_intfs.c +2 -1
index beb9137c198c..d15d52c0d1a7 100644
@@ -388,7 +388,8 @@ static int netdev_open(struct net_device *pnetdev)
 			 * address.
 			 */
 			msleep(200);
-			r8712_setMacAddr_cmd(padapter, (u8 *)pnetdev->dev_addr);
+			r8712_setMacAddr_cmd(padapter,
+					     (const u8 *)pnetdev->dev_addr);
 			/*
 			 * The "myid" function will get the wifi mac address
 			 * from eeprompriv structure instead of netdev
drivers/staging/rtl8712/rtl871x_cmd.c +1 -1
index 75716f59044d..acda930722b2 100644
@@ -554,7 +554,7 @@ void r8712_setstakey_cmd(struct _adapter *padapter, u8 *psta, u8 unicast_key)
 	r8712_enqueue_cmd(pcmdpriv, ph2c);
 }
 
-void r8712_setMacAddr_cmd(struct _adapter *padapter, u8 *mac_addr)
+void r8712_setMacAddr_cmd(struct _adapter *padapter, const u8 *mac_addr)
 {
 	struct cmd_priv	*pcmdpriv = &padapter->cmdpriv;
 	struct cmd_obj *ph2c;
drivers/staging/rtl8712/rtl871x_cmd.h +1 -1
index bf6f0c6a86e5..ddd69c4ae208 100644
@@ -718,7 +718,7 @@ struct DisconnectCtrlEx_param {
 #define H2C_CMD_OVERFLOW		0x06
 #define H2C_RESERVED			0x07
 
-void r8712_setMacAddr_cmd(struct _adapter *padapter, u8 *mac_addr);
+void r8712_setMacAddr_cmd(struct _adapter *padapter, const u8 *mac_addr);
 u8 r8712_sitesurvey_cmd(struct _adapter *padapter,
 			struct ndis_802_11_ssid *pssid);
 int r8712_createbss_cmd(struct _adapter *padapter);
Signature · 1 line
2.31.1
#6 lore raw

PATCH 6/8 staging: unisys: use eth_hw_addr_set()

In reply to Jakub Kicinski

Commit 406f42fa0d3c ("net-next: When a bond have a massive amount of VLANs...") introduced a rbtree for faster Ethernet address look up. To maintain netdev->dev_addr in this tree we need to make all the writes to it got through appropriate helpers.

---
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]

---
 drivers/staging/unisys/visornic/visornic_main.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/staging/unisys/visornic/visornic_main.c +3 -2
index a3bc568c660d..62cd9b783732 100644
@@ -1782,6 +1782,7 @@ static int visornic_probe(struct visor_device *dev)
 	struct net_device *netdev = NULL;
 	int err;
 	int channel_offset = 0;
+	u8 addr[ETH_ALEN];
 	u64 features;
 
 	netdev = alloc_etherdev(sizeof(struct visornic_devdata));
@@ -1798,14 +1799,14 @@ static int visornic_probe(struct visor_device *dev)
 	/* Get MAC address from channel and read it into the device. */
 	netdev->addr_len = ETH_ALEN;
 	channel_offset = offsetof(struct visor_io_channel, vnic.macaddr);
-	err = visorbus_read_channel(dev, channel_offset, netdev->dev_addr,
-				    ETH_ALEN);
+	err = visorbus_read_channel(dev, channel_offset, addr, ETH_ALEN);
 	if (err < 0) {
 		dev_err(&dev->device,
 			"%s failed to get mac addr from chan (%d)\n",
 			__func__, err);
 		goto cleanup_netdev;
 	}
+	eth_hw_addr_set(netdev, addr);
 
 	devdata = devdata_initialize(netdev_priv(netdev), dev);
 	if (!devdata) {
Signature · 1 line
2.31.1
#7 lore raw

PATCH 7/8 staging: rtl: use eth_hw_addr_set()

In reply to Jakub Kicinski

Commit 406f42fa0d3c ("net-next: When a bond have a massive amount of VLANs...") introduced a rbtree for faster Ethernet address look up. To maintain netdev->dev_addr in this tree we need to make all the writes to it got through appropriate helpers.

---
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]
CC: [email protected]

---
 drivers/staging/rtl8192e/rtl8192e/r8192E_dev.c |  5 ++++-
 drivers/staging/rtl8192e/rtl8192e/rtl_cam.c    |  4 ++--
 drivers/staging/rtl8192u/r8192U.h              |  3 ++-
 drivers/staging/rtl8192u/r8192U_core.c         | 11 +++++++----
 drivers/staging/rtl8723bs/os_dep/os_intfs.c    |  2 +-
 5 files changed, 16 insertions(+), 9 deletions(-)
drivers/staging/rtl8192e/rtl8192e/r8192E_dev.c +4 -1
index cfeaa9c1542f..7f9dee42a04d 100644
@@ -360,11 +360,14 @@ static void _rtl92e_read_eeprom_info(struct net_device *dev)
 		 priv->eeprom_CustomerID);
 
 	if (!priv->AutoloadFailFlag) {
+		u8 addr[ETH_ALEN];
+
 		for (i = 0; i < 6; i += 2) {
 			usValue = rtl92e_eeprom_read(dev,
 				 (EEPROM_NODE_ADDRESS_BYTE_0 + i) >> 1);
-			*(u16 *)(&dev->dev_addr[i]) = usValue;
+			*(u16 *)(&addr[i]) = usValue;
 		}
+		eth_hw_addr_set(dev, addr);
 	} else {
 		eth_hw_addr_set(dev, bMac_Tmp_Addr);
 	}
drivers/staging/rtl8192e/rtl8192e/rtl_cam.c +2 -2
index f75a12543781..d7630f02a910 100644
@@ -184,7 +184,7 @@ void rtl92e_cam_restore(struct net_device *dev)
 		if (priv->rtllib->iw_mode == IW_MODE_ADHOC) {
 			rtl92e_set_key(dev, 4, 0,
 				       priv->rtllib->pairwise_key_type,
-				       (u8 *)dev->dev_addr, 0,
+				       (const u8 *)dev->dev_addr, 0,
 				       (u32 *)(&priv->rtllib->swcamtable[4].key_buf[0]));
 		} else {
 			rtl92e_set_key(dev, 4, 0,
@@ -197,7 +197,7 @@ void rtl92e_cam_restore(struct net_device *dev)
 		if (priv->rtllib->iw_mode == IW_MODE_ADHOC) {
 			rtl92e_set_key(dev, 4, 0,
 				       priv->rtllib->pairwise_key_type,
-				       (u8 *)dev->dev_addr, 0,
+				       (const u8 *)dev->dev_addr, 0,
 				       (u32 *)(&priv->rtllib->swcamtable[4].key_buf[0]));
 		} else {
 			rtl92e_set_key(dev, 4, 0,
drivers/staging/rtl8192u/r8192U.h +2 -1
index 4013107cd93a..14ca00a2789b 100644
@@ -1114,6 +1114,7 @@ void rtl8192_set_rxconf(struct net_device *dev);
 void rtl819xusb_beacon_tx(struct net_device *dev, u16 tx_rate);
 
 void EnableHWSecurityConfig8192(struct net_device *dev);
-void setKey(struct net_device *dev, u8 EntryNo, u8 KeyIndex, u16 KeyType, u8 *MacAddr, u8 DefaultKey, u32 *KeyContent);
+void setKey(struct net_device *dev, u8 EntryNo, u8 KeyIndex, u16 KeyType,
+	    const u8 *MacAddr, u8 DefaultKey, u32 *KeyContent);
 
 #endif
drivers/staging/rtl8192u/r8192U_core.c +7 -4
index 3718d72e217e..cfbd9d79baa7 100644
@@ -2300,12 +2300,15 @@ static int rtl8192_read_eeprom_info(struct net_device *dev)
 	/* set channelplan from eeprom */
 	priv->ChannelPlan = priv->eeprom_ChannelPlan;
 	if (bLoad_From_EEPOM) {
+		u8 addr[ETH_ALEN];
+
 		for (i = 0; i < 6; i += 2) {
 			ret = eprom_read(dev, (u16)((EEPROM_NODE_ADDRESS_BYTE_0 + i) >> 1));
 			if (ret < 0)
 				return ret;
-			*(u16 *)(&dev->dev_addr[i]) = (u16)ret;
+			*(u16 *)(&addr[i]) = (u16)ret;
 		}
+		eth_hw_addr_set(dev, addr);
 	} else {
 		eth_hw_addr_set(dev, bMac_Tmp_Addr);
 		/* should I set IDR0 here? */
@@ -3045,14 +3048,14 @@ static void CamRestoreAllEntry(struct net_device *dev)
 	} else if (priv->ieee80211->pairwise_key_type == KEY_TYPE_TKIP) {
 		if (priv->ieee80211->iw_mode == IW_MODE_ADHOC)
 			setKey(dev, 4, 0, priv->ieee80211->pairwise_key_type,
-			       (u8 *)dev->dev_addr, 0, NULL);
+			       (const u8 *)dev->dev_addr, 0, NULL);
 		else
 			setKey(dev, 4, 0, priv->ieee80211->pairwise_key_type,
 			       MacAddr, 0, NULL);
 	} else if (priv->ieee80211->pairwise_key_type == KEY_TYPE_CCMP) {
 		if (priv->ieee80211->iw_mode == IW_MODE_ADHOC)
 			setKey(dev, 4, 0, priv->ieee80211->pairwise_key_type,
-			       (u8 *)dev->dev_addr, 0, NULL);
+			       (const u8 *)dev->dev_addr, 0, NULL);
 		else
 			setKey(dev, 4, 0, priv->ieee80211->pairwise_key_type,
 			       MacAddr, 0, NULL);
@@ -4868,7 +4871,7 @@ void EnableHWSecurityConfig8192(struct net_device *dev)
 }
 
 void setKey(struct net_device *dev, u8 entryno, u8 keyindex, u16 keytype,
-	    u8 *macaddr, u8 defaultkey, u32 *keycontent)
+	    const u8 *macaddr, u8 defaultkey, u32 *keycontent)
 {
 	u32 target_command = 0;
 	u32 target_content = 0;
drivers/staging/rtl8723bs/os_dep/os_intfs.c +1 -1
index 719e75ee3fb2..05482341eefe 100644
@@ -283,7 +283,7 @@ static int rtw_net_set_mac_address(struct net_device *pnetdev, void *p)
 	if (!padapter->bup) {
 		/* addr->sa_data[4], addr->sa_data[5]); */
 		memcpy(padapter->eeprompriv.mac_addr, addr->sa_data, ETH_ALEN);
-		/* memcpy(pnetdev->dev_addr, addr->sa_data, ETH_ALEN); */
+		/* eth_hw_addr_set(pnetdev, addr->sa_data); */
 		/* padapter->bset_hwaddr = true; */
 	}
 
Signature · 1 line
2.31.1
#8 lore raw

Re: [PATCH 7/8] staging: rtl: use eth_hw_addr_set()

Quoted 5 lines · Jakub Kicinski
drivers/staging/rtl8192e/rtl8192e/r8192E_dev.c +0 -0
index cfeaa9c1542f..7f9dee42a04d 100644

drivers/staging/rtl8192e/rtl8192e/r8192E_dev.c static void _rtl92e_read_eeprom_info(struct net_device *dev) · line 368

Quoted 10 lines
drivers/staging/rtl8192e/rtl8192e/r8192E_dev.c +3 -1
@@ -360,11 +360,14 @@ static void _rtl92e_read_eeprom_info(struct net_device *dev)
 		 priv->eeprom_CustomerID);
 
 	if (!priv->AutoloadFailFlag) {
+		u8 addr[ETH_ALEN];
+
 		for (i = 0; i < 6; i += 2) {
 			usValue = rtl92e_eeprom_read(dev,
 				 (EEPROM_NODE_ADDRESS_BYTE_0 + i) >> 1);
-			*(u16 *)(&dev->dev_addr[i]) = usValue;
+			*(u16 *)(&addr[i]) = usValue;

No this doesn't work. It writes 2 bytes instead of one so it will write one element beyond the end of addr[]. It doesn't work at all on little endian systems.

I'm not sure what's going on here or how to fix it but array overflows are always bad.

Quoted 46 lines
drivers/staging/rtl8192e/rtl8192e/r8192E_dev.c +1 -0
 		}
+		eth_hw_addr_set(dev, addr);
 	} else {
 		eth_hw_addr_set(dev, bMac_Tmp_Addr);
 	}
drivers/staging/rtl8192e/rtl8192e/rtl_cam.c +2 -2
index f75a12543781..d7630f02a910 100644
@@ -184,7 +184,7 @@ void rtl92e_cam_restore(struct net_device *dev)
 		if (priv->rtllib->iw_mode == IW_MODE_ADHOC) {
 			rtl92e_set_key(dev, 4, 0,
 				       priv->rtllib->pairwise_key_type,
-				       (u8 *)dev->dev_addr, 0,
+				       (const u8 *)dev->dev_addr, 0,
 				       (u32 *)(&priv->rtllib->swcamtable[4].key_buf[0]));
 		} else {
 			rtl92e_set_key(dev, 4, 0,
@@ -197,7 +197,7 @@ void rtl92e_cam_restore(struct net_device *dev)
 		if (priv->rtllib->iw_mode == IW_MODE_ADHOC) {
 			rtl92e_set_key(dev, 4, 0,
 				       priv->rtllib->pairwise_key_type,
-				       (u8 *)dev->dev_addr, 0,
+				       (const u8 *)dev->dev_addr, 0,
 				       (u32 *)(&priv->rtllib->swcamtable[4].key_buf[0]));
 		} else {
 			rtl92e_set_key(dev, 4, 0,
drivers/staging/rtl8192u/r8192U.h +2 -1
index 4013107cd93a..14ca00a2789b 100644
@@ -1114,6 +1114,7 @@ void rtl8192_set_rxconf(struct net_device *dev);
 void rtl819xusb_beacon_tx(struct net_device *dev, u16 tx_rate);
 
 void EnableHWSecurityConfig8192(struct net_device *dev);
-void setKey(struct net_device *dev, u8 EntryNo, u8 KeyIndex, u16 KeyType, u8 *MacAddr, u8 DefaultKey, u32 *KeyContent);
+void setKey(struct net_device *dev, u8 EntryNo, u8 KeyIndex, u16 KeyType,
+	    const u8 *MacAddr, u8 DefaultKey, u32 *KeyContent);
 
 #endif
drivers/staging/rtl8192u/r8192U_core.c +0 -0
index 3718d72e217e..cfbd9d79baa7 100644
@@ -2300,12 +2300,15 @@ static int rtl8192_read_eeprom_info(struct net_device *dev)
 	/* set channelplan from eeprom */

drivers/staging/rtl8192u/r8192U_core.c static int rtl8192_read_eeprom_info(struct net_device *dev) · line 2309

Quoted 10 lines
drivers/staging/rtl8192u/r8192U_core.c +3 -1
 	priv->ChannelPlan = priv->eeprom_ChannelPlan;
 	if (bLoad_From_EEPOM) {
+		u8 addr[ETH_ALEN];
+
 		for (i = 0; i < 6; i += 2) {
 			ret = eprom_read(dev, (u16)((EEPROM_NODE_ADDRESS_BYTE_0 + i) >> 1));
 			if (ret < 0)
 				return ret;
-			*(u16 *)(&dev->dev_addr[i]) = (u16)ret;
+			*(u16 *)(&addr[i]) = (u16)ret;

Same thing here.

drivers/staging/rtl8192u/r8192U_core.c static int rtl8192_read_eeprom_info(struct net_device *dev) · line 2314

Quoted 5 lines
drivers/staging/rtl8192u/r8192U_core.c +1 -0
 		}
+		eth_hw_addr_set(dev, addr);
 	} else {
 		eth_hw_addr_set(dev, bMac_Tmp_Addr);
 		/* should I set IDR0 here? */

regards,
dan carpenter

#9 lore raw

Re: [PATCH 7/8] staging: rtl: use eth_hw_addr_set()

Quoted 11 lines · On Wed, 3 Nov 2021 14:29:06 +0300 Dan Carpenter wrote:

drivers/staging/rtl8192e/rtl8192e/r8192E_dev.c static void _rtl92e_read_eeprom_info(struct net_device *dev) · line 368

Quoted 8 lines
drivers/staging/rtl8192e/rtl8192e/r8192E_dev.c +3 -1
 	if (!priv->AutoloadFailFlag) {
+		u8 addr[ETH_ALEN];
+
 		for (i = 0; i < 6; i += 2) {
 			usValue = rtl92e_eeprom_read(dev,
 				 (EEPROM_NODE_ADDRESS_BYTE_0 + i) >> 1);
-			*(u16 *)(&dev->dev_addr[i]) = usValue;
+			*(u16 *)(&addr[i]) = usValue;  

No this doesn't work. It writes 2 bytes instead of one so it will write one element beyond the end of addr[].

But the index moves by 2, IOW loop is only executed for i = 0, 2, 4.

Quoted 1 line

It doesn't work at all on little endian systems.

Indeed.

Quoted 2 lines

I'm not sure what's going on here or how to fix it but array overflows are always bad.

Same :(

#10 lore raw

Re: [PATCH 7/8] staging: rtl: use eth_hw_addr_set()

Quoted 13 lines · Jakub Kicinski
Quoted 11 lines · On Wed, 3 Nov 2021 14:29:06 +0300 Dan Carpenter wrote:

drivers/staging/rtl8192e/rtl8192e/r8192E_dev.c static void _rtl92e_read_eeprom_info(struct net_device *dev) · line 368

Quoted 8 lines
drivers/staging/rtl8192e/rtl8192e/r8192E_dev.c +3 -1
 	if (!priv->AutoloadFailFlag) {
+		u8 addr[ETH_ALEN];
+
 		for (i = 0; i < 6; i += 2) {
 			usValue = rtl92e_eeprom_read(dev,
 				 (EEPROM_NODE_ADDRESS_BYTE_0 + i) >> 1);
-			*(u16 *)(&dev->dev_addr[i]) = usValue;
+			*(u16 *)(&addr[i]) = usValue;  

No this doesn't work. It writes 2 bytes instead of one so it will write one element beyond the end of addr[].

Quoted 1 line

But the index moves by 2, IOW loop is only executed for i = 0, 2, 4.

Ah, right. I missed that.

regards,
dan carpenter

#11 lore raw

PATCH 8/8 staging: use eth_hw_addr_set() in orphan drivers

In reply to Jakub Kicinski

Commit 406f42fa0d3c ("net-next: When a bond have a massive amount of VLANs...") introduced a rbtree for faster Ethernet address look up. To maintain netdev->dev_addr in this tree we need to make all the writes to it got through appropriate helpers.

---
CC: [email protected]
CC: [email protected]
CC: [email protected]

---
 drivers/staging/gdm724x/gdm_lte.c   | 4 +++-
 drivers/staging/octeon/ethernet.c   | 2 +-
 drivers/staging/wlan-ng/prism2sta.c | 4 +++-
 3 files changed, 7 insertions(+), 3 deletions(-)
drivers/staging/gdm724x/gdm_lte.c +3 -1
index e390c924ec1c..493ed4821515 100644
@@ -867,6 +867,7 @@ int register_lte_device(struct phy_dev *phy_dev,
 	struct nic *nic;
 	struct net_device *net;
 	char pdn_dev_name[16];
+	u8 addr[ETH_ALEN];
 	int ret = 0;
 	u8 index;
 
@@ -893,11 +894,12 @@ int register_lte_device(struct phy_dev *phy_dev,
 		nic->phy_dev = phy_dev;
 		nic->nic_id = index;
 
-		form_mac_address(net->dev_addr,
+		form_mac_address(addr,
 				 nic->src_mac_addr,
 				 nic->dest_mac_addr,
 				 mac_address,
 				 index);
+		eth_hw_addr_set(net, addr);
 
 		SET_NETDEV_DEV(net, dev);
 		SET_NETDEV_DEVTYPE(net, &wwan_type);
drivers/staging/octeon/ethernet.c +1 -1
index 5d24c1b6663b..bf8c5443a218 100644
@@ -350,7 +350,7 @@ static int cvm_oct_set_mac_filter(struct net_device *dev)
 	    (cvmx_helper_interface_get_mode(interface) !=
 		CVMX_HELPER_INTERFACE_MODE_SPI)) {
 		int i;
-		u8 *ptr = dev->dev_addr;
+		const u8 *ptr = dev->dev_addr;
 		u64 mac = 0;
 		int index = INDEX(priv->port);
 
drivers/staging/wlan-ng/prism2sta.c +3 -1
index 1be43300052f..daa7cc4e897c 100644
@@ -585,6 +585,7 @@ static int prism2sta_getcardinfo(struct wlandevice *wlandev)
 	struct hfa384x *hw = wlandev->priv;
 	u16 temp;
 	u8 snum[HFA384x_RID_NICSERIALNUMBER_LEN];
+	u8 addr[ETH_ALEN];
 
 	/* Collect version and compatibility info */
 	/*  Some are critical, some are not */
@@ -855,11 +856,12 @@ static int prism2sta_getcardinfo(struct wlandevice *wlandev)
 
 	/* Collect the MAC address */
 	result = hfa384x_drvr_getconfig(hw, HFA384x_RID_CNFOWNMACADDR,
-					wlandev->netdev->dev_addr, ETH_ALEN);
+					addr, ETH_ALEN);
 	if (result != 0) {
 		netdev_err(wlandev->netdev, "Failed to retrieve mac address\n");
 		goto failed;
 	}
+	eth_hw_addr_set(wlandev->netdev, addr);
 
 	/* short preamble is always implemented */
 	wlandev->nsdcaps |= P80211_NSDCAP_SHORT_PREAMBLE;
Signature · 1 line
2.31.1
Reviewed-by on v1 8/8
#12 lore raw

Re: [PATCH 8/8] staging: use eth_hw_addr_set() in orphan drivers

Quoted 6 lines · Jakub Kicinski

Commit 406f42fa0d3c ("net-next: When a bond have a massive amount of VLANs...") introduced a rbtree for faster Ethernet address look up. To maintain netdev->dev_addr in this tree we need to make all the writes to it got through appropriate helpers.

Signature · 1 line
Kees Cook
maintainer
#13 lore raw
In reply to Jakub Kicinski
Quoted 8 lines · Jakub Kicinski

Hi Greg,

This set prepares staging for netdev->dev_addr being const. We need to sprinkle const around some variables and arguments and use appropriate helpers to write to netdev->dev_addr.

I'll do another pass over staging before the merge window, this set is based on what's already there in net-next.

Are these ok to take through my tree now? Or are you wanting to take them all through netdev?

thanks,

greg k-h

#14 lore raw
Quoted 7 lines · On Tue, 19 Oct 2021 19:34:18 +0200 Greg KH wrote:
Quoted 6 lines · Jakub Kicinski

Hi Greg,

This set prepares staging for netdev->dev_addr being const. We need to sprinkle const around some variables and arguments and use appropriate helpers to write to netdev->dev_addr.

Quoted 5 lines
Quoted 2 lines

I'll do another pass over staging before the merge window, this set is based on what's already there in net-next.

Are these ok to take through my tree now? Or are you wanting to take them all through netdev?

I was expecting you to take them, I'll only mark netdev->dev_addr const after the next merge window so no rush until then.

And there's already a small conflict between this set if generated on top of net-next and changes you have in your tree.

maintainer
#15 lore raw
Quoted 8 lines · Jakub Kicinski
Quoted 7 lines · On Tue, 19 Oct 2021 19:34:18 +0200 Greg KH wrote:
Quoted 6 lines · Jakub Kicinski

Hi Greg,

This set prepares staging for netdev->dev_addr being const. We need to sprinkle const around some variables and arguments and use appropriate helpers to write to netdev->dev_addr.

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

I'll do another pass over staging before the merge window, this set is based on what's already there in net-next.

Are these ok to take through my tree now? Or are you wanting to take them all through netdev?

I was expecting you to take them, I'll only mark netdev->dev_addr const after the next merge window so no rush until then.

Ok, I'll apply them to my tree tomorrow, thanks!

greg k-h