Skip to content

Commit ca87931

Browse files
kuba-moodavem330
authored andcommitted
ethernet: tulip: remove direct netdev->dev_addr writes
Consify the casts of netdev->dev_addr. Convert pointless to eth_hw_addr_set() where possible. Use local buffers in a number of places. Signed-off-by: Jakub Kicinski <kuba@kernel.org> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent a04436b commit ca87931

File tree

6 files changed

+61
-50
lines changed

6 files changed

+61
-50
lines changed

drivers/net/ethernet/dec/tulip/de2104x.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -666,8 +666,8 @@ static void build_setup_frame_hash(u16 *setup_frm, struct net_device *dev)
666666
struct de_private *de = netdev_priv(dev);
667667
u16 hash_table[32];
668668
struct netdev_hw_addr *ha;
669+
const u16 *eaddrs;
669670
int i;
670-
u16 *eaddrs;
671671

672672
memset(hash_table, 0, sizeof(hash_table));
673673
__set_bit_le(255, hash_table); /* Broadcast entry */
@@ -685,7 +685,7 @@ static void build_setup_frame_hash(u16 *setup_frm, struct net_device *dev)
685685
setup_frm = &de->setup_frame[13*6];
686686

687687
/* Fill the final entry with our physical address. */
688-
eaddrs = (u16 *)dev->dev_addr;
688+
eaddrs = (const u16 *)dev->dev_addr;
689689
*setup_frm++ = eaddrs[0]; *setup_frm++ = eaddrs[0];
690690
*setup_frm++ = eaddrs[1]; *setup_frm++ = eaddrs[1];
691691
*setup_frm++ = eaddrs[2]; *setup_frm++ = eaddrs[2];
@@ -695,7 +695,7 @@ static void build_setup_frame_perfect(u16 *setup_frm, struct net_device *dev)
695695
{
696696
struct de_private *de = netdev_priv(dev);
697697
struct netdev_hw_addr *ha;
698-
u16 *eaddrs;
698+
const u16 *eaddrs;
699699

700700
/* We have <= 14 addresses so we can use the wonderful
701701
16 address perfect filtering of the Tulip. */
@@ -710,7 +710,7 @@ static void build_setup_frame_perfect(u16 *setup_frm, struct net_device *dev)
710710
setup_frm = &de->setup_frame[15*6];
711711

712712
/* Fill the final entry with our physical address. */
713-
eaddrs = (u16 *)dev->dev_addr;
713+
eaddrs = (const u16 *)dev->dev_addr;
714714
*setup_frm++ = eaddrs[0]; *setup_frm++ = eaddrs[0];
715715
*setup_frm++ = eaddrs[1]; *setup_frm++ = eaddrs[1];
716716
*setup_frm++ = eaddrs[2]; *setup_frm++ = eaddrs[2];
@@ -1713,6 +1713,7 @@ static const struct ethtool_ops de_ethtool_ops = {
17131713

17141714
static void de21040_get_mac_address(struct de_private *de)
17151715
{
1716+
u8 addr[ETH_ALEN];
17161717
unsigned i;
17171718

17181719
dw32 (ROMCmd, 0); /* Reset the pointer with a dummy write. */
@@ -1724,12 +1725,13 @@ static void de21040_get_mac_address(struct de_private *de)
17241725
value = dr32(ROMCmd);
17251726
rmb();
17261727
} while (value < 0 && --boguscnt > 0);
1727-
de->dev->dev_addr[i] = value;
1728+
addr[i] = value;
17281729
udelay(1);
17291730
if (boguscnt <= 0)
17301731
pr_warn("timeout reading 21040 MAC address byte %u\n",
17311732
i);
17321733
}
1734+
eth_hw_addr_set(de->dev, addr);
17331735
}
17341736

17351737
static void de21040_get_media_info(struct de_private *de)
@@ -1821,8 +1823,7 @@ static void de21041_get_srom_info(struct de_private *de)
18211823
#endif
18221824

18231825
/* store MAC address */
1824-
for (i = 0; i < 6; i ++)
1825-
de->dev->dev_addr[i] = ee_data[i + sa_offset];
1826+
eth_hw_addr_set(de->dev, &ee_data[i + sa_offset]);
18261827

