don't write directly to netdev->dev_addr
Subsystems (8)
Jakub Kicinski
maintainerv2 cover don't write directly to netdev->dev_addr
Constify references to netdev->dev_addr and
use appropriate helpers.
v2: s/got/go/
Jakub Kicinski (8):
net: core: constify mac addrs in selftests
net: rtnetlink: use __dev_addr_set()
net: phy: constify netdev->dev_addr references
net: bonding: constify and use dev_addr_set()
net: hsr: get ready for const netdev->dev_addr
net: caif: get ready for const netdev->dev_addr
net: drivers: get ready for const netdev->dev_addr
net: atm: use address setting helpers
drivers/net/bonding/bond_alb.c | 28 +++++++++++++--------------- drivers/net/bonding/bond_main.c | 2 +- drivers/net/macsec.c | 2 +- drivers/net/macvlan.c | 3 ++- drivers/net/phy/dp83867.c | 4 ++-- drivers/net/phy/dp83869.c | 4 ++-- drivers/net/vmxnet3/vmxnet3_drv.c | 4 ++-- net/atm/br2684.c | 4 +++- net/atm/lec.c | 5 ++--- net/caif/caif_usb.c | 2 +- net/core/rtnetlink.c | 4 ++-- net/core/selftests.c | 8 ++++---- net/hsr/hsr_framereg.c | 4 ++-- net/hsr/hsr_framereg.h | 4 ++-- 14 files changed, 39 insertions(+), 39 deletions(-)
Signature · 1 line
2.31.1
Jakub Kicinski
maintainerPATCH v2 1/8 net: core: constify mac addrs in selftests
Get it ready for constant netdev->dev_addr.
--- net/core/selftests.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
net/core/selftests.c +4 -4
@@ -15,8 +15,8 @@#include <net/udp.h> struct net_packet_attrs { -unsigned char *src; -unsigned char *dst; +const unsigned char *src; +const unsigned char *dst;u32 ip_src;u32 ip_dst;bool tcp;
@@ -173,8 +173,8 @@ static int net_test_loopback_validate(struct sk_buff *skb, struct net_device *orig_ndev) {struct net_test_priv *tpriv = pt->af_packet_priv; -unsigned char *src = tpriv->packet->src; -unsigned char *dst = tpriv->packet->dst; +const unsigned char *src = tpriv->packet->src; +const unsigned char *dst = tpriv->packet->dst;struct netsfhdr *shdr;struct ethhdr *ehdr;struct udphdr *uhdr;
Signature · 1 line
2.31.1
Jakub Kicinski
maintainerPATCH v2 2/8 net: rtnetlink: use __dev_addr_set()
In reply to Jakub KicinskiGet it ready for constant netdev->dev_addr.
--- net/core/rtnetlink.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
net/core/rtnetlink.c +2 -2
@@ -3204,8 +3204,8 @@ struct net_device *rtnl_create_link(struct net *net, const char *ifname, dev->mtu = mtu; }if (tb[IFLA_ADDRESS ]) { -memcpy (dev->dev_addr,nla_data (tb[IFLA_ADDRESS ]), -nla_len (tb[IFLA_ADDRESS ])); +__dev_addr_set (dev,nla_data (tb[IFLA_ADDRESS ]), +nla_len (tb[IFLA_ADDRESS ])); dev->addr_assign_type =NET_ADDR_SET ; }if (tb[IFLA_BROADCAST ])
Signature · 1 line
2.31.1
Jakub Kicinski
maintainerPATCH v2 3/8 net: phy: constify netdev->dev_addr references
In reply to Jakub Kicinskinetdev->dev_addr will become a const soon(ish),
constify the local variables referring to it.
---
CC: [email protected]
CC: [email protected]
--- drivers/net/phy/dp83867.c | 4 ++-- drivers/net/phy/dp83869.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-)
drivers/net/phy/dp83867.c +2 -2
@@ -182,7 +182,7 @@ static int dp83867_set_wol(struct phy_device *phydev, {struct net_device *ndev = phydev->attached_dev;u16 val_rxcfg, val_micr; -u8 *mac; +const u8 *mac; val_rxcfg =phy_read_mmd (phydev,DP83867_DEVADDR ,DP83867_RXFCFG ); val_micr =phy_read (phydev,MII_DP83867_MICR );
@@ -193,7 +193,7 @@ static int dp83867_set_wol(struct phy_device *phydev, val_micr |=MII_DP83867_MICR_WOL_INT_EN ;if (wol->wolopts &WAKE_MAGIC ) { - mac = (u8 *)ndev->dev_addr; + mac = (const u8 *)ndev->dev_addr;if (!is_valid_ether_addr (mac))return -EINVAL ;
drivers/net/phy/dp83869.c +2 -2
@@ -246,7 +246,7 @@ static int dp83869_set_wol(struct phy_device *phydev, {struct net_device *ndev = phydev->attached_dev;int val_rxcfg, val_micr; -u8 *mac; +const u8 *mac;int ret; val_rxcfg =phy_read_mmd (phydev,DP83869_DEVADDR ,DP83869_RXFCFG );
@@ -264,7 +264,7 @@ static int dp83869_set_wol(struct phy_device *phydev,if (wol->wolopts &WAKE_MAGIC || wol->wolopts &WAKE_MAGICSECURE ) { - mac = (u8 *)ndev->dev_addr; + mac = (const u8 *)ndev->dev_addr;if (!is_valid_ether_addr (mac))return -EINVAL ;
Signature · 1 line
2.31.1
Jakub Kicinski
maintainerPATCH v2 4/8 net: bonding: constify and use dev_addr_set()
In reply to Jakub KicinskiCommit 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 go through appropriate helpers.
Make sure local references to netdev->dev_addr are constant.
---
CC: [email protected]
CC: [email protected]
CC: [email protected]
--- drivers/net/bonding/bond_alb.c | 28 +++++++++++++--------------- drivers/net/bonding/bond_main.c | 2 +- 2 files changed, 14 insertions(+), 16 deletions(-)
drivers/net/bonding/bond_alb.c +13 -15
@@ -50,7 +50,7 @@ struct arp_pkt {#pragma pack()/* Forward declaration */ -static void alb_send_learning_packets (struct slave *slave,u8 mac_addr[], +static void alb_send_learning_packets (struct slave *slave,const u8 mac_addr[],bool strict_match);static void rlb_purge_src_ip (struct bonding *bond,struct arp_pkt *arp);static void rlb_src_unlink (struct bonding *bond,u32 index);
@@ -353,7 +353,8 @@ static struct slave *rlb_next_rx_slave(struct bonding *bond)* * Caller must hold RTNL */ -static void rlb_teach_disabled_mac_on_primary (struct bonding *bond,u8 addr[]) +static void rlb_teach_disabled_mac_on_primary (struct bonding *bond, +const u8 addr[]) {struct slave *curr_active =rtnl_dereference (bond->curr_active_slave);
@@ -904,7 +905,7 @@ static void rlb_clear_vlan(struct bonding *bond, unsigned short vlan_id)/*********************** tlb/rlb shared functions *********************/ -static void alb_send_lp_vid (struct slave *slave,u8 mac_addr[], +static void alb_send_lp_vid (struct slave *slave,const u8 mac_addr[],__be16 vlan_proto,u16 vid) {struct learning_pkt pkt;
@@ -940,7 +941,7 @@ static void alb_send_lp_vid(struct slave *slave, u8 mac_addr[],struct alb_walk_data {struct bonding *bond;struct slave *slave; -u8 *mac_addr; +const u8 *mac_addr;bool strict_match; };
@@ -949,9 +950,9 @@ static int alb_upper_dev_walk(struct net_device *upper, {struct alb_walk_data *data = (struct alb_walk_data *)priv->data;bool strict_match = data->strict_match; +const u8 *mac_addr = data->mac_addr;struct bonding *bond = data->bond;struct slave *slave = data->slave; -u8 *mac_addr = data->mac_addr;struct bond_vlan_tag *tags; if (is_vlan_dev(upper) &&
@@ -982,7 +983,7 @@ static int alb_upper_dev_walk(struct net_device *upper,return 0 ; } -static void alb_send_learning_packets (struct slave *slave,u8 mac_addr[], +static void alb_send_learning_packets (struct slave *slave,const u8 mac_addr[],bool strict_match) {struct bonding *bond =bond_get_bond_by_slave (slave);
@@ -1006,14 +1007,14 @@ static void alb_send_learning_packets(struct slave *slave, u8 mac_addr[],rcu_read_unlock (); } -static int alb_set_slave_mac_addr (struct slave *slave,u8 addr[], +static int alb_set_slave_mac_addr (struct slave *slave,const u8 addr[],unsigned int len) {struct net_device *dev = slave->dev;struct sockaddr_storage ss;if (BOND_MODE (slave->bond) ==BOND_MODE_TLB ) { -memcpy (dev->dev_addr, addr, len); +__dev_addr_set (dev, addr, len);return 0 ; }
@@ -1242,8 +1243,7 @@ static int alb_set_mac_address(struct bonding *bond, void *addr) res =dev_set_mac_address (slave->dev, addr,NULL );/* restore net_device's hw address */ -bond_hw_addr_copy (slave->dev->dev_addr, tmp_addr, - slave->dev->addr_len); +dev_addr_set (slave->dev, tmp_addr);if (res) goto unwind;
@@ -1263,8 +1263,7 @@ static int alb_set_mac_address(struct bonding *bond, void *addr) rollback_slave->dev->addr_len);dev_set_mac_address (rollback_slave->dev, (struct sockaddr *)&ss,NULL ); -bond_hw_addr_copy (rollback_slave->dev->dev_addr, tmp_addr, - rollback_slave->dev->addr_len); +dev_addr_set (rollback_slave->dev, tmp_addr); }return res;
@@ -1727,8 +1726,7 @@ void bond_alb_handle_active_change(struct bonding *bond, struct slave *new_slavedev_set_mac_address (new_slave->dev, (struct sockaddr *)&ss,NULL ); -bond_hw_addr_copy (new_slave->dev->dev_addr, tmp_addr, - new_slave->dev->addr_len); +dev_addr_set (new_slave->dev, tmp_addr); }/* curr_active_slave must be set before calling alb_swap_mac_addr */
@@ -1761,7 +1759,7 @@ int bond_alb_set_mac_address(struct net_device *bond_dev, void *addr)if (res)return res; -bond_hw_addr_copy (bond_dev->dev_addr, ss->__data, bond_dev->addr_len); +dev_addr_set (bond_dev, ss->__data);/* If there is no curr_active_slave there is nothing else to do. * Otherwise we'll need to pass the new address to it and handle
drivers/net/bonding/bond_main.c +1 -1
@@ -923,7 +923,7 @@ static int bond_set_dev_addr(struct net_device *bond_dev,if (err)return err; -memcpy (bond_dev->dev_addr, slave_dev->dev_addr, slave_dev->addr_len); +__dev_addr_set (bond_dev, slave_dev->dev_addr, slave_dev->addr_len); bond_dev->addr_assign_type =NET_ADDR_STOLEN ;call_netdevice_notifiers (NETDEV_CHANGEADDR , bond_dev);return 0 ;
Signature · 1 line
2.31.1
Jakub Kicinski
maintainerPATCH v2 5/8 net: hsr: get ready for const netdev->dev_addr
In reply to Jakub Kicinskihsr_create_self_node() may get netdev->dev_addr
passed as argument, netdev->dev_addr will be
const soon.
---
CC: [email protected]
CC: [email protected]
--- net/hsr/hsr_framereg.c | 4 ++-- net/hsr/hsr_framereg.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-)
net/hsr/hsr_framereg.c +2 -2
@@ -76,8 +76,8 @@ static struct hsr_node *find_node_by_addr_A(struct list_head *node_db,* frames from self that's been looped over the HSR ring. */ int hsr_create_self_node (struct hsr_priv *hsr, -unsigned char addr_a[ETH_ALEN ], -unsigned char addr_b[ETH_ALEN ]) +const unsigned char addr_a[ETH_ALEN ], +const unsigned char addr_b[ETH_ALEN ]) {struct list_head *self_node_db = &hsr->self_node_db;struct hsr_node *node, *oldnode;
net/hsr/hsr_framereg.h +2 -2
@@ -48,8 +48,8 @@ int hsr_register_frame_out(struct hsr_port *port, struct hsr_node *node,void hsr_prune_nodes (struct timer_list *t);int hsr_create_self_node (struct hsr_priv *hsr, -unsigned char addr_a[ETH_ALEN ], -unsigned char addr_b[ETH_ALEN ]); +const unsigned char addr_a[ETH_ALEN ], +const unsigned char addr_b[ETH_ALEN ]);void *hsr_get_next_node (struct hsr_priv *hsr,void *_pos,unsigned char addr[ETH_ALEN ]);
Signature · 1 line
2.31.1
Jakub Kicinski
maintainerPATCH v2 6/8 net: caif: get ready for const netdev->dev_addr
In reply to Jakub KicinskiGet it ready for constant netdev->dev_addr.
--- net/caif/caif_usb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/caif/caif_usb.c +1 -1
@@ -81,7 +81,7 @@ static void cfusbl_ctrlcmd(struct cflayer *layr, enum caif_ctrlcmd ctrl, layr->up->ctrlcmd (layr->up, ctrl, layr->id); } -static struct cflayer *cfusbl_create (int phyid,u8 ethaddr[ETH_ALEN ], +static struct cflayer *cfusbl_create (int phyid,const u8 ethaddr[ETH_ALEN ],u8 braddr[ETH_ALEN ]) {struct cfusbl *this =kmalloc (sizeof (struct cfusbl ),GFP_ATOMIC );
Signature · 1 line
2.31.1
Jakub Kicinski
maintainerPATCH v2 7/8 net: drivers: get ready for const netdev->dev_addr
In reply to Jakub KicinskiCommit 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 go through appropriate helpers. We will make netdev->dev_addr a const.
Make sure local references to netdev->dev_addr are constant.
---
CC: [email protected]
CC: [email protected]
--- drivers/net/macsec.c | 2 +- drivers/net/macvlan.c | 3 ++- drivers/net/vmxnet3/vmxnet3_drv.c | 4 ++-- 3 files changed, 5 insertions(+), 4 deletions(-)
drivers/net/macsec.c +1 -1
@@ -250,7 +250,7 @@ static bool send_sci(const struct macsec_secy *secy) (secy->n_rx_sc >1 && !tx_sc->end_station && !tx_sc->scb); } -static sci_t make_sci (u8 *addr,__be16 port) +static sci_t make_sci (const u8 *addr,__be16 port) {sci_t sci;
drivers/net/macvlan.c +2 -1
@@ -698,7 +698,8 @@ static int macvlan_stop(struct net_device *dev)return 0 ; } -static int macvlan_sync_address (struct net_device *dev,unsigned char *addr) +static int macvlan_sync_address (struct net_device *dev, +const unsigned char *addr) {struct macvlan_dev *vlan =netdev_priv (dev);struct net_device *lowerdev = vlan->lowerdev;
drivers/net/vmxnet3/vmxnet3_drv.c +2 -2
@@ -46,7 +46,7 @@ MODULE_DEVICE_TABLE(pci, vmxnet3_pciid_table);static int enable_mq =1 ;static void -vmxnet3_write_mac_addr (struct vmxnet3_adapter *adapter,u8 *mac); +vmxnet3_write_mac_addr (struct vmxnet3_adapter *adapter,const u8 *mac);/* * Enable/Disable the given intr
@@ -2806,7 +2806,7 @@ vmxnet3_quiesce_dev(struct vmxnet3_adapter *adapter)static void -vmxnet3_write_mac_addr (struct vmxnet3_adapter *adapter,u8 *mac) +vmxnet3_write_mac_addr (struct vmxnet3_adapter *adapter,const u8 *mac) {u32 tmp;
Signature · 1 line
2.31.1
Jakub Kicinski
maintainerPATCH v2 8/8 net: atm: use address setting helpers
In reply to Jakub KicinskiGet it ready for constant netdev->dev_addr.
--- net/atm/br2684.c | 4 +++- net/atm/lec.c | 5 ++--- 2 files changed, 5 insertions(+), 4 deletions(-)
net/atm/br2684.c +3 -1
@@ -577,10 +577,12 @@ static int br2684_regvcc(struct atm_vcc *atmvcc, void __user * arg)pr_debug ("vcc=%p, encaps=%d, brvcc=%p\n" , atmvcc, be.encaps, brvcc);if (list_empty (&brdev->brvccs) && !brdev->mac_was_set) {unsigned char *esi = atmvcc->dev->esi; +const u8 one =1 ; +if (esi[0 ] | esi[1 ] | esi[2 ] | esi[3 ] | esi[4 ] | esi[5 ])dev_addr_set (net_dev, esi);else - net_dev->dev_addr[2 ] =1 ; +dev_addr_mod (net_dev,2 , &one,1 ); }list_add (&brvcc->brvccs, &brdev->brvccs);write_unlock_irq (&devs_lock);
net/atm/lec.c +2 -3
@@ -340,12 +340,12 @@ static int lec_close(struct net_device *dev)static int lec_atm_send (struct atm_vcc *vcc,struct sk_buff *skb) { +static const u8 zero_addr[ETH_ALEN ] = {};unsigned long flags;struct net_device *dev = (struct net_device *)vcc->proto_data;struct lec_priv *priv =netdev_priv (dev);struct atmlec_msg *mesg;struct lec_arp_table *entry; -int i;char *tmp;/* FIXME */ WARN_ON (refcount_sub_and_test (skb->truesize, &sk_atm (vcc)->sk_wmem_alloc));
@@ -358,8 +358,7 @@ static int lec_atm_send(struct atm_vcc *vcc, struct sk_buff *skb)eth_hw_addr_set (dev, mesg->content.normal.mac_addr);break ;case l_del_mac_addr: -for (i =0 ; i <6 ; i++) - dev->dev_addr[i] =0 ; +eth_hw_addr_set (dev, zero_addr);break ;case l_addr_delete: lec_addr_delete(priv, mesg->content.normal.atm_addr,
Signature · 1 line
2.31.1
This series was applied to netdev/net-next.git (master) by David S. Miller <[email protected]>:
Hello:
This series was applied to netdev/net-next.git (master) by David S. Miller <[email protected]>:
Quoted 15 lines · On Fri, 22 Oct 2021 16:20:55 -0700 you wrote:
Constify references to
netdev->dev_addrand
use appropriate helpers.v2: s/got/go/
Jakub Kicinski (8):
net: core: constify mac addrs in selftests
net: rtnetlink: use__dev_addr_set()
net: phy: constifynetdev->dev_addrreferences
net: bonding: constify and usedev_addr_set()
net: hsr: get ready for constnetdev->dev_addr
net: caif: get ready for constnetdev->dev_addr
net: drivers: get ready for constnetdev->dev_addr
net: atm: use address setting helpers
Quoted 1 line
[...]
Here is the summary with links:
- [net-next,v2,1/8] net: core: constify mac addrs in selftests
https://git.kernel.org/netdev/net-next/c/5fd348a050f7 - [net-next,v2,2/8] net: rtnetlink: use __dev_addr_set() https://git.kernel.org/netdev/net-next/c/efd38f75bb04 - [net-next,v2,3/8] net: phy: constify netdev->dev_addr references https://git.kernel.org/netdev/net-next/c/86466cbed173 - [net-next,v2,4/8] net: bonding: constify and use dev_addr_set() https://git.kernel.org/netdev/net-next/c/6f238100d098 - [net-next,v2,5/8] net: hsr: get ready for const netdev->dev_addr https://git.kernel.org/netdev/net-next/c/39c19fb9b4f9 - [net-next,v2,6/8] net: caif: get ready for const netdev->dev_addr https://git.kernel.org/netdev/net-next/c/5520fb42a0a1 - [net-next,v2,7/8] net: drivers: get ready for const netdev->dev_addr https://git.kernel.org/netdev/net-next/c/8bc7823ed3bd - [net-next,v2,8/8] net: atm: use address setting helpers https://git.kernel.org/netdev/net-next/c/d6b3daf24e75
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html