Skip to content

Commit 2b37367

Browse files
kuba-moodavem330
authored andcommitted
ethernet: forcedeth: remove direct netdev->dev_addr writes
forcedeth writes to dev_addr byte by byte, make it use a local buffer instead. Commit the changes with eth_hw_addr_set() at the end. Signed-off-by: Jakub Kicinski <kuba@kernel.org> Reviewed-by: Zhu Yanjun <zyjzyj2000@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent f12e658 commit 2b37367

File tree

1 file changed

+26
-23
lines changed

1 file changed

+26
-23
lines changed

drivers/net/ethernet/nvidia/forcedeth.c

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5711,6 +5711,7 @@ static int nv_probe(struct pci_dev *pci_dev, const struct pci_device_id *id)
57115711
u32 phystate_orig = 0, phystate;
57125712
int phyinitialized = 0;
57135713
static int printed_version;
5714+
u8 mac[ETH_ALEN];
57145715

57155716
if (!printed_version++)
57165717
pr_info("Reverse Engineered nForce ethernet driver. Version %s.\n",
@@ -5884,50 +5885,52 @@ static int nv_probe(struct pci_dev *pci_dev, const struct pci_device_id *id)
58845885
txreg = readl(base + NvRegTransmitPoll);
58855886
if (id->driver_data & DEV_HAS_CORRECT_MACADDR) {
58865887
/* mac address is already in correct order */
5887-
dev->dev_addr[0] = (np->orig_mac[0] >> 0) & 0xff;
5888-
dev->dev_addr[1] = (np->orig_mac[0] >> 8) & 0xff;
5889-
dev->dev_addr[2] = (np->orig_mac[0] >> 16) & 0xff;
5890-
dev->dev_addr[3] = (np->orig_mac[0] >> 24) & 0xff;
5891-
dev->dev_addr[4] = (np->orig_mac[1] >> 0) & 0xff;
5892-
dev->dev_addr[5] = (np->orig_mac[1] >> 8) & 0xff;
5888+
mac[0] = (np->orig_mac[0] >> 0) & 0xff;
5889+
mac[1] = (np->orig_mac[0] >> 8) & 0xff;
5890+
mac[2] = (np->orig_mac[0] >> 16) & 0xff;
5891+
mac[3] = (np->orig_mac[0] >> 24) & 0xff;
5892+
mac[4] = (np->orig_mac[1] >> 0) & 0xff;
5893+
mac[5] = (np->orig_mac[1] >> 8) & 0xff;
58935894
} else if (txreg & NVREG_TRANSMITPOLL_MAC_ADDR_REV) {
58945895
/* mac address is already in correct order */
5895-
dev->dev_addr[0] = (np->orig_mac[0] >> 0) & 0xff;
5896-
dev->dev_addr[1] = (np->orig_mac[0] >> 8) & 0xff;
5897-
dev->dev_addr[2] = (np->orig_mac[0] >> 16) & 0xff;
5898-
dev->dev_addr[3] = (np->orig_mac[0] >> 24) & 0xff;
5899-
dev->dev_addr[4] = (np->orig_mac[1] >> 0) & 0xff;
5900-
dev->dev_addr[5] = (np->orig_mac[1] >> 8) & 0xff;
5896+
mac[0] = (np->orig_mac[0] >> 0) & 0xff;
5897+
mac[1] = (np->orig_mac[0] >> 8) & 0xff;
5898+
mac[2] = (np->orig_mac[0] >> 16) & 0xff;
5899+
mac[3] = (np->orig_mac[0] >> 24) & 0xff;
5900+
mac[4] = (np->orig_mac[1] >> 0) & 0xff;
5901+
mac[5] = (np->orig_mac[1] >> 8) & 0xff;
59015902
/*
59025903
* Set orig mac address back to the reversed version.
59035904
* This flag will be cleared during low power transition.
59045905
* Therefore, we should always put back the reversed address.
59055906
*/
5906-
np->orig_mac[0] = (dev->dev_addr[5] << 0) + (dev->dev_addr[4] << 8) +
5907-
(dev->dev_addr[3] << 16) + (dev->dev_addr[2] << 24);
5908-
np->orig_mac[1] = (dev->dev_addr[1] << 0) + (dev->dev_addr[0] << 8);
5907+
np->orig_mac[0] = (mac[5] << 0) + (mac[4] << 8) +
5908+
(mac[3] << 16) + (mac[2] << 24);
5909+
np->orig_mac[1] = (mac[1] << 0) + (mac[0] << 8);
59095910
} else {
59105911
/* need to reverse mac address to correct order */
5911-
dev->dev_addr[0] = (np->orig_mac[1] >> 8) & 0xff;
5912-
dev->dev_addr[1] = (np->orig_mac[1] >> 0) & 0xff;
5913-
dev->dev_addr[2] = (np->orig_mac[0] >> 24) & 0xff;
5914-
dev->dev_addr[3] = (np->orig_mac[0] >> 16) & 0xff;
5915-
dev->dev_addr[4] = (np->orig_mac[0] >> 8) & 0xff;
5916-
dev->dev_addr[5] = (np->orig_mac[0] >> 0) & 0xff;
5912+
mac[0] = (np->orig_mac[1] >> 8) & 0xff;
5913+
mac[1] = (np->orig_mac[1] >> 0) & 0xff;
5914+
mac[2] = (np->orig_mac[0] >> 24) & 0xff;
5915+
mac[3] = (np->orig_mac[0] >> 16) & 0xff;
5916+
mac[4] = (np->orig_mac[0] >> 8) & 0xff;
5917+
mac[5] = (np->orig_mac[0] >> 0) & 0xff;
59175918
writel(txreg|NVREG_TRANSMITPOLL_MAC_ADDR_REV, base + NvRegTransmitPoll);
59185919
dev_dbg(&pci_dev->dev,
59195920
"%s: set workaround bit for reversed mac addr\n",
59205921
__func__);
59215922
}
59225923

5923-
if (!is_valid_ether_addr(dev->dev_addr)) {
5924+
if (is_valid_ether_addr(mac)) {
5925+
eth_hw_addr_set(dev, mac);
5926+
} else {
59245927
/*
59255928
* Bad mac address. At least one bios sets the mac address
59265929
* to 01:23:45:67:89:ab
59275930
*/
59285931
dev_err(&pci_dev->dev,
59295932
"Invalid MAC address detected: %pM - Please complain to your hardware vendor.\n",
5930-
dev->dev_addr);
5933+
mac);
59315934
eth_hw_addr_random(dev);
59325935
dev_err(&pci_dev->dev,
59335936
"Using random MAC address: %pM\n", dev->dev_addr);

0 commit comments

Comments
 (0)