18271828
/* get offset of controller 0 info leaf. ignore 2nd byte. */
18281829
ofs = ee_data[SROMC0InfoLeaf];

drivers/net/ethernet/dec/tulip/de4x5.c

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4031,6 +4031,7 @@ get_hw_addr(struct net_device *dev)
40314031
int broken, i, k, tmp, status = 0;
40324032
u_short j,chksum;
40334033
struct de4x5_private *lp = netdev_priv(dev);
4034+
u8 addr[ETH_ALEN];
40344035

40354036
broken = de4x5_bad_srom(lp);
40364037

@@ -4042,28 +4043,30 @@ get_hw_addr(struct net_device *dev)
40424043
if (lp->chipset == DC21040) {
40434044
while ((tmp = inl(DE4X5_APROM)) < 0);
40444045
k += (u_char) tmp;
4045-
dev->dev_addr[i++] = (u_char) tmp;
4046+
addr[i++] = (u_char) tmp;
40464047
while ((tmp = inl(DE4X5_APROM)) < 0);
40474048
k += (u_short) (tmp << 8);
4048-
dev->dev_addr[i++] = (u_char) tmp;
4049+
addr[i++] = (u_char) tmp;
40494050
} else if (!broken) {
4050-
dev->dev_addr[i] = (u_char) lp->srom.ieee_addr[i]; i++;
4051-
dev->dev_addr[i] = (u_char) lp->srom.ieee_addr[i]; i++;
4051+
addr[i] = (u_char) lp->srom.ieee_addr[i]; i++;
4052+
addr[i] = (u_char) lp->srom.ieee_addr[i]; i++;
40524053
} else if ((broken == SMC) || (broken == ACCTON)) {
4053-
dev->dev_addr[i] = *((u_char *)&lp->srom + i); i++;
4054-
dev->dev_addr[i] = *((u_char *)&lp->srom + i); i++;
4054+
addr[i] = *((u_char *)&lp->srom + i); i++;
4055+
addr[i] = *((u_char *)&lp->srom + i); i++;
40554056
}
40564057
} else {
40574058
k += (u_char) (tmp = inb(EISA_APROM));
4058-
dev->dev_addr[i++] = (u_char) tmp;
4059+
addr[i++] = (u_char) tmp;
40594060
k += (u_short) ((tmp = inb(EISA_APROM)) << 8);
4060-
dev->dev_addr[i++] = (u_char) tmp;
4061+
addr[i++] = (u_char) tmp;
40614062
}
40624063

40634064
if (k > 0xffff) k-=0xffff;
40644065
}
40654066
if (k == 0xffff) k=0;
40664067

4068+
eth_hw_addr_set(dev, addr);
4069+
40674070
if (lp->bus == PCI) {
40684071
if (lp->chipset == DC21040) {
40694072
while ((tmp = inl(DE4X5_APROM)) < 0);
@@ -4095,8 +4098,9 @@ get_hw_addr(struct net_device *dev)
40954098
int x = dev->dev_addr[i];
40964099
x = ((x & 0xf) << 4) + ((x & 0xf0) >> 4);
40974100
x = ((x & 0x33) << 2) + ((x & 0xcc) >> 2);
4098-
dev->dev_addr[i] = ((x & 0x55) << 1) + ((x & 0xaa) >> 1);
4101+
addr[i] = ((x & 0x55) << 1) + ((x & 0xaa) >> 1);
40994102
}
4103+
eth_hw_addr_set(dev, addr);
41004104
}
41014105
#endif /* CONFIG_PPC_PMAC */
41024106

