net: nixge: Fix error path for obtaining mac address
Subsystems (2)
PATCH 1/2 net: nixge: Fix error path for obtaining mac address
Fix issue where nixge_get_nvmem_address() returns a non-NULL return value on a failed nvmem_cell_get() that causes an invalid access when error value encoded in pointer is dereferenced.
Furthermore ensure that buffer allocated by nvmem_cell_read() actually gets kfreed() if the function succeeds.
Fixes commit 492caffa8a1a ("net: ethernet: nixge: Add support for National Instruments XGE netdev")
--- drivers/net/ethernet/ni/nixge.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/net/ethernet/ni/nixge.c +5 -3
@@ -1170,7 +1170,7 @@ static void *nixge_get_nvmem_address(struct device *dev) cell =nvmem_cell_get (dev,"address" );if (IS_ERR (cell)) -return cell; +return NULL ; mac =nvmem_cell_read (cell, &cell_size);nvmem_cell_put (cell);
@@ -1202,10 +1202,12 @@ 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 (mac_addr &&is_valid_ether_addr (mac_addr)) {ether_addr_copy (ndev->dev_addr, mac_addr); -else +kfree (mac_addr); + }else {eth_hw_addr_random (ndev); + } priv =netdev_priv (ndev); priv->ndev = ndev;
Signature · 1 line
2.17.0
PATCH 2/2 net: nixge: Address compiler warnings about signedness
Fixes the following warnings:
warning: pointer targets in passing argument 1 of ‘is_valid_ether_addr’ differ in signedness [-Wpointer-sign]
if (mac_addr && is_valid_ether_addr(mac_addr)) {
^~~~~~~~
expected ‘const u8 * {aka const unsigned char *}’ but argument
is of type ‘const char *’
static inline bool is_valid_ether_addr(const u8 *addr)
^~~~~~~~~~~~~~~~~~~
warning: pointer targets in passing argument 2 of
‘ether_addr_copy’ differ in signedness [-Wpointer-sign]
ether_addr_copy(ndev->dev_addr, mac_addr);
^~~~~~~~expected ‘const u8 * {aka const unsigned char *}’ but argument is of type ‘const char *’
static inline void ether_addr_copy(u8 *dst, const u8 *src)
--- drivers/net/ethernet/ni/nixge.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/ni/nixge.c +1 -1
@@ -1183,7 +1183,7 @@ static int nixge_probe(struct platform_device *pdev)struct nixge_priv *priv;struct net_device *ndev;struct resource *dmares; -const char *mac_addr; +const u8 *mac_addr;int err; ndev =alloc_etherdev (sizeof (*priv));
Signature · 1 line
2.17.0
Re: [PATCH 2/2] net: nixge: Address compiler warnings about signedness
From: Moritz Fischer <[email protected]>
Date: Fri, 4 May 2018 10:18:34 -0700
Quoted 13 lines
Fixes the following warnings:
warning: pointer targets in passing argument 1 of ‘is_valid_ether_addr’ differ in signedness [-Wpointer-sign]if (mac_addr && is_valid_ether_addr(mac_addr)) { ^~~~~~~~ expected ‘const u8 * {aka const unsigned char *}’ but argument is of type ‘const char *’ static inline bool is_valid_ether_addr(const u8 *addr) ^~~~~~~~~~~~~~~~~~~ warning: pointer targets in passing argument 2 of ‘ether_addr_copy’ differ in signedness [-Wpointer-sign] ether_addr_copy(ndev->dev_addr, mac_addr); ^~~~~~~~
Quoted 5 lines
expected ‘const u8 * {aka const unsigned char *}’ but argument is of type ‘const char *’
static inline voidether_addr_copy(u8 *dst, const u8 *src)Signed-off-by Moritz Fischer <[email protected]>
Applied.
From: Moritz Fischer <[email protected]>
Date: Fri, 4 May 2018 10:18:33 -0700
Quoted 11 lines
Fix issue where
nixge_get_nvmem_address()returns a non-NULL return value on a failednvmem_cell_get()that causes an invalid access when error value encoded in pointer is dereferenced.Furthermore ensure that buffer allocated by
nvmem_cell_read()actually getskfreed()if the function succeeds.Fixes commit
492caffa8a1a("net: ethernet: nixge: Add support for National Instruments XGE netdev")Reported-by Alex Williams <[email protected]>Signed-off-by Moritz Fischer <[email protected]>
Applied.