From: Arnd Bergmann <arnd@kernel.org>
To: "David S. Miller" <davem@davemloft.net>,
Jakub Kicinski <kuba@kernel.org>, Moritz Fischer <mdf@kernel.org>
Cc: Arnd Bergmann <arnd@arndb.de>,
Yang Yingliang <yangyingliang@huawei.com>,
Huazhong Tan <tanhuazhong@huawei.com>,
Yufeng Mo <moyufeng@huawei.com>,
Cai Huoqing <caihuoqing@baidu.com>,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] [v2] nixge: fix mac address error handling again
Date: Mon, 22 Nov 2021 16:07:44 +0100 [thread overview]
Message-ID: <20211122150754.4044081-1-arnd@kernel.org> (raw)
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 NULL on error for consistency,
this addresses the bug and the compiler warning.
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>
---
v2: return NULL consistently, rather than returning error pointer
---
drivers/net/ethernet/ni/nixge.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/net/ethernet/ni/nixge.c b/drivers/net/ethernet/ni/nixge.c
index cfeb7620ae20..9d8826ad84a6 100644
--- a/drivers/net/ethernet/ni/nixge.c
+++ b/drivers/net/ethernet/ni/nixge.c
@@ -1213,6 +1213,8 @@ static void *nixge_get_nvmem_address(struct device *dev)
mac = nvmem_cell_read(cell, &cell_size);
nvmem_cell_put(cell);
+ if (IS_ERR(mac))
+ return NULL;
return mac;
}
--
2.29.2
reply other threads:[~2021-11-22 15:08 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20211122150754.4044081-1-arnd@kernel.org \
--to=arnd@kernel.org \
--cc=arnd@arndb.de \
--cc=caihuoqing@baidu.com \
--cc=davem@davemloft.net \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mdf@kernel.org \
--cc=moyufeng@huawei.com \
--cc=netdev@vger.kernel.org \
--cc=tanhuazhong@huawei.com \
--cc=yangyingliang@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).