Skip to contentSkip to conversation

net: nixge: Fix error path for obtaining mac address

PATCH Applied Moritz Fischer 2 participants 4 messages May 4, 2018 – May 8, 2018

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

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
index 27364b7572fc..c41fea9253e3 100644
@@ -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
#1 lore raw

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
index c41fea9253e3..b092894dd128 100644
@@ -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
maintainer Applied
#2 lore raw

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 void ether_addr_copy(u8 *dst, const u8 *src)

Applied.

maintainer Applied
#3 lore raw
In reply to Moritz Fischer

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 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")

Applied.