Skip to contentSkip to conversation

ethernet: fix some esoteric drivers after netdev->dev_addr constification

PATCH Superseded Jakub Kicinski 3 participants 8 messages Jan 25, 2022 – Jan 26, 2022

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Jakub Kicinski

author maintainer
#0 lore raw

cover ethernet: fix some esoteric drivers after netdev->dev_addr constification

Looking at recent fixes for drivers which don't get included with allmodconfig builds I thought it's worth grepping for more instances of:

dev->dev_addr\[.*\] =

This set contains the fixes.

Jakub Kicinski (3):
ethernet: 3com/typhoon: don't write directly to netdev->dev_addr
ethernet: tundra: don't write directly to netdev->dev_addr
ethernet: broadcom/sb1250-mac: don't write directly to

    netdev->dev_addr
 drivers/net/ethernet/3com/typhoon.c        |  6 ++--
 drivers/net/ethernet/broadcom/sb1250-mac.c |  4 +--
 drivers/net/ethernet/tundra/tsi108_eth.c   | 35 +++++++++++-----------
 3 files changed, 23 insertions(+), 22 deletions(-)
Signature · 1 line
2.34.1
author maintainer
#4 lore raw

PATCH 3/3 ethernet: broadcom/sb1250-mac: don't write directly to netdev->dev_addr

netdev->dev_addr is const now.

Compile tested bigsur_defconfig and sb1250_swarm_defconfig.

Fixes adeef3e32146 ("net: constify netdev->dev_addr")
---
 drivers/net/ethernet/broadcom/sb1250-mac.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/net/ethernet/broadcom/sb1250-mac.c +1 -3
index f38f40eb966e..a1a38456c9a3 100644
@@ -2183,9 +2183,7 @@ static int sbmac_init(struct platform_device *pldev, long long base)
 		ea_reg >>= 8;
 	}
 
