OSDN Git Service

ethernet: sun: remove direct netdev->dev_addr writes
authorJakub Kicinski <kuba@kernel.org>
Fri, 8 Oct 2021 17:59:12 +0000 (10:59 -0700)
committerDavid S. Miller <davem@davemloft.net>
Sat, 9 Oct 2021 10:46:57 +0000 (11:46 +0100)
Consify temporary variables pointing to netdev->dev_addr.

A few places need local storage but pretty simple conversion
over all. Note that macaddr[] is an array of ints, so we need
to keep the loops.

Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/sun/cassini.c
drivers/net/ethernet/sun/ldmvsw.c
drivers/net/ethernet/sun/niu.c
drivers/net/ethernet/sun/sungem.c
drivers/net/ethernet/sun/sunhme.c

index 287ae4c..d2d4f47 100644 (file)
@@ -3027,7 +3027,7 @@ static void cas_mac_reset(struct cas *cp)
 /* Must be invoked under cp->lock. */
 static void cas_init_mac(struct cas *cp)
 {
-       unsigned char *e = &cp->dev->dev_addr[0];
+       const unsigned char *e = &cp->dev->dev_addr[0];
        int i;
        cas_mac_reset(cp);
 
@@ -3379,6 +3379,7 @@ static void cas_check_pci_invariants(struct cas *cp)
 static int cas_check_invariants(struct cas *cp)
 {
        struct pci_dev *pdev = cp->pdev;
+       u8 addr[ETH_ALEN];
        u32 cfg;
        int i;
 
@@ -3407,8 +3408,8 @@ static int cas_check_invariants(struct cas *cp)
        /* finish phy determination. MDIO1 takes precedence over MDIO0 if
         * they're both connected.
         */
-       cp->phy_type = cas_get_vpd_info(cp, cp->dev->dev_addr,
-                                       PCI_SLOT(pdev->devfn));
+       cp->phy_type = cas_get_vpd_info(cp, addr, PCI_SLOT(pdev->devfn));
+       eth_hw_addr_set(cp->dev, addr);
        if (cp->phy_type & CAS_PHY_SERDES) {
                cp->cas_flags |= CAS_FLAG_1000MB_CAP;
                return 0; /* no more checking needed */
index 50bd4e3..074c540 100644 (file)
@@ -230,7 +230,6 @@ static struct net_device *vsw_alloc_netdev(u8 hwaddr[],
 {
        struct net_device *dev;
        struct vnet_port *port;
-       int i;
 
        dev = alloc_etherdev_mqs(sizeof(*port), VNET_MAX_TXQS, 1);
        if (!dev)
@@ -238,10 +237,8 @@ static struct net_device *vsw_alloc_netdev(u8 hwaddr[],
        dev->needed_headroom = VNET_PACKET_SKIP + 8;
        dev->needed_tailroom = 8;
 
-       for (i = 0; i < ETH_ALEN; i++) {
-               dev->dev_addr[i] = hwaddr[i];
-               dev->perm_addr[i] = dev->dev_addr[i];
-       }
+       eth_hw_addr_set(dev, hwaddr);
+       ether_addr_copy(dev->perm_addr, dev->dev_addr)
 
        sprintf(dev->name, "vif%d.%d", (int)handle, (int)port_id);
 
index 1a73a94..ba8ad76 100644 (file)
@@ -2603,7 +2603,7 @@ static int niu_init_link(struct niu *np)
        return 0;
 }
 
-static void niu_set_primary_mac(struct niu *np, unsigned char *addr)
+static void niu_set_primary_mac(struct niu *np, const unsigned char *addr)
 {
        u16 reg0 = addr[4] << 8 | addr[5];
        u16 reg1 = addr[2] << 8 | addr[3];
@@ -8312,6 +8312,7 @@ static void niu_pci_vpd_validate(struct niu *np)
 {
        struct net_device *dev = np->dev;
        struct niu_vpd *vpd = &np->vpd;
+       u8 addr[ETH_ALEN];
        u8 val8;
 
        if (!is_valid_ether_addr(&vpd->local_mac[0])) {
@@ -8344,17 +8345,20 @@ static void niu_pci_vpd_validate(struct niu *np)
                return;
        }
 
-       eth_hw_addr_set(dev, vpd->local_mac);
+       ether_addr_copy(addr, vpd->local_mac);
 
-       val8 = dev->dev_addr[5];
-       dev->dev_addr[5] += np->port;
-       if (dev->dev_addr[5] < val8)
-               dev->dev_addr[4]++;
+       val8 = addr[5];
+       addr[5] += np->port;
+       if (addr[5] < val8)
+               addr[4]++;
+
+       eth_hw_addr_set(dev, addr);
 }
 
 static int niu_pci_probe_sprom(struct niu *np)
 {
        struct net_device *dev = np->dev;
+       u8 addr[ETH_ALEN];
        int len, i;
        u64 val, sum;
        u8 val8;
@@ -8446,27 +8450,29 @@ static int niu_pci_probe_sprom(struct niu *np)
        val = nr64(ESPC_MAC_ADDR0);
        netif_printk(np, probe, KERN_DEBUG, np->dev,
                     "SPROM: MAC_ADDR0[%08llx]\n", (unsigned long long)val);
-       dev->dev_addr[0] = (val >>  0) & 0xff;
-       dev->dev_addr[1] = (val >>  8) & 0xff;
-       dev->dev_addr[2] = (val >> 16) & 0xff;
-       dev->dev_addr[3] = (val >> 24) & 0xff;
+       addr[0] = (val >>  0) & 0xff;
+       addr[1] = (val >>  8) & 0xff;
+       addr[2] = (val >> 16) & 0xff;
+       addr[3] = (val >> 24) & 0xff;
 
        val = nr64(ESPC_MAC_ADDR1);
        netif_printk(np, probe, KERN_DEBUG, np->dev,
                     "SPROM: MAC_ADDR1[%08llx]\n", (unsigned long long)val);
-       dev->dev_addr[4] = (val >>  0) & 0xff;
-       dev->dev_addr[5] = (val >>  8) & 0xff;
+       addr[4] = (val >>  0) & 0xff;
+       addr[5] = (val >>  8) & 0xff;
 
-       if (!is_valid_ether_addr(&dev->dev_addr[0])) {
+       if (!is_valid_ether_addr(addr)) {
                dev_err(np->device, "SPROM MAC address invalid [ %pM ]\n",
-                       dev->dev_addr);
+                       addr);
                return -EINVAL;
        }
 
-       val8 = dev->dev_addr[5];
-       dev->dev_addr[5] += np->port;
-       if (dev->dev_addr[5] < val8)
-               dev->dev_addr[4]++;
+       val8 = addr[5];
+       addr[5] += np->port;
+       if (addr[5] < val8)
+               addr[4]++;
+
+       eth_hw_addr_set(dev, addr);
 
        val = nr64(ESPC_MOD_STR_LEN);
        netif_printk(np, probe, KERN_DEBUG, np->dev,
index 5f786d6..0368561 100644 (file)
@@ -1810,7 +1810,7 @@ static u32 gem_setup_multicast(struct gem *gp)
 
 static void gem_init_mac(struct gem *gp)
 {
-       unsigned char *e = &gp->dev->dev_addr[0];
+       const unsigned char *e = &gp->dev->dev_addr[0];
 
        writel(0x1bf0, gp->regs + MAC_SNDPAUSE);
 
@@ -2087,7 +2087,7 @@ static void gem_stop_phy(struct gem *gp, int wol)
        writel(mifcfg, gp->regs + MIF_CFG);
 
        if (wol && gp->has_wol) {
-               unsigned char *e = &gp->dev->dev_addr[0];
+               const unsigned char *e = &gp->dev->dev_addr[0];
                u32 csr;
 
                /* Setup wake-on-lan for MAGIC packet */
@@ -2431,8 +2431,8 @@ static struct net_device_stats *gem_get_stats(struct net_device *dev)
 static int gem_set_mac_address(struct net_device *dev, void *addr)
 {
        struct sockaddr *macaddr = (struct sockaddr *) addr;
+       const unsigned char *e = &dev->dev_addr[0];
        struct gem *gp = netdev_priv(dev);
-       unsigned char *e = &dev->dev_addr[0];
 
        if (!is_valid_ether_addr(macaddr->sa_data))
                return -EADDRNOTAVAIL;
@@ -2799,7 +2799,10 @@ static int gem_get_device_address(struct gem *gp)
        }
        eth_hw_addr_set(dev, addr);
 #else
-       get_gem_mac_nonobp(gp->pdev, gp->dev->dev_addr);
+       u8 addr[ETH_ALEN];
+
+       get_gem_mac_nonobp(gp->pdev, addr);
+       eth_hw_addr_set(gp->dev, addr);
 #endif
        return 0;
 }
index fe5482b..ad9029a 100644 (file)
@@ -1395,13 +1395,13 @@ force_link:
 /* hp->happy_lock must be held */
 static int happy_meal_init(struct happy_meal *hp)
 {
+       const unsigned char *e = &hp->dev->dev_addr[0];
        void __iomem *gregs        = hp->gregs;
        void __iomem *etxregs      = hp->etxregs;
        void __iomem *erxregs      = hp->erxregs;
        void __iomem *bregs        = hp->bigmacregs;
        void __iomem *tregs        = hp->tcvregs;
        u32 regtmp, rxcfg;
-       unsigned char *e = &hp->dev->dev_addr[0];
 
        /* If auto-negotiation timer is running, kill it. */
        del_timer(&hp->happy_timer);
@@ -2661,6 +2661,7 @@ static int happy_meal_sbus_probe_one(struct platform_device *op, int is_qfe)
        struct happy_meal *hp;
        struct net_device *dev;
        int i, qfe_slot = -1;
+       u8 addr[ETH_ALEN];
        int err = -ENODEV;
 
        sbus_dp = op->dev.parent->of_node;
@@ -2698,7 +2699,8 @@ static int happy_meal_sbus_probe_one(struct platform_device *op, int is_qfe)
        }
        if (i < 6) { /* a mac address was given */
                for (i = 0; i < 6; i++)
-                       dev->dev_addr[i] = macaddr[i];
+                       addr[i] = macaddr[i];
+               eth_hw_addr_set(dev, addr);
                macaddr[5]++;
        } else {
                const unsigned char *addr;
@@ -2969,6 +2971,7 @@ static int happy_meal_pci_probe(struct pci_dev *pdev,
        unsigned long hpreg_res;
        int i, qfe_slot = -1;
        char prom_name[64];
+       u8 addr[ETH_ALEN];
        int err;
 
        /* Now make sure pci_dev cookie is there. */
@@ -3044,7 +3047,8 @@ static int happy_meal_pci_probe(struct pci_dev *pdev,
        }
        if (i < 6) { /* a mac address was given */
                for (i = 0; i < 6; i++)
-                       dev->dev_addr[i] = macaddr[i];
+                       addr[i] = macaddr[i];
+               eth_hw_addr_set(dev, addr);
                macaddr[5]++;
        } else {
 #ifdef CONFIG_SPARC
@@ -3060,7 +3064,10 @@ static int happy_meal_pci_probe(struct pci_dev *pdev,
                        eth_hw_addr_set(dev, idprom->id_ethaddr);
                }
 #else
-               get_hme_mac_nonsparc(pdev, &dev->dev_addr[0]);
+               u8 addr[ETH_ALEN];
+
+               get_hme_mac_nonsparc(pdev, addr);
+               eth_hw_addr_set(dev, addr);
 #endif
        }