All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] net: nixge: Fix error path for obtaining mac address
@ 2018-05-04 17:18 Moritz Fischer
  2018-05-04 17:18 ` [PATCH 2/2] net: nixge: Address compiler warnings about signedness Moritz Fischer
  2018-05-08  3:30 ` [PATCH 1/2] net: nixge: Fix error path for obtaining mac address David Miller
  0 siblings, 2 replies; 4+ messages in thread
From: Moritz Fischer @ 2018-05-04 17:18 UTC (permalink / raw)
  To: linux-kernel; +Cc: netdev, davem, alex.williams, Moritz Fischer

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")
Reported-by: Alex Williams <alex.williams@ni.com>
Signed-off-by: Moritz Fischer <mdf@kernel.org>
---
 drivers/net/ethernet/ni/nixge.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/ni/nixge.c b/drivers/net/ethernet/ni/nixge.c
index 27364b7572fc..c41fea9253e3 100644
--- a/drivers/net/ethernet/ni/nixge.c
+++ b/drivers/net/ethernet/ni/nixge.c
@@ -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;
-- 
2.17.0

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/2] net: nixge: Address compiler warnings about signedness
  2018-05-04 17:18 [PATCH 1/2] net: nixge: Fix error path for obtaining mac address Moritz Fischer
@ 2018-05-04 17:18 ` Moritz Fischer
  2018-05-08  3:30   ` David Miller
  2018-05-08  3:30 ` [PATCH 1/2] net: nixge: Fix error path for obtaining mac address David Miller
  1 sibling, 1 reply; 4+ messages in thread
From: Moritz Fischer @ 2018-05-04 17:18 UTC (permalink / raw)
  To: linux-kernel; +Cc: netdev, davem, alex.williams, Moritz Fischer

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)

Signed-off-by: Moritz Fischer <mdf@kernel.org>
---
 drivers/net/ethernet/ni/nixge.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/ni/nixge.c b/drivers/net/ethernet/ni/nixge.c
index c41fea9253e3..b092894dd128 100644
--- a/drivers/net/ethernet/ni/nixge.c
+++ b/drivers/net/ethernet/ni/nixge.c
@@ -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));
-- 
2.17.0

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/2] net: nixge: Fix error path for obtaining mac address
  2018-05-04 17:18 [PATCH 1/2] net: nixge: Fix error path for obtaining mac address Moritz Fischer
  2018-05-04 17:18 ` [PATCH 2/2] net: nixge: Address compiler warnings about signedness Moritz Fischer
@ 2018-05-08  3:30 ` David Miller
  1 sibling, 0 replies; 4+ messages in thread
From: David Miller @ 2018-05-08  3:30 UTC (permalink / raw)
  To: mdf; +Cc: linux-kernel, netdev, alex.williams

From: Moritz Fischer <mdf@kernel.org>
Date: Fri,  4 May 2018 10:18:33 -0700

> 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")
> Reported-by: Alex Williams <alex.williams@ni.com>
> Signed-off-by: Moritz Fischer <mdf@kernel.org>

Applied.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 2/2] net: nixge: Address compiler warnings about signedness
  2018-05-04 17:18 ` [PATCH 2/2] net: nixge: Address compiler warnings about signedness Moritz Fischer
@ 2018-05-08  3:30   ` David Miller
  0 siblings, 0 replies; 4+ messages in thread
From: David Miller @ 2018-05-08  3:30 UTC (permalink / raw)
  To: mdf; +Cc: linux-kernel, netdev, alex.williams

From: Moritz Fischer <mdf@kernel.org>
Date: Fri,  4 May 2018 10:18:34 -0700

> 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)
> 
> Signed-off-by: Moritz Fischer <mdf@kernel.org>

Applied.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2018-05-08  3:30 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-05-04 17:18 [PATCH 1/2] net: nixge: Fix error path for obtaining mac address Moritz Fischer
2018-05-04 17:18 ` [PATCH 2/2] net: nixge: Address compiler warnings about signedness Moritz Fischer
2018-05-08  3:30   ` David Miller
2018-05-08  3:30 ` [PATCH 1/2] net: nixge: Fix error path for obtaining mac address David Miller

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.