Skip to content

Commit a763927

Browse files
kuba-moodavem330
authored andcommitted
ethernet: sun: remove direct netdev->dev_addr writes
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>
1 parent ca87931 commit a763927

File tree

5 files changed

+48
-34
lines changed

5 files changed

+48
-34
lines changed

drivers/net/ethernet/sun/cassini.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3027,7 +3027,7 @@ static void cas_mac_reset(struct cas *cp)
30273027
/* Must be invoked under cp->lock. */
30283028
static void cas_init_mac(struct cas *cp)
30293029
{
3030-
unsigned char *e = &cp->dev->dev_addr[0];
3030+
const unsigned char *e = &cp->dev->dev_addr[0];
30313031
int i;
30323032
cas_mac_reset(cp);
30333033

@@ -3379,6 +3379,7 @@ static void cas_check_pci_invariants(struct cas *cp)
33793379
static int cas_check_invariants(struct cas *cp)
33803380
{
33813381
struct pci_dev *pdev = cp->pdev;
3382+
u8 addr[ETH_ALEN];
33823383
u32 cfg;
33833384
int i;
33843385

@@ -3407,8 +3408,8 @@ static int cas_check_invariants(struct cas *cp)
34073408
/* finish phy determination. MDIO1 takes precedence over MDIO0 if
34083409
* they're both connected.
34093410
*/
3410-
cp->phy_type = cas_get_vpd_info(cp, cp->dev->dev_addr,
3411-
PCI_SLOT(pdev->devfn));
3411+
cp->phy_type = cas_get_vpd_info(cp, addr, PCI_SLOT(pdev->devfn));
3412+
eth_hw_addr_set(cp->dev, addr);
34123413
if (cp->phy_type & CAS_PHY_SERDES) {
34133414
cp->cas_flags |= CAS_FLAG_1000MB_CAP;
34143415
return 0; /* no more checking needed */

drivers/net/ethernet/sun/ldmvsw.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -230,18 +230,15 @@ static struct net_device *vsw_alloc_netdev(u8 hwaddr[],
230230
{
231231
struct net_device *dev;
232232
struct vnet_port *port;
233-
int i;
234233

235234
dev = alloc_etherdev_mqs(sizeof(*port), VNET_MAX_TXQS, 1);
236235
if (!dev)
237236
return ERR_PTR(-ENOMEM);
238237
dev->needed_headroom = VNET_PACKET_SKIP + 8;
239238
dev->needed_tailroom = 8;
240239

241-
for (i = 0; i < ETH_ALEN; i++) {
242-
dev->dev_addr[i] = hwaddr[i];
243-
dev->perm_addr[i] = dev->dev_addr[i];
244-
}
240+
eth_hw_addr_set(dev, hwaddr);
241+
ether_addr_copy(dev->perm_addr, dev->dev_addr)
245242

246243
sprintf(dev->name, "vif%d.%d", (int)handle, (int)port_id);
247244

drivers/net/ethernet/sun/niu.c

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2603,7 +2603,7 @@ static int niu_init_link(struct niu *np)
26032603
return 0;
26042604
}
26052605

2606-
static void niu_set_primary_mac(struct niu *np, unsigned char *addr)
2606+
static void niu_set_primary_mac(struct niu *np, const unsigned char *addr)
26072607
{
26082608
u16 reg0 = addr[4] << 8 | addr[5];
26092609
u16 reg1 = addr[2] << 8 | addr[3];
@@ -8312,6 +8312,7 @@ static void niu_pci_vpd_validate(struct niu *np)
83128312
{
83138313
struct net_device *dev = np->dev;
83148314
struct niu_vpd *vpd = &np->vpd;
8315+
u8 addr[ETH_ALEN];
83158316
u8 val8;
83168317

83178318
if (!is_valid_ether_addr(&vpd->local_mac[0])) {
@@ -8344,17 +8345,20 @@ static void niu_pci_vpd_validate(struct niu *np)
83448345
return;
83458346
}
83468347

8347-
eth_hw_addr_set(dev, vpd->local_mac);
8348+
ether_addr_copy(addr, vpd->local_mac);
83488349

8349-
val8 = dev->dev_addr[5];
8350-
dev->dev_addr[5] += np->port;
8351-
if (dev->dev_addr[5] < val8)
8352-
dev->dev_addr[4]++;
8350+
val8 = addr[5];
8351+
addr[5] += np->port;
8352+
if (addr[5] < val8)
8353+
addr[4]++;
8354+
8355+
eth_hw_addr_set(dev, addr);
83538356
}
83548357

83558358
static int niu_pci_probe_sprom(struct niu *np)
83568359
{
83578360
struct net_device *dev = np->dev;
8361+
u8 addr[ETH_ALEN];
83588362
int len, i;
83598363
u64 val, sum;
83608364
u8 val8;
@@ -8446,27 +8450,29 @@ static int niu_pci_probe_sprom(struct niu *np)
84468450
val = nr64(ESPC_MAC_ADDR0);
84478451
netif_printk(np, probe, KERN_DEBUG, np->dev,
84488452
"SPROM: MAC_ADDR0[%08llx]\n", (unsigned long long)val);
8449-
dev->dev_addr[0] = (val >> 0) & 0xff;
8450-
dev->dev_addr[1] = (val >> 8) & 0xff;
8451-
dev->dev_addr[2] = (val >> 16) & 0xff;
8452-
dev->dev_addr[3] = (val >> 24) & 0xff;
8453+
addr[0] = (val >> 0) & 0xff;
8454+
addr[1] = (val >> 8) & 0xff;
8455+
addr[2] = (val >> 16) & 0xff;
8456+
addr[3] = (val >> 24) & 0xff;
84538457

84548458
val = nr64(ESPC_MAC_ADDR1);
84558459
netif_printk(np, probe, KERN_DEBUG, np->dev,
84568460
"SPROM: MAC_ADDR1[%08llx]\n", (unsigned long long)val);
8457-
dev->dev_addr[4] = (val >> 0) & 0xff;
8458-
dev->dev_addr[5] = (val >> 8) & 0xff;
8461+
addr[4] = (val >> 0) & 0xff;
8462+
addr[5] = (val >> 8) & 0xff;
84598463

8460-
if (!is_valid_ether_addr(&dev->dev_addr[0])) {
8464+
if (!is_valid_ether_addr(addr)) {
84618465
dev_err(np->device, "SPROM MAC address invalid [ %pM ]\n",
8462-
dev->dev_addr);
8466+
addr);
84638467
return -EINVAL;
84648468
}
84658469

8466-
val8 = dev->dev_addr[5];
8467-
dev->dev_addr[5] += np->port;
8468-
if (dev->dev_addr[5] < val8)
8469-
dev->dev_addr[4]++;
8470+
val8 = addr[5];
8471+
addr[5] += np->port;
8472+
if (addr[5] < val8)
8473+
addr[4]++;
8474+
8475+
eth_hw_addr_set(dev, addr);
84708476

84718477
val = nr64(ESPC_MOD_STR_LEN);
84728478
netif_printk(np, probe, KERN_DEBUG, np->dev,

drivers/net/ethernet/sun/sungem.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1810,7 +1810,7 @@ static u32 gem_setup_multicast(struct gem *gp)
18101810

18111811
static void gem_init_mac(struct gem *gp)
18121812
{
1813-
unsigned char *e = &gp->dev->dev_addr[0];
1813+
const unsigned char *e = &gp->dev->dev_addr[0];
18141814

18151815
writel(0x1bf0, gp->regs + MAC_SNDPAUSE);
18161816

@@ -2087,7 +2087,7 @@ static void gem_stop_phy(struct gem *gp, int wol)
20872087
writel(mifcfg, gp->regs + MIF_CFG);
20882088

20892089
if (wol && gp->has_wol) {
2090-
unsigned char *e = &gp->dev->dev_addr[0];
2090+
const unsigned char *e = &gp->dev->dev_addr[0];
20912091
u32 csr;
20922092

20932093
/* Setup wake-on-lan for MAGIC packet */
@@ -2431,8 +2431,8 @@ static struct net_device_stats *gem_get_stats(struct net_device *dev)
24312431
static int gem_set_mac_address(struct net_device *dev, void *addr)
24322432
{
24332433
struct sockaddr *macaddr = (struct sockaddr *) addr;
2434+
const unsigned char *e = &dev->dev_addr[0];
24342435
struct gem *gp = netdev_priv(dev);
2435-
unsigned char *e = &dev->dev_addr[0];
24362436

24372437
if (!is_valid_ether_addr(macaddr->sa_data))
24382438
return -EADDRNOTAVAIL;
@@ -2799,7 +2799,10 @@ static int gem_get_device_address(struct gem *gp)
27992799
}
28002800
eth_hw_addr_set(dev, addr);
28012801
#else
2802-
get_gem_mac_nonobp(gp->pdev, gp->dev->dev_addr);
2802+
u8 addr[ETH_ALEN];
2803+
2804+
get_gem_mac_nonobp(gp->pdev, addr);
2805+
eth_hw_addr_set(gp->dev, addr);
28032806
#endif
28042807
return 0;
28052808
}

drivers/net/ethernet/sun/sunhme.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1395,13 +1395,13 @@ happy_meal_begin_auto_negotiation(struct happy_meal *hp,
13951395
/* hp->happy_lock must be held */
13961396
static int happy_meal_init(struct happy_meal *hp)
13971397
{
1398+
const unsigned char *e = &hp->dev->dev_addr[0];
13981399
void __iomem *gregs = hp->gregs;
13991400
void __iomem *etxregs = hp->etxregs;
14001401
void __iomem *erxregs = hp->erxregs;
14011402
void __iomem *bregs = hp->bigmacregs;
14021403
void __iomem *tregs = hp->tcvregs;
14031404
u32 regtmp, rxcfg;
1404-
unsigned char *e = &hp->dev->dev_addr[0];
14051405

14061406
/* If auto-negotiation timer is running, kill it. */
14071407
del_timer(&hp->happy_timer);
@@ -2661,6 +2661,7 @@ static int happy_meal_sbus_probe_one(struct platform_device *op, int is_qfe)
26612661
struct happy_meal *hp;
26622662
struct net_device *dev;
26632663
int i, qfe_slot = -1;
2664+
u8 addr[ETH_ALEN];
26642665
int err = -ENODEV;
26652666

26662667
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)
26982699
}
26992700
if (i < 6) { /* a mac address was given */
27002701
for (i = 0; i < 6; i++)
2701-
dev->dev_addr[i] = macaddr[i];
2702+
addr[i] = macaddr[i];
2703+
eth_hw_addr_set(dev, addr);
27022704
macaddr[5]++;
27032705
} else {
27042706
const unsigned char *addr;
@@ -2969,6 +2971,7 @@ static int happy_meal_pci_probe(struct pci_dev *pdev,
29692971
unsigned long hpreg_res;
29702972
int i, qfe_slot = -1;
29712973
char prom_name[64];
2974+
u8 addr[ETH_ALEN];
29722975
int err;
29732976

29742977
/* Now make sure pci_dev cookie is there. */
@@ -3044,7 +3047,8 @@ static int happy_meal_pci_probe(struct pci_dev *pdev,
30443047
}
30453048
if (i < 6) { /* a mac address was given */
30463049
for (i = 0; i < 6; i++)
3047-
dev->dev_addr[i] = macaddr[i];
3050+
addr[i] = macaddr[i];
3051+
eth_hw_addr_set(dev, addr);
30483052
macaddr[5]++;
30493053
} else {
30503054
#ifdef CONFIG_SPARC
@@ -3060,7 +3064,10 @@ static int happy_meal_pci_probe(struct pci_dev *pdev,
30603064
eth_hw_addr_set(dev, idprom->id_ethaddr);
30613065
}
30623066
#else
3063-
get_hme_mac_nonsparc(pdev, &dev->dev_addr[0]);
3067+
u8 addr[ETH_ALEN];
3068+
3069+
get_hme_mac_nonsparc(pdev, addr);
3070+
eth_hw_addr_set(dev, addr);
30643071
#endif
30653072
}
30663073

0 commit comments

Comments
 (0)