Skip to content

Commit a68229c

Browse files
arndbdavem330
authored andcommitted
nixge: fix mac address error handling again
The change to eth_hw_addr_set() caused gcc to correctly spot a bug that was introduced in an earlier incorrect fix: In file included from include/linux/etherdevice.h:21, from drivers/net/ethernet/ni/nixge.c:7: In function '__dev_addr_set', inlined from 'eth_hw_addr_set' at include/linux/etherdevice.h:319:2, inlined from 'nixge_probe' at drivers/net/ethernet/ni/nixge.c:1286:3: include/linux/netdevice.h:4648:9: error: 'memcpy' reading 6 bytes from a region of size 0 [-Werror=stringop-overread] 4648 | memcpy(dev->dev_addr, addr, len); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ As nixge_get_nvmem_address() can return either NULL or an error pointer, the NULL check is wrong, and we can end up reading from ERR_PTR(-EOPNOTSUPP), which gcc knows to contain zero readable bytes. Make the function always return an error pointer again but fix the check to match that. Fixes: f3956eb ("ethernet: use eth_hw_addr_set() instead of ether_addr_copy()") Fixes: abcd3d6 ("net: nixge: Fix error path for obtaining mac address") Signed-off-by: Arnd Bergmann <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 7a61432 commit a68229c

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

drivers/net/ethernet/ni/nixge.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1209,7 +1209,7 @@ static void *nixge_get_nvmem_address(struct device *dev)
12091209

12101210
cell = nvmem_cell_get(dev, "address");
12111211
if (IS_ERR(cell))
1212-
return NULL;
1212+
return cell;
12131213

12141214
mac = nvmem_cell_read(cell, &cell_size);
12151215
nvmem_cell_put(cell);
@@ -1282,7 +1282,7 @@ static int nixge_probe(struct platform_device *pdev)
12821282
ndev->max_mtu = NIXGE_JUMBO_MTU;
12831283

12841284
mac_addr = nixge_get_nvmem_address(&pdev->dev);
1285-
if (mac_addr && is_valid_ether_addr(mac_addr)) {
1285+
if (!IS_ERR(mac_addr) && is_valid_ether_addr(mac_addr)) {
12861286
eth_hw_addr_set(ndev, mac_addr);
12871287
kfree(mac_addr);
12881288
} else {

0 commit comments

Comments
 (0)