Skip to content

Commit

Permalink
Merge branch 'net-don-t-write-directly-to-netdev-dev_addr'
Browse files Browse the repository at this point in the history
Don't write directly to netdev->dev_addr.

More conversions, mostly in usb/net.

v2: leave out catc (patch 4)

Link: https://lore.kernel.org/r/20211021131214.2032925-1-kuba@kernel.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
  • Loading branch information
Jakub Kicinski committed Oct 22, 2021
2 parents 016c894 + 65a4fbb commit 07591eb
Show file tree
Hide file tree
Showing 30 changed files with 99 additions and 61 deletions.
6 changes: 3 additions & 3 deletions drivers/net/fddi/defxx.c
Original file line number Diff line number Diff line change
Expand Up @@ -1117,7 +1117,7 @@ static int dfx_driver_init(struct net_device *dev, const char *print_name,
* dfx_ctl_set_mac_address.
*/

memcpy(dev->dev_addr, bp->factory_mac_addr, FDDI_K_ALEN);
dev_addr_set(dev, bp->factory_mac_addr);
if (dfx_bus_tc)
board_name = "DEFTA";
if (dfx_bus_eisa)
Expand Down Expand Up @@ -1474,7 +1474,7 @@ static int dfx_open(struct net_device *dev)
* address.
*/

memcpy(dev->dev_addr, bp->factory_mac_addr, FDDI_K_ALEN);
dev_addr_set(dev, bp->factory_mac_addr);

/* Clear local unicast/multicast address tables and counts */

Expand Down Expand Up @@ -2379,7 +2379,7 @@ static int dfx_ctl_set_mac_address(struct net_device *dev, void *addr)

/* Copy unicast address to driver-maintained structs and update count */

memcpy(dev->dev_addr, p_sockaddr->sa_data, FDDI_K_ALEN); /* update device struct */
dev_addr_set(dev, p_sockaddr->sa_data); /* update device struct */
memcpy(&bp->uc_table[0], p_sockaddr->sa_data, FDDI_K_ALEN); /* update driver struct */
bp->uc_count = 1;

Expand Down
2 changes: 1 addition & 1 deletion drivers/net/fddi/defza.c
Original file line number Diff line number Diff line change
Expand Up @@ -1380,7 +1380,7 @@ static int fza_probe(struct device *bdev)
goto err_out_irq;

fza_reads(&init->hw_addr, &hw_addr, sizeof(hw_addr));
memcpy(dev->dev_addr, &hw_addr, FDDI_K_ALEN);
dev_addr_set(dev, &hw_addr);

fza_reads(&init->rom_rev, &rom_rev, sizeof(rom_rev));
fza_reads(&init->fw_rev, &fw_rev, sizeof(fw_rev));
Expand Down
2 changes: 1 addition & 1 deletion drivers/net/fddi/skfp/h/smc.h
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ void card_stop(struct s_smc *smc);
void init_board(struct s_smc *smc, u_char *mac_addr);
int init_fplus(struct s_smc *smc);
void init_plc(struct s_smc *smc);
int init_smt(struct s_smc *smc, u_char *mac_addr);
int init_smt(struct s_smc *smc, const u_char *mac_addr);
void mac1_irq(struct s_smc *smc, u_short stu, u_short stl);
void mac2_irq(struct s_smc *smc, u_short code_s2u, u_short code_s2l);
void mac3_irq(struct s_smc *smc, u_short code_s3u, u_short code_s3l);
Expand Down
2 changes: 1 addition & 1 deletion drivers/net/fddi/skfp/skfddi.c
Original file line number Diff line number Diff line change
Expand Up @@ -925,7 +925,7 @@ static int skfp_ctl_set_mac_address(struct net_device *dev, void *addr)
unsigned long Flags;


memcpy(dev->dev_addr, p_sockaddr->sa_data, FDDI_K_ALEN);
dev_addr_set(dev, p_sockaddr->sa_data);
spin_lock_irqsave(&bp->DriverLock, Flags);
ResetAdapter(smc);
spin_unlock_irqrestore(&bp->DriverLock, Flags);
Expand Down
4 changes: 2 additions & 2 deletions drivers/net/fddi/skfp/smtinit.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include "h/fddi.h"
#include "h/smc.h"

void init_fddi_driver(struct s_smc *smc, u_char *mac_addr);
void init_fddi_driver(struct s_smc *smc, const u_char *mac_addr);

/* define global debug variable */
#if defined(DEBUG) && !defined(DEBUG_BRD)
Expand Down Expand Up @@ -57,7 +57,7 @@ static void set_oem_spec_val(struct s_smc *smc)
/*
* Init SMT
*/
int init_smt(struct s_smc *smc, u_char *mac_addr)
int init_smt(struct s_smc *smc, const u_char *mac_addr)
/* u_char *mac_addr; canonical address or NULL */
{
int p ;
Expand Down
3 changes: 2 additions & 1 deletion drivers/net/fjes/fjes_hw.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ static void fjes_hw_free_epbuf(struct epbuf_handler *epbh)
epbh->ring = NULL;
}

void fjes_hw_setup_epbuf(struct epbuf_handler *epbh, u8 *mac_addr, u32 mtu)
void fjes_hw_setup_epbuf(struct epbuf_handler *epbh, const u8 *mac_addr,
u32 mtu)
{
union ep_buffer_info *info = epbh->info;
u16 vlan_id[EP_BUFFER_SUPPORT_VLAN_MAX];
Expand Down
2 changes: 1 addition & 1 deletion drivers/net/fjes/fjes_hw.h
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ int fjes_hw_register_buff_addr(struct fjes_hw *, int,
int fjes_hw_unregister_buff_addr(struct fjes_hw *, int);
void fjes_hw_init_command_registers(struct fjes_hw *,
struct fjes_device_command_param *);
void fjes_hw_setup_epbuf(struct epbuf_handler *, u8 *, u32);
void fjes_hw_setup_epbuf(struct epbuf_handler *, const u8 *, u32);
int fjes_hw_raise_interrupt(struct fjes_hw *, int, enum REG_ICTL_MASK);
void fjes_hw_set_irqmask(struct fjes_hw *, enum REG_ICTL_MASK, bool);
u32 fjes_hw_capture_interrupt_status(struct fjes_hw *);
Expand Down
14 changes: 8 additions & 6 deletions drivers/net/fjes/fjes_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1203,6 +1203,7 @@ static int fjes_probe(struct platform_device *plat_dev)
struct net_device *netdev;
struct resource *res;
struct fjes_hw *hw;
u8 addr[ETH_ALEN];
int err;

err = -ENOMEM;
Expand Down Expand Up @@ -1266,12 +1267,13 @@ static int fjes_probe(struct platform_device *plat_dev)
goto err_free_control_wq;

/* setup MAC address (02:00:00:00:00:[epid])*/
netdev->dev_addr[0] = 2;
netdev->dev_addr[1] = 0;
netdev->dev_addr[2] = 0;
netdev->dev_addr[3] = 0;
netdev->dev_addr[4] = 0;
netdev->dev_addr[5] = hw->my_epid; /* EPID */
addr[0] = 2;
addr[1] = 0;
addr[2] = 0;
addr[3] = 0;
addr[4] = 0;
addr[5] = hw->my_epid; /* EPID */
eth_hw_addr_set(netdev, addr);

err = register_netdev(netdev);
if (err)
Expand Down
6 changes: 4 additions & 2 deletions drivers/net/hippi/rrunner.c
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,7 @@ static unsigned int write_eeprom(struct rr_private *rrpriv,

static int rr_init(struct net_device *dev)
{
u8 addr[HIPPI_ALEN] __aligned(4);
struct rr_private *rrpriv;
struct rr_regs __iomem *regs;
u32 sram_size, rev;
Expand Down Expand Up @@ -537,10 +538,11 @@ static int rr_init(struct net_device *dev)
* other method I've seen. -VAL
*/

*(__be16 *)(dev->dev_addr) =
*(__be16 *)(addr) =
htons(rr_read_eeprom_word(rrpriv, offsetof(struct eeprom, manf.BoardULA)));
*(__be32 *)(dev->dev_addr+2) =
*(__be32 *)(addr+2) =
htonl(rr_read_eeprom_word(rrpriv, offsetof(struct eeprom, manf.BoardULA[4])));
dev_addr_set(dev, addr);

printk(" MAC: %pM\n", dev->dev_addr);

Expand Down
8 changes: 6 additions & 2 deletions drivers/net/plip/plip.c
Original file line number Diff line number Diff line change
Expand Up @@ -284,12 +284,16 @@ static const struct net_device_ops plip_netdev_ops = {
static void
plip_init_netdev(struct net_device *dev)
{
static const u8 addr_init[ETH_ALEN] = {
0xfc, 0xfc, 0xfc,
0xfc, 0xfc, 0xfc,
};
struct net_local *nl = netdev_priv(dev);

/* Then, override parts of it */
dev->tx_queue_len = 10;
dev->flags = IFF_POINTOPOINT|IFF_NOARP;
memset(dev->dev_addr, 0xfc, ETH_ALEN);
eth_hw_addr_set(dev, addr_init);

dev->netdev_ops = &plip_netdev_ops;
dev->header_ops = &plip_header_ops;
Expand Down Expand Up @@ -1109,7 +1113,7 @@ plip_open(struct net_device *dev)
plip_init_dev(). */
const struct in_ifaddr *ifa = rcu_dereference(in_dev->ifa_list);
if (ifa != NULL) {
memcpy(dev->dev_addr+2, &ifa->ifa_local, 4);
dev_addr_mod(dev, 2, &ifa->ifa_local, 4);
}
}

Expand Down
14 changes: 8 additions & 6 deletions drivers/net/rionet.c
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,7 @@ static int rionet_setup_netdev(struct rio_mport *mport, struct net_device *ndev)
{
int rc = 0;
struct rionet_private *rnet;
u8 addr[ETH_ALEN];
u16 device_id;
const size_t rionet_active_bytes = sizeof(void *) *
RIO_MAX_ROUTE_ENTRIES(mport->sys_size);
Expand All @@ -501,12 +502,13 @@ static int rionet_setup_netdev(struct rio_mport *mport, struct net_device *ndev)

/* Set the default MAC address */
device_id = rio_local_get_device_id(mport);
ndev->dev_addr[0] = 0x00;
ndev->dev_addr[1] = 0x01;
ndev->dev_addr[2] = 0x00;
ndev->dev_addr[3] = 0x01;
ndev->dev_addr[4] = device_id >> 8;
ndev->dev_addr[5] = device_id & 0xff;
addr[0] = 0x00;
addr[1] = 0x01;
addr[2] = 0x00;
addr[3] = 0x01;
addr[4] = device_id >> 8;
addr[5] = device_id & 0xff;
eth_hw_addr_set(ndev, addr);

ndev->netdev_ops = &rionet_netdev_ops;
ndev->mtu = RIONET_MAX_MTU;
Expand Down
12 changes: 8 additions & 4 deletions drivers/net/sb1000.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ sb1000_probe_one(struct pnp_dev *pdev, const struct pnp_device_id *id)
unsigned short ioaddr[2], irq;
unsigned int serial_number;
int error = -ENODEV;
u8 addr[ETH_ALEN];

if (pnp_device_attach(pdev) < 0)
return -ENODEV;
Expand Down Expand Up @@ -203,10 +204,13 @@ sb1000_probe_one(struct pnp_dev *pdev, const struct pnp_device_id *id)
dev->netdev_ops = &sb1000_netdev_ops;

/* hardware address is 0:0:serial_number */
dev->dev_addr[2] = serial_number >> 24 & 0xff;
dev->dev_addr[3] = serial_number >> 16 & 0xff;
dev->dev_addr[4] = serial_number >> 8 & 0xff;
dev->dev_addr[5] = serial_number >> 0 & 0xff;
addr[0] = 0;
addr[1] = 0;
addr[2] = serial_number >> 24 & 0xff;
addr[3] = serial_number >> 16 & 0xff;
addr[4] = serial_number >> 8 & 0xff;
addr[5] = serial_number >> 0 & 0xff;
eth_hw_addr_set(dev, addr);

pnp_set_drvdata(pdev, dev);

Expand Down
4 changes: 3 additions & 1 deletion drivers/net/usb/ch9200.c
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ static int ch9200_bind(struct usbnet *dev, struct usb_interface *intf)
{
int retval = 0;
unsigned char data[2];
u8 addr[ETH_ALEN];

retval = usbnet_get_endpoints(dev, intf);
if (retval)
Expand Down Expand Up @@ -383,7 +384,8 @@ static int ch9200_bind(struct usbnet *dev, struct usb_interface *intf)
retval = control_write(dev, REQUEST_WRITE, 0, MAC_REG_CTRL, data, 0x02,
CONTROL_TIMEOUT_MS);

retval = get_mac_address(dev, dev->net->dev_addr);
retval = get_mac_address(dev, addr);
eth_hw_addr_set(dev->net, addr);

return retval;
}
Expand Down
5 changes: 3 additions & 2 deletions drivers/net/usb/cx82310_eth.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ static int cx82310_bind(struct usbnet *dev, struct usb_interface *intf)
u8 link[3];
int timeout = 50;
struct cx82310_priv *priv;
u8 addr[ETH_ALEN];

/* avoid ADSL modems - continue only if iProduct is "USB NET CARD" */
if (usb_string(udev, udev->descriptor.iProduct, buf, sizeof(buf)) > 0
Expand Down Expand Up @@ -202,12 +203,12 @@ static int cx82310_bind(struct usbnet *dev, struct usb_interface *intf)
goto err;

/* get the MAC address */
ret = cx82310_cmd(dev, CMD_GET_MAC_ADDR, true, NULL, 0,
dev->net->dev_addr, ETH_ALEN);
ret = cx82310_cmd(dev, CMD_GET_MAC_ADDR, true, NULL, 0, addr, ETH_ALEN);
if (ret) {
netdev_err(dev->net, "unable to read MAC address: %d\n", ret);
goto err;
}
eth_hw_addr_set(dev->net, addr);

/* start (does not seem to have any effect?) */
ret = cx82310_cmd(dev, CMD_START, false, NULL, 0, NULL, 0);
Expand Down
3 changes: 1 addition & 2 deletions drivers/net/usb/kaweth.c
Original file line number Diff line number Diff line change
Expand Up @@ -1044,8 +1044,7 @@ static int kaweth_probe(
goto err_all_but_rxbuf;

memcpy(netdev->broadcast, &bcast_addr, sizeof(bcast_addr));
memcpy(netdev->dev_addr, &kaweth->configuration.hw_addr,
sizeof(kaweth->configuration.hw_addr));
eth_hw_addr_set(netdev, (u8 *)&kaweth->configuration.hw_addr);

netdev->netdev_ops = &kaweth_netdev_ops;
netdev->watchdog_timeo = KAWETH_TX_TIMEOUT;
Expand Down
4 changes: 3 additions & 1 deletion drivers/net/usb/mcs7830.c
Original file line number Diff line number Diff line change
Expand Up @@ -473,17 +473,19 @@ static const struct net_device_ops mcs7830_netdev_ops = {
static int mcs7830_bind(struct usbnet *dev, struct usb_interface *udev)
{
struct net_device *net = dev->net;
u8 addr[ETH_ALEN];
int ret;
int retry;

/* Initial startup: Gather MAC address setting from EEPROM */
ret = -EINVAL;
for (retry = 0; retry < 5 && ret; retry++)
ret = mcs7830_hif_get_mac_address(dev, net->dev_addr);
ret = mcs7830_hif_get_mac_address(dev, addr);
if (ret) {
dev_warn(&dev->udev->dev, "Cannot read MAC address\n");
goto out;
}
eth_hw_addr_set(net, addr);

mcs7830_data_set_multicast(net);

Expand Down
7 changes: 5 additions & 2 deletions drivers/net/usb/qmi_wwan.c
Original file line number Diff line number Diff line change
Expand Up @@ -835,8 +835,11 @@ static int qmi_wwan_bind(struct usbnet *dev, struct usb_interface *intf)

/* make MAC addr easily distinguishable from an IP header */
if (possibly_iphdr(dev->net->dev_addr)) {
dev->net->dev_addr[0] |= 0x02; /* set local assignment bit */
dev->net->dev_addr[0] &= 0xbf; /* clear "IP" bit */
u8 addr = dev->net->dev_addr[0];

addr |= 0x02; /* set local assignment bit */
addr &= 0xbf; /* clear "IP" bit */
dev_addr_mod(dev->net, 0, &addr, 1);
}
dev->net->netdev_ops = &qmi_wwan_netdev_ops;
dev->net->sysfs_groups[0] = &qmi_wwan_sysfs_attr_group;
Expand Down
6 changes: 4 additions & 2 deletions drivers/net/usb/sierra_net.c
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,7 @@ static int sierra_net_bind(struct usbnet *dev, struct usb_interface *intf)
0x00, 0x00, SIERRA_NET_HIP_MSYNC_ID, 0x00};
static const u8 shdwn_tmplate[sizeof(priv->shdwn_msg)] = {
0x00, 0x00, SIERRA_NET_HIP_SHUTD_ID, 0x00};
u8 mod[2];

dev_dbg(&dev->udev->dev, "%s", __func__);

Expand Down Expand Up @@ -698,8 +699,9 @@ static int sierra_net_bind(struct usbnet *dev, struct usb_interface *intf)
dev->net->netdev_ops = &sierra_net_device_ops;

/* change MAC addr to include, ifacenum, and to be unique */
dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return(&iface_counter);
dev->net->dev_addr[ETH_ALEN-1] = ifacenum;
mod[0] = atomic_inc_return(&iface_counter);
mod[1] = ifacenum;
dev_addr_mod(dev->net, ETH_ALEN - 2, mod, 2);

/* prepare shutdown message template */
memcpy(priv->shdwn_msg, shdwn_tmplate, sizeof(priv->shdwn_msg));
Expand Down
6 changes: 4 additions & 2 deletions drivers/net/usb/smsc75xx.c
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,8 @@ static int smsc75xx_ioctl(struct net_device *netdev, struct ifreq *rq, int cmd)

static void smsc75xx_init_mac_address(struct usbnet *dev)
{
u8 addr[ETH_ALEN];

/* maybe the boot loader passed the MAC address in devicetree */
if (!platform_get_ethdev_address(&dev->udev->dev, dev->net)) {
if (is_valid_ether_addr(dev->net->dev_addr)) {
Expand All @@ -767,8 +769,8 @@ static void smsc75xx_init_mac_address(struct usbnet *dev)
}

/* try reading mac address from EEPROM */
if (smsc75xx_read_eeprom(dev, EEPROM_MAC_OFFSET, ETH_ALEN,
dev->net->dev_addr) == 0) {
if (smsc75xx_read_eeprom(dev, EEPROM_MAC_OFFSET, ETH_ALEN, addr) == 0) {
eth_hw_addr_set(dev->net, addr);
if (is_valid_ether_addr(dev->net->dev_addr)) {
/* eeprom values are valid so use them */
netif_dbg(dev, ifup, dev->net,
Expand Down
6 changes: 4 additions & 2 deletions drivers/net/usb/smsc95xx.c
Original file line number Diff line number Diff line change
Expand Up @@ -755,6 +755,8 @@ static int smsc95xx_ioctl(struct net_device *netdev, struct ifreq *rq, int cmd)

static void smsc95xx_init_mac_address(struct usbnet *dev)
{
u8 addr[ETH_ALEN];

/* maybe the boot loader passed the MAC address in devicetree */
if (!platform_get_ethdev_address(&dev->udev->dev, dev->net)) {
if (is_valid_ether_addr(dev->net->dev_addr)) {
Expand All @@ -765,8 +767,8 @@ static void smsc95xx_init_mac_address(struct usbnet *dev)
}

/* try reading mac address from EEPROM */
if (smsc95xx_read_eeprom(dev, EEPROM_MAC_OFFSET, ETH_ALEN,
dev->net->dev_addr) == 0) {
if (smsc95xx_read_eeprom(dev, EEPROM_MAC_OFFSET, ETH_ALEN, addr) == 0) {
eth_hw_addr_set(dev->net, addr);
if (is_valid_ether_addr(dev->net->dev_addr)) {
/* eeprom values are valid so use them */
netif_dbg(dev, ifup, dev->net, "MAC address read from EEPROM\n");
Expand Down
4 changes: 3 additions & 1 deletion drivers/net/usb/sr9700.c
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@ static int sr9700_bind(struct usbnet *dev, struct usb_interface *intf)
{
struct net_device *netdev;
struct mii_if_info *mii;
u8 addr[ETH_ALEN];
int ret;

ret = usbnet_get_endpoints(dev, intf);
Expand Down Expand Up @@ -350,11 +351,12 @@ static int sr9700_bind(struct usbnet *dev, struct usb_interface *intf)
* EEPROM automatically to PAR. In case there is no EEPROM externally,
* a default MAC address is stored in PAR for making chip work properly.
*/
if (sr_read(dev, SR_PAR, ETH_ALEN, netdev->dev_addr) < 0) {
if (sr_read(dev, SR_PAR, ETH_ALEN, addr) < 0) {
netdev_err(netdev, "Error reading MAC address\n");
ret = -ENODEV;
goto out;
}
eth_hw_addr_set(netdev, addr);

/* power up and reset phy */
sr_write_reg(dev, SR_PRR, PRR_PHY_RST);
Expand Down
Loading

0 comments on commit 07591eb

Please sign in to comment.