-	for (i = 0; i < 6; i++) {
-		dev->dev_addr[i] = eaddr[i];
-	}
+	eth_hw_addr_set(dev, eaddr);
 
 	/*
 	 * Initialize context (get pointers to registers and stuff), then
Signature · 1 line
2.34.1
author maintainer
#1 lore raw

PATCH 1/3 ethernet: 3com/typhoon: don't write directly to netdev->dev_addr

In reply to Jakub Kicinski

This driver casts off the const and writes directly to netdev->dev_addr. This will result in a MAC address tree corruption and a warning.

Compile tested ppc6xx_defconfig.

Fixes adeef3e32146 ("net: constify netdev->dev_addr")
---
 drivers/net/ethernet/3com/typhoon.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/net/ethernet/3com/typhoon.c +4 -2
index 481f1df3106c..8aec5d9fbfef 100644
@@ -2278,6 +2278,7 @@ typhoon_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 	struct net_device *dev;
 	struct typhoon *tp;
 	int card_id = (int) ent->driver_data;
+	u8 addr[ETH_ALEN] __aligned(4);
 	void __iomem *ioaddr;
 	void *shared;
 	dma_addr_t shared_dma;
@@ -2409,8 +2410,9 @@ typhoon_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
 		goto error_out_reset;
 	}
 
-	*(__be16 *)&dev->dev_addr[0] = htons(le16_to_cpu(xp_resp[0].parm1));
-	*(__be32 *)&dev->dev_addr[2] = htonl(le32_to_cpu(xp_resp[0].parm2));
+	*(__be16 *)&addr[0] = htons(le16_to_cpu(xp_resp[0].parm1));
+	*(__be32 *)&addr[2] = htonl(le32_to_cpu(xp_resp[0].parm2));
+	eth_hw_addr_set(dev, addr);
 
 	if (!is_valid_ether_addr(dev->dev_addr)) {
 		err_msg = "Could not obtain valid ethernet address, aborting";
Signature · 1 line
2.34.1
author maintainer
#3 lore raw

PATCH 2/3 ethernet: tundra: don't write directly to netdev->dev_addr

In reply to Jakub Kicinski

netdev->dev_addr is const now.

Maintain the questionable offsetting in ndo_set_mac_address.

Compile tested holly_defconfig and mpc7448_hpc2_defconfig.

Fixes adeef3e32146 ("net: constify netdev->dev_addr")
---
 drivers/net/ethernet/tundra/tsi108_eth.c | 35 ++++++++++++------------
 1 file changed, 18 insertions(+), 17 deletions(-)
drivers/net/ethernet/tundra/tsi108_eth.c +18 -17
index cf0917b29e30..5251fc324221 100644
@@ -1091,20 +1091,22 @@ static int tsi108_get_mac(struct net_device *dev)
 	struct tsi108_prv_data *data = netdev_priv(dev);
 	u32 word1 = TSI_READ(TSI108_MAC_ADDR1);
 	u32 word2 = TSI_READ(TSI108_MAC_ADDR2);
+	u8 addr[ETH_ALEN];
 
 	/* Note that the octets are reversed from what the manual says,
 	 * producing an even weirder ordering...
 	 */
 	if (word2 == 0 && word1 == 0) {
-		dev->dev_addr[0] = 0x00;
-		dev->dev_addr[1] = 0x06;
-		dev->dev_addr[2] = 0xd2;
-		dev->dev_addr[3] = 0x00;
-		dev->dev_addr[4] = 0x00;
+		addr[0] = 0x00;
+		addr[1] = 0x06;
+		addr[2] = 0xd2;
+		addr[3] = 0x00;
+		addr[4] = 0x00;
 		if (0x8 == data->phy)
-			dev->dev_addr[5] = 0x01;
+			addr[5] = 0x01;
 		else
-			dev->dev_addr[5] = 0x02;
+			addr[5] = 0x02;
+		eth_hw_addr_set(dev, addr);
 
 		word2 = (dev->dev_addr[0] << 16) | (dev->dev_addr[1] << 24);
 
@@ -1114,12 +1116,13 @@ static int tsi108_get_mac(struct net_device *dev)
 		TSI_WRITE(TSI108_MAC_ADDR1, word1);
 		TSI_WRITE(TSI108_MAC_ADDR2, word2);
 	} else {
-		dev->dev_addr[0] = (word2 >> 16) & 0xff;
-		dev->dev_addr[1] = (word2 >> 24) & 0xff;
-		dev->dev_addr[2] = (word1 >> 0) & 0xff;
-		dev->dev_addr[3] = (word1 >> 8) & 0xff;
-		dev->dev_addr[4] = (word1 >> 16) & 0xff;
-		dev->dev_addr[5] = (word1 >> 24) & 0xff;
+		addr[0] = (word2 >> 16) & 0xff;
+		addr[1] = (word2 >> 24) & 0xff;
+		addr[2] = (word1 >> 0) & 0xff;
+		addr[3] = (word1 >> 8) & 0xff;
+		addr[4] = (word1 >> 16) & 0xff;
+		addr[5] = (word1 >> 24) & 0xff;
+		eth_hw_addr_set(dev, addr);
 	}
 
 	if (!is_valid_ether_addr(dev->dev_addr)) {
@@ -1136,14 +1139,12 @@ static int tsi108_set_mac(struct net_device *dev, void *addr)
 {
 	struct tsi108_prv_data *data = netdev_priv(dev);
 	u32 word1, word2;
-	int i;
 
 	if (!is_valid_ether_addr(addr))
 		return -EADDRNOTAVAIL;
 
-	for (i = 0; i < 6; i++)
-		/* +2 is for the offset of the HW addr type */
-		dev->dev_addr[i] = ((unsigned char *)addr)[i + 2];
+	/* +2 is for the offset of the HW addr type */
+	eth_hw_addr_set(dev, ((unsigned char *)addr) + 2);
 
 	word2 = (dev->dev_addr[0] << 16) | (dev->dev_addr[1] << 24);
 
Signature · 1 line
2.34.1
author maintainer
#5 lore raw
In reply to Jakub Kicinski
Quoted 6 lines · On Tue, 25 Jan 2022 14:23:14 -0800 Jakub Kicinski wrote:

Looking at recent fixes for drivers which don't get included with allmodconfig builds I thought it's worth grepping for more instances of:

dev->dev_addr\[.*\] =

This set contains the fixes.

Hi Arnd, there's another case in drivers/net/ethernet/i825xx/ether1.c which will be broken in 5.17, it looks like only RiscPC includes that. But when I do:

make ARCH=arm CROSS_COMPILE=$cross/arm-linux-gnueabi/bin/arm-linux-gnueabi- O=build_tmp/ rpc_defconfig

The resulting config is not for ARCH_RPC:

$ grep ARM_ETHER1 build_tmp/.config
$ grep RPC build_tmp/.config
# CONFIG_AF_RXRPC is not set
CONFIG_SUNRPC=y
# CONFIG_SUNRPC_DEBUG is not set
CONFIG_XZ_DEC_POWERPC=y
$ grep ACORN build_tmp/.config
# CONFIG_ACORN_PARTITION is not set
CONFIG_FONT_ACORN_8x8=y

Is there an extra smidgen of magic I need to produce a working config here? Is RPC dead and can we send it off to Valhalla?

#6 lore raw
Quoted 26 lines · Jakub Kicinski
Quoted 6 lines · On Tue, 25 Jan 2022 14:23:14 -0800 Jakub Kicinski wrote:

Looking at recent fixes for drivers which don't get included with allmodconfig builds I thought it's worth grepping for more instances of:

dev->dev_addr\[.*\] =

This set contains the fixes.

Hi Arnd, there's another case in drivers/net/ethernet/i825xx/ether1.c which will be broken in 5.17, it looks like only RiscPC includes that. But when I do:

make ARCH=arm CROSS_COMPILE=$cross/arm-linux-gnueabi/bin/arm-linux-gnueabi- O=build_tmp/ rpc_defconfig

The resulting config is not for ARCH_RPC:

$ grep ARM_ETHER1 build_tmp/.config
$ grep RPC build_tmp/.config
# CONFIG_AF_RXRPC is not set
CONFIG_SUNRPC=y
# CONFIG_SUNRPC_DEBUG is not set
CONFIG_XZ_DEC_POWERPC=y
$ grep ACORN build_tmp/.config
# CONFIG_ACORN_PARTITION is not set
CONFIG_FONT_ACORN_8x8=y
Quoted 2 lines

Is there an extra smidgen of magic I need to produce a working config here? Is RPC dead and can we send it off to Valhalla?

Support for ARMv3 was removed in gcc-9, so there is a Kconfig dependency on the compiler version to prevent broken builds. You can use the gcc-8 builds from kernel.org[1].

Russell still uses this machine with an older compiler though, and I guess he will keep using newer kernels for as long as gcc-8 can build them.

No idea which ethernet card he uses, there are at least three of them.

Arnd

[1] https://mirrors.edge.kernel.org/pub/tools/crosstool/files/bin/x86_64/8.5.0/x86_64-gcc-8.5.0-nolibc-arm-linux-gnueabi.tar.gz

author maintainer
#7 lore raw
Quoted 18 lines · On Wed, 26 Jan 2022 00:59:47 +0100 Arnd Bergmann wrote:
Quoted 18 lines

Hi Arnd, there's another case in drivers/net/ethernet/i825xx/ether1.c which will be broken in 5.17, it looks like only RiscPC includes that. But when I do:

make ARCH=arm CROSS_COMPILE=$cross/arm-linux-gnueabi/bin/arm-linux-gnueabi- O=build_tmp/ rpc_defconfig

The resulting config is not for ARCH_RPC:

$ grep ARM_ETHER1 build_tmp/.config
$ grep RPC build_tmp/.config
# CONFIG_AF_RXRPC is not set
CONFIG_SUNRPC=y
# CONFIG_SUNRPC_DEBUG is not set
CONFIG_XZ_DEC_POWERPC=y
$ grep ACORN build_tmp/.config
# CONFIG_ACORN_PARTITION is not set
CONFIG_FONT_ACORN_8x8=y
Quoted 6 lines
Quoted 2 lines

Is there an extra smidgen of magic I need to produce a working config here? Is RPC dead and can we send it off to Valhalla?

Support for ARMv3 was removed in gcc-9, so there is a Kconfig dependency on the compiler version to prevent broken builds. You can use the gcc-8 builds from kernel.org[1].

That worked! Thank you!

Quoted 7 lines

Russell still uses this machine with an older compiler though, and I guess he will keep using newer kernels for as long as gcc-8 can build them.

No idea which ethernet card he uses, there are at least three of them.

[1] https://mirrors.edge.kernel.org/pub/tools/crosstool/files/bin/x86_64/8.5.0/x86_64-gcc-8.5.0-nolibc-arm-linux-gnueabi.tar.gz

If there are 3 I broke the build for all of them, it seems :) I'll send the fixes shortly.

maintainer Acked-by on v1 1/3
#2 lore raw

Re: [PATCH net 1/3] ethernet: 3com/typhoon: don't write directly to netdev->dev_addr

In reply to Jakub Kicinski
Quoted 8 lines · Jakub Kicinski

This driver casts off the const and writes directly to netdev-

Quoted 1 line

dev_addr.

This will result in a MAC address tree corruption and a warning.

Compile tested ppc6xx_defconfig.

Fixes adeef3e32146 ("net: constify netdev->dev_addr")

Thanks!