@@ -4158,12 +4162,9 @@ test_bad_enet(struct net_device *dev, int status)
41584162
if ((tmp == 0) || (tmp == 0x5fa)) {
41594163
if ((lp->chipset == last.chipset) &&
41604164
(lp->bus_num == last.bus) && (lp->bus_num > 0)) {
4161-
for (i=0; i<ETH_ALEN; i++) dev->dev_addr[i] = last.addr[i];
4162-
for (i=ETH_ALEN-1; i>2; --i) {
4163-
dev->dev_addr[i] += 1;
4164-
if (dev->dev_addr[i] != 0) break;
4165-
}
4166-
for (i=0; i<ETH_ALEN; i++) last.addr[i] = dev->dev_addr[i];
4165+
eth_addr_inc(last.addr);
4166+
eth_hw_addr_set(dev, last.addr);
4167+
41674168
if (!an_exception(lp)) {
41684169
dev->irq = last.irq;
41694170
}
@@ -5391,9 +5392,7 @@ de4x5_siocdevprivate(struct net_device *dev, struct ifreq *rq, void __user *data
53915392
if (netif_queue_stopped(dev))
53925393
return -EBUSY;
53935394
netif_stop_queue(dev);
5394-
for (i=0; i<ETH_ALEN; i++) {
5395-
dev->dev_addr[i] = tmp.addr[i];
5396-
}
5395+
eth_hw_addr_set(dev, tmp.addr);
53975396
build_setup_frame(dev, PHYS_ADDR_ONLY);
53985397
/* Set up the descriptor and give ownership to the card */
53995398
load_packet(dev, lp->setup_frame, TD_IC | PERFECT_F | TD_SET |

drivers/net/ethernet/dec/tulip/dmfe.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -476,8 +476,7 @@ static int dmfe_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
476476
}
477477

478478
/* Set Node address */
479-
for (i = 0; i < 6; i++)
480-
dev->dev_addr[i] = db->srom[20 + i];
479+
eth_hw_addr_set(dev, &db->srom[20 + i]);
481480

482481
err = register_netdev (dev);
483482
if (err)
@@ -1436,9 +1435,9 @@ static void update_cr6(u32 cr6_data, void __iomem *ioaddr)
14361435

14371436
static void dm9132_id_table(struct net_device *dev)
14381437
{
1438+
const u16 *addrptr = (const u16 *)dev->dev_addr;
14391439
struct dmfe_board_info *db = netdev_priv(dev);
14401440
void __iomem *ioaddr = db->ioaddr + 0xc0;
1441-
u16 *addrptr = (u16 *)dev->dev_addr;
14421441
struct netdev_hw_addr *ha;
14431442
u16 i, hash_table[4];
14441443

@@ -1477,7 +1476,7 @@ static void send_filter_frame(struct net_device *dev)
14771476
struct dmfe_board_info *db = netdev_priv(dev);
14781477
struct netdev_hw_addr *ha;
14791478
struct tx_desc *txptr;
1480-
u16 * addrptr;
1479+
const u16 * addrptr;
14811480
u32 * suptr;
14821481
int i;
14831482

@@ -1487,7 +1486,7 @@ static void send_filter_frame(struct net_device *dev)
14871486
suptr = (u32 *) txptr->tx_buf_ptr;
14881487

14891488
/* Node address */
1490-
addrptr = (u16 *) dev->dev_addr;
1489+
addrptr = (const u16 *) dev->dev_addr;
14911490
*suptr++ = addrptr[0];
14921491
*suptr++ = addrptr[1];
14931492
*suptr++ = addrptr[2];

drivers/net/ethernet/dec/tulip/tulip_core.c

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ static void tulip_up(struct net_device *dev)
339339
}
340340
} else {
341341
/* This is set_rx_mode(), but without starting the transmitter. */
342-
u16 *eaddrs = (u16 *)dev->dev_addr;
342+
const u16 *eaddrs = (const u16 *)dev->dev_addr;
343343
u16 *setup_frm = &tp->setup_frame[15*6];
344344
dma_addr_t mapping;
345345

@@ -1001,8 +1001,8 @@ static void build_setup_frame_hash(u16 *setup_frm, struct net_device *dev)
10011001
struct tulip_private *tp = netdev_priv(dev);
10021002
u16 hash_table[32];
10031003
struct netdev_hw_addr *ha;
1004+
const u16 *eaddrs;
10041005
int i;
1005-
u16 *eaddrs;
10061006

10071007
memset(hash_table, 0, sizeof(hash_table));
10081008
__set_bit_le(255, hash_table); /* Broadcast entry */
@@ -1019,7 +1019,7 @@ static void build_setup_frame_hash(u16 *setup_frm, struct net_device *dev)
10191019
setup_frm = &tp->setup_frame[13*6];
10201020

10211021
/* Fill the final entry with our physical address. */
1022-
eaddrs = (u16 *)dev->dev_addr;
1022+
eaddrs = (const u16 *)dev->dev_addr;
10231023
*setup_frm++ = eaddrs[0]; *setup_frm++ = eaddrs[0];
10241024
*setup_frm++ = eaddrs[1]; *setup_frm++ = eaddrs[1];
10251025
*setup_frm++ = eaddrs[2]; *setup_frm++ = eaddrs[2];
@@ -1029,7 +1029,7 @@ static void build_setup_frame_perfect(u16 *setup_frm, struct net_device *dev)
10291029
{
10301030
struct tulip_private *tp = netdev_priv(dev);
10311031
struct netdev_hw_addr *ha;
1032-
u16 *eaddrs;
1032+
const u16 *eaddrs;
10331033

10341034
/* We have <= 14 addresses so we can use the wonderful
10351035
16 address perfect filtering of the Tulip. */
@@ -1044,7 +1044,7 @@ static void build_setup_frame_perfect(u16 *setup_frm, struct net_device *dev)
10441044
setup_frm = &tp->setup_frame[15*6];
10451045

10461046
/* Fill the final entry with our physical address. */
1047-
eaddrs = (u16 *)dev->dev_addr;
1047+
eaddrs = (const u16 *)dev->dev_addr;
10481048
*setup_frm++ = eaddrs[0]; *setup_frm++ = eaddrs[0];
10491049
*setup_frm++ = eaddrs[1]; *setup_frm++ = eaddrs[1];
10501050
*setup_frm++ = eaddrs[2]; *setup_frm++ = eaddrs[2];
@@ -1305,6 +1305,7 @@ static int tulip_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
13051305
int chip_idx = ent->driver_data;
13061306
const char *chip_name = tulip_tbl[chip_idx].chip_name;
13071307
unsigned int eeprom_missing = 0;
1308+
u8 addr[ETH_ALEN] __aligned(2);
13081309
unsigned int force_csr0 = 0;
13091310

13101311
board_idx++;
@@ -1506,13 +1507,15 @@ static int tulip_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
15061507
do {
15071508
value = ioread32(ioaddr + CSR9);
15081509
} while (value < 0 && --boguscnt > 0);
1509-
put_unaligned_le16(value, ((__le16 *)dev->dev_addr) + i);
1510+
put_unaligned_le16(value, ((__le16 *)addr) + i);
15101511
sum += value & 0xffff;
15111512
}
1513+
eth_hw_addr_set(dev, addr);
15121514
} else if (chip_idx == COMET) {
15131515
/* No need to read the EEPROM. */
1514-
put_unaligned_le32(ioread32(ioaddr + 0xA4), dev->dev_addr);
1515-
put_unaligned_le16(ioread32(ioaddr + 0xA8), dev->dev_addr + 4);
1516+
put_unaligned_le32(ioread32(ioaddr + 0xA4), addr);
1517+
put_unaligned_le16(ioread32(ioaddr + 0xA8), addr + 4);
1518+
eth_hw_addr_set(dev, addr);
15161519
for (i = 0; i < 6; i ++)
15171520
sum += dev->dev_addr[i];
15181521
} else {
@@ -1575,20 +1578,23 @@ static int tulip_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
15751578
#endif
15761579

15771580
for (i = 0; i < 6; i ++) {
1578-
dev->dev_addr[i] = ee_data[i + sa_offset];
1581+
addr[i] = ee_data[i + sa_offset];
15791582
sum += ee_data[i + sa_offset];
15801583
}
1584+
eth_hw_addr_set(dev, addr);
15811585
}
15821586
/* Lite-On boards have the address byte-swapped. */
15831587
if ((dev->dev_addr[0] == 0xA0 ||
15841588
dev->dev_addr[0] == 0xC0 ||
15851589
dev->dev_addr[0] == 0x02) &&
1586-
dev->dev_addr[1] == 0x00)
1590+
dev->dev_addr[1] == 0x00) {
15871591
for (i = 0; i < 6; i+=2) {
1588-
char tmp = dev->dev_addr[i];
1589-
dev->dev_addr[i] = dev->dev_addr[i+1];
1590-
dev->dev_addr[i+1] = tmp;
1592+
addr[i] = dev->dev_addr[i+1];
1593+
addr[i+1] = dev->dev_addr[i];
15911594
}
1595+
eth_hw_addr_set(dev, addr);
1596+
}
1597+
15921598
/* On the Zynx 315 Etherarray and other multiport boards only the
15931599
first Tulip has an EEPROM.
15941600
On Sparc systems the mac address is held in the OBP property
@@ -1604,8 +1610,9 @@ static int tulip_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
16041610
#endif
16051611
eeprom_missing = 1;
16061612
for (i = 0; i < 5; i++)
1607-
dev->dev_addr[i] = last_phys_addr[i];
1608-
dev->dev_addr[i] = last_phys_addr[i] + 1;
1613+
addr[i] = last_phys_addr[i];
1614+
addr[i] = last_phys_addr[i] + 1;
1615+
eth_hw_addr_set(dev, addr);
16091616
#if defined(CONFIG_SPARC)
16101617
addr = of_get_property(dp, "local-mac-address", &len);
16111618
if (addr && len == ETH_ALEN)

drivers/net/ethernet/dec/tulip/uli526x.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,7 @@ static int uli526x_init_one(struct pci_dev *pdev,
272272
struct uli526x_board_info *db; /* board information structure */
273273
struct net_device *dev;
274274
void __iomem *ioaddr;
275+
u8 addr[ETH_ALEN];
275276
int i, err;
276277

277278
ULI526X_DBUG(0, "uli526x_init_one()", 0);
@@ -379,7 +380,7 @@ static int uli526x_init_one(struct pci_dev *pdev,
379380
uw32(DCR13, 0x1b0); //Select ID Table access port
380381
//Read MAC address from CR14
381382
for (i = 0; i < 6; i++)
382-
dev->dev_addr[i] = ur32(DCR14);
383+
addr[i] = ur32(DCR14);
383384
//Read end
384385
uw32(DCR13, 0); //Clear CR13
385386
uw32(DCR0, 0); //Clear CR0
@@ -388,8 +389,10 @@ static int uli526x_init_one(struct pci_dev *pdev,
388389
else /*Exist SROM*/
389390
{
390391
for (i = 0; i < 6; i++)
391-
dev->dev_addr[i] = db->srom[20 + i];
392+
addr[i] = db->srom[20 + i];
392393
}
394+
eth_hw_addr_set(dev, addr);
395+
393396
err = register_netdev (dev);
394397
if (err)
395398
goto err_out_unmap;
@@ -1343,7 +1346,7 @@ static void send_filter_frame(struct net_device *dev, int mc_cnt)
13431346
void __iomem *ioaddr = db->ioaddr;
13441347
struct netdev_hw_addr *ha;
13451348
struct tx_desc *txptr;
1346-
u16 * addrptr;
1349+
const u16 * addrptr;
13471350
u32 * suptr;
13481351
int i;
13491352

@@ -1353,7 +1356,7 @@ static void send_filter_frame(struct net_device *dev, int mc_cnt)
13531356
suptr = (u32 *) txptr->tx_buf_ptr;
13541357

13551358
/* Node address */
1356-
addrptr = (u16 *) dev->dev_addr;
1359+
addrptr = (const u16 *) dev->dev_addr;
13571360
*suptr++ = addrptr[0] << FLT_SHIFT;
13581361
*suptr++ = addrptr[1] << FLT_SHIFT;
13591362
*suptr++ = addrptr[2] << FLT_SHIFT;

drivers/net/ethernet/dec/tulip/xircom_cb.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1015,12 +1015,14 @@ static void read_mac_address(struct xircom_private *card)
10151015
xw32(CSR10, i + 3);
10161016
data_count = xr32(CSR9);
10171017
if ((tuple == 0x22) && (data_id == 0x04) && (data_count == 0x06)) {
1018+
u8 addr[ETH_ALEN];
10181019
int j;
10191020

10201021
for (j = 0; j < 6; j++) {
10211022
xw32(CSR10, i + j + 4);
1022-
card->dev->dev_addr[j] = xr32(CSR9) & 0xff;
1023+
addr[j] = xr32(CSR9) & 0xff;
10231024
}
1025+
eth_hw_addr_set(card->dev, addr);
10241026
break;
10251027
} else if (link == 0) {
10261028
break;

0 commit comments

Comments
 (0)