* [PATCH] nixge: fix mac address error handling again
@ 2021-11-22 15:02 Arnd Bergmann
2021-11-22 15:06 ` Arnd Bergmann
2021-11-22 15:10 ` patchwork-bot+netdevbpf
0 siblings, 2 replies; 3+ messages in thread
From: Arnd Bergmann @ 2021-11-22 15:02 UTC (permalink / raw)
To: David S. Miller, Jakub Kicinski, Moritz Fischer
Cc: Arnd Bergmann, Yang Yingliang, Yufeng Mo, Huazhong Tan,
Cai Huoqing, netdev, linux-kernel
From: Arnd Bergmann <arnd@arndb.de>
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: f3956ebb3bf0 ("ethernet: use eth_hw_addr_set() instead of ether_addr_copy()")
Fixes: abcd3d6fc640 ("net: nixge: Fix error path for obtaining mac address")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
drivers/net/ethernet/ni/nixge.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/net/ethernet/ni/nixge.c b/drivers/net/ethernet/ni/nixge.c
index cfeb7620ae20..07a00dd9cfe0 100644
--- a/drivers/net/ethernet/ni/nixge.c
+++ b/drivers/net/ethernet/ni/nixge.c
@@ -1209,7 +1209,7 @@ static void *nixge_get_nvmem_address(struct device *dev)
cell = nvmem_cell_get(dev, "address");
if (IS_ERR(cell))
- return NULL;
+ return cell;
mac = nvmem_cell_read(cell, &cell_size);
nvmem_cell_put(cell);
@@ -1282,7 +1282,7 @@ static int nixge_probe(struct platform_device *pdev)
ndev->max_mtu = NIXGE_JUMBO_MTU;
mac_addr = nixge_get_nvmem_address(&pdev->dev);
- if (mac_addr && is_valid_ether_addr(mac_addr)) {
+ if (!IS_ERR(mac_addr) && is_valid_ether_addr(mac_addr)) {
eth_hw_addr_set(ndev, mac_addr);
kfree(mac_addr);
} else {
--
2.29.2
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] nixge: fix mac address error handling again
2021-11-22 15:02 [PATCH] nixge: fix mac address error handling again Arnd Bergmann
@ 2021-11-22 15:06 ` Arnd Bergmann
2021-11-22 15:10 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: Arnd Bergmann @ 2021-11-22 15:06 UTC (permalink / raw)
To: David S. Miller, Jakub Kicinski, Moritz Fischer
Cc: Arnd Bergmann, Yang Yingliang, Yufeng Mo, Huazhong Tan,
Cai Huoqing, Networking, Linux Kernel Mailing List
On Mon, Nov 22, 2021 at 4:02 PM Arnd Bergmann <arnd@kernel.org> wrote:
>
> From: Arnd Bergmann <arnd@arndb.de>
>
> 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: f3956ebb3bf0 ("ethernet: use eth_hw_addr_set() instead of ether_addr_copy()")
> Fixes: abcd3d6fc640 ("net: nixge: Fix error path for obtaining mac address")
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Sorry, I sent out the wrong patch, this version fixes the bug but not the
warning. v2 is the version I actually tested successfully.
Arnd
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] nixge: fix mac address error handling again
2021-11-22 15:02 [PATCH] nixge: fix mac address error handling again Arnd Bergmann
2021-11-22 15:06 ` Arnd Bergmann
@ 2021-11-22 15:10 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2021-11-22 15:10 UTC (permalink / raw)
To: Arnd Bergmann
Cc: davem, kuba, mdf, arnd, yangyingliang, moyufeng, tanhuazhong,
caihuoqing, netdev, linux-kernel
Hello:
This patch was applied to netdev/net.git (master)
by David S. Miller <davem@davemloft.net>:
On Mon, 22 Nov 2021 16:02:49 +0100 you wrote:
> From: Arnd Bergmann <arnd@arndb.de>
>
> 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);
> | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> [...]
Here is the summary with links:
- nixge: fix mac address error handling again
https://git.kernel.org/netdev/net/c/a68229ca6340
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-11-22 15:10 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-22 15:02 [PATCH] nixge: fix mac address error handling again Arnd Bergmann
2021-11-22 15:06 ` Arnd Bergmann
2021-11-22 15:10 ` patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).