linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net v3 0/5] DPAA FMan driver fixes
@ 2020-08-03  7:07 Florinel Iordache
  2020-08-03  7:07 ` [PATCH net v3 1/5] fsl/fman: use 32-bit unsigned integer Florinel Iordache
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: Florinel Iordache @ 2020-08-03  7:07 UTC (permalink / raw)
  To: madalin.bucur, davem, kuba, netdev; +Cc: linux-kernel, Florinel Iordache

Here are several fixes for the DPAA FMan driver.

v2 changes:
* corrected patch 4 by removing the line added by mistake
* used longer fixes tags with the first 12 characters of the SHA-1 ID

v3 changes:
* remove the empty line inserted after fixes tag

Florinel Iordache (5):
  fsl/fman: use 32-bit unsigned integer
  fsl/fman: fix dereference null return value
  fsl/fman: fix unreachable code
  fsl/fman: check dereferencing null pointer
  fsl/fman: fix eth hash table allocation

 drivers/net/ethernet/freescale/fman/fman.c       | 3 +--
 drivers/net/ethernet/freescale/fman/fman_dtsec.c | 4 ++--
 drivers/net/ethernet/freescale/fman/fman_mac.h   | 2 +-
 drivers/net/ethernet/freescale/fman/fman_memac.c | 3 +--
 drivers/net/ethernet/freescale/fman/fman_port.c  | 9 ++++++++-
 drivers/net/ethernet/freescale/fman/fman_tgec.c  | 2 +-
 6 files changed, 14 insertions(+), 9 deletions(-)

-- 
1.9.1


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

* [PATCH net v3 1/5] fsl/fman: use 32-bit unsigned integer
  2020-08-03  7:07 [PATCH net v3 0/5] DPAA FMan driver fixes Florinel Iordache
@ 2020-08-03  7:07 ` Florinel Iordache
  2020-08-03  7:07 ` [PATCH net v3 2/5] fsl/fman: fix dereference null return value Florinel Iordache
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Florinel Iordache @ 2020-08-03  7:07 UTC (permalink / raw)
  To: madalin.bucur, davem, kuba, netdev; +Cc: linux-kernel, Florinel Iordache

Potentially overflowing expression (ts_freq << 16 and intgr << 16)
declared as type u32 (32-bit unsigned) is evaluated using 32-bit
arithmetic and then used in a context that expects an expression of
type u64 (64-bit unsigned) which ultimately is used as 16-bit
unsigned by typecasting to u16. Fixed by using an unsigned 32-bit
integer since the value is truncated anyway in the end.

Fixes: 414fd46e7762 ("fsl/fman: Add FMan support")
Signed-off-by: Florinel Iordache <florinel.iordache@nxp.com>
---
 drivers/net/ethernet/freescale/fman/fman.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/freescale/fman/fman.c b/drivers/net/ethernet/freescale/fman/fman.c
index f151d6e..ef67e85 100644
--- a/drivers/net/ethernet/freescale/fman/fman.c
+++ b/drivers/net/ethernet/freescale/fman/fman.c
@@ -1398,8 +1398,7 @@ static void enable_time_stamp(struct fman *fman)
 {
 	struct fman_fpm_regs __iomem *fpm_rg = fman->fpm_regs;
 	u16 fm_clk_freq = fman->state->fm_clk_freq;
-	u32 tmp, intgr, ts_freq;
-	u64 frac;
+	u32 tmp, intgr, ts_freq, frac;
 
 	ts_freq = (u32)(1 << fman->state->count1_micro_bit);
 	/* configure timestamp so that bit 8 will count 1 microsecond
-- 
1.9.1


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

* [PATCH net v3 2/5] fsl/fman: fix dereference null return value
  2020-08-03  7:07 [PATCH net v3 0/5] DPAA FMan driver fixes Florinel Iordache
  2020-08-03  7:07 ` [PATCH net v3 1/5] fsl/fman: use 32-bit unsigned integer Florinel Iordache
@ 2020-08-03  7:07 ` Florinel Iordache
  2020-08-03  7:07 ` [PATCH net v3 3/5] fsl/fman: fix unreachable code Florinel Iordache
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Florinel Iordache @ 2020-08-03  7:07 UTC (permalink / raw)
  To: madalin.bucur, davem, kuba, netdev; +Cc: linux-kernel, Florinel Iordache

Check before using returned value to avoid dereferencing null pointer.

Fixes: 18a6c85fcc78 ("fsl/fman: Add FMan Port Support")
Signed-off-by: Florinel Iordache <florinel.iordache@nxp.com>
---
 drivers/net/ethernet/freescale/fman/fman_port.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/freescale/fman/fman_port.c b/drivers/net/ethernet/freescale/fman/fman_port.c
index 87b26f0..c27df15 100644
--- a/drivers/net/ethernet/freescale/fman/fman_port.c
+++ b/drivers/net/ethernet/freescale/fman/fman_port.c
@@ -1767,6 +1767,7 @@ static int fman_port_probe(struct platform_device *of_dev)
 	struct fman_port *port;
 	struct fman *fman;
 	struct device_node *fm_node, *port_node;
+	struct platform_device *fm_pdev;
 	struct resource res;
 	struct resource *dev_res;
 	u32 val;
@@ -1791,8 +1792,14 @@ static int fman_port_probe(struct platform_device *of_dev)
 		goto return_err;
 	}
 
-	fman = dev_get_drvdata(&of_find_device_by_node(fm_node)->dev);
+	fm_pdev = of_find_device_by_node(fm_node);
 	of_node_put(fm_node);
+	if (!fm_pdev) {
+		err = -EINVAL;
+		goto return_err;
+	}
+
+	fman = dev_get_drvdata(&fm_pdev->dev);
 	if (!fman) {
 		err = -EINVAL;
 		goto return_err;
-- 
1.9.1


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

* [PATCH net v3 3/5] fsl/fman: fix unreachable code
  2020-08-03  7:07 [PATCH net v3 0/5] DPAA FMan driver fixes Florinel Iordache
  2020-08-03  7:07 ` [PATCH net v3 1/5] fsl/fman: use 32-bit unsigned integer Florinel Iordache
  2020-08-03  7:07 ` [PATCH net v3 2/5] fsl/fman: fix dereference null return value Florinel Iordache
@ 2020-08-03  7:07 ` Florinel Iordache
  2020-08-03  7:07 ` [PATCH net v3 4/5] fsl/fman: check dereferencing null pointer Florinel Iordache
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Florinel Iordache @ 2020-08-03  7:07 UTC (permalink / raw)
  To: madalin.bucur, davem, kuba, netdev; +Cc: linux-kernel, Florinel Iordache

The parameter 'priority' is incorrectly forced to zero which ultimately
induces logically dead code in the subsequent lines.

Fixes: 57ba4c9b56d8 ("fsl/fman: Add FMan MAC support")
Signed-off-by: Florinel Iordache <florinel.iordache@nxp.com>
---
 drivers/net/ethernet/freescale/fman/fman_memac.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/drivers/net/ethernet/freescale/fman/fman_memac.c b/drivers/net/ethernet/freescale/fman/fman_memac.c
index a5500ed..bb02b37 100644
--- a/drivers/net/ethernet/freescale/fman/fman_memac.c
+++ b/drivers/net/ethernet/freescale/fman/fman_memac.c
@@ -852,7 +852,6 @@ int memac_set_tx_pause_frames(struct fman_mac *memac, u8 priority,
 
 	tmp = ioread32be(&regs->command_config);
 	tmp &= ~CMD_CFG_PFC_MODE;
-	priority = 0;
 
 	iowrite32be(tmp, &regs->command_config);
 
-- 
1.9.1


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

* [PATCH net v3 4/5] fsl/fman: check dereferencing null pointer
  2020-08-03  7:07 [PATCH net v3 0/5] DPAA FMan driver fixes Florinel Iordache
                   ` (2 preceding siblings ...)
  2020-08-03  7:07 ` [PATCH net v3 3/5] fsl/fman: fix unreachable code Florinel Iordache
@ 2020-08-03  7:07 ` Florinel Iordache
  2020-08-03  7:07 ` [PATCH net v3 5/5] fsl/fman: fix eth hash table allocation Florinel Iordache
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Florinel Iordache @ 2020-08-03  7:07 UTC (permalink / raw)
  To: madalin.bucur, davem, kuba, netdev; +Cc: linux-kernel, Florinel Iordache

Add a safe check to avoid dereferencing null pointer

Fixes: 57ba4c9b56d8 ("fsl/fman: Add FMan MAC support")
Signed-off-by: Florinel Iordache <florinel.iordache@nxp.com>
---
 drivers/net/ethernet/freescale/fman/fman_dtsec.c | 4 ++--
 drivers/net/ethernet/freescale/fman/fman_memac.c | 2 +-
 drivers/net/ethernet/freescale/fman/fman_tgec.c  | 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/net/ethernet/freescale/fman/fman_dtsec.c b/drivers/net/ethernet/freescale/fman/fman_dtsec.c
index 004c266..bce3c93 100644
--- a/drivers/net/ethernet/freescale/fman/fman_dtsec.c
+++ b/drivers/net/ethernet/freescale/fman/fman_dtsec.c
@@ -1200,7 +1200,7 @@ int dtsec_del_hash_mac_address(struct fman_mac *dtsec, enet_addr_t *eth_addr)
 		list_for_each(pos,
 			      &dtsec->multicast_addr_hash->lsts[bucket]) {
 			hash_entry = ETH_HASH_ENTRY_OBJ(pos);
-			if (hash_entry->addr == addr) {
+			if (hash_entry && hash_entry->addr == addr) {
 				list_del_init(&hash_entry->node);
 				kfree(hash_entry);
 				break;
@@ -1213,7 +1213,7 @@ int dtsec_del_hash_mac_address(struct fman_mac *dtsec, enet_addr_t *eth_addr)
 		list_for_each(pos,
 			      &dtsec->unicast_addr_hash->lsts[bucket]) {
 			hash_entry = ETH_HASH_ENTRY_OBJ(pos);
-			if (hash_entry->addr == addr) {
+			if (hash_entry && hash_entry->addr == addr) {
 				list_del_init(&hash_entry->node);
 				kfree(hash_entry);
 				break;
diff --git a/drivers/net/ethernet/freescale/fman/fman_memac.c b/drivers/net/ethernet/freescale/fman/fman_memac.c
index bb02b37..645764a 100644
--- a/drivers/net/ethernet/freescale/fman/fman_memac.c
+++ b/drivers/net/ethernet/freescale/fman/fman_memac.c
@@ -981,7 +981,7 @@ int memac_del_hash_mac_address(struct fman_mac *memac, enet_addr_t *eth_addr)
 
 	list_for_each(pos, &memac->multicast_addr_hash->lsts[hash]) {
 		hash_entry = ETH_HASH_ENTRY_OBJ(pos);
-		if (hash_entry->addr == addr) {
+		if (hash_entry && hash_entry->addr == addr) {
 			list_del_init(&hash_entry->node);
 			kfree(hash_entry);
 			break;
diff --git a/drivers/net/ethernet/freescale/fman/fman_tgec.c b/drivers/net/ethernet/freescale/fman/fman_tgec.c
index 8c7eb87..41946b1 100644
--- a/drivers/net/ethernet/freescale/fman/fman_tgec.c
+++ b/drivers/net/ethernet/freescale/fman/fman_tgec.c
@@ -626,7 +626,7 @@ int tgec_del_hash_mac_address(struct fman_mac *tgec, enet_addr_t *eth_addr)
 
 	list_for_each(pos, &tgec->multicast_addr_hash->lsts[hash]) {
 		hash_entry = ETH_HASH_ENTRY_OBJ(pos);
-		if (hash_entry->addr == addr) {
+		if (hash_entry && hash_entry->addr == addr) {
 			list_del_init(&hash_entry->node);
 			kfree(hash_entry);
 			break;
-- 
1.9.1


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

* [PATCH net v3 5/5] fsl/fman: fix eth hash table allocation
  2020-08-03  7:07 [PATCH net v3 0/5] DPAA FMan driver fixes Florinel Iordache
                   ` (3 preceding siblings ...)
  2020-08-03  7:07 ` [PATCH net v3 4/5] fsl/fman: check dereferencing null pointer Florinel Iordache
@ 2020-08-03  7:07 ` Florinel Iordache
  2020-08-03  8:26 ` [PATCH net v3 0/5] DPAA FMan driver fixes Madalin Bucur (OSS)
  2020-08-03 23:20 ` David Miller
  6 siblings, 0 replies; 8+ messages in thread
From: Florinel Iordache @ 2020-08-03  7:07 UTC (permalink / raw)
  To: madalin.bucur, davem, kuba, netdev; +Cc: linux-kernel, Florinel Iordache

Fix memory allocation for ethernet address hash table.
The code was wrongly allocating an array for eth hash table which
is incorrect because this is the main structure for eth hash table
(struct eth_hash_t) that contains inside a number of elements.

Fixes: 57ba4c9b56d8 ("fsl/fman: Add FMan MAC support")
Signed-off-by: Florinel Iordache <florinel.iordache@nxp.com>
---
 drivers/net/ethernet/freescale/fman/fman_mac.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/freescale/fman/fman_mac.h b/drivers/net/ethernet/freescale/fman/fman_mac.h
index dd6d052..19f327e 100644
--- a/drivers/net/ethernet/freescale/fman/fman_mac.h
+++ b/drivers/net/ethernet/freescale/fman/fman_mac.h
@@ -252,7 +252,7 @@ static inline struct eth_hash_t *alloc_hash_table(u16 size)
 	struct eth_hash_t *hash;
 
 	/* Allocate address hash table */
-	hash = kmalloc_array(size, sizeof(struct eth_hash_t *), GFP_KERNEL);
+	hash = kmalloc(sizeof(*hash), GFP_KERNEL);
 	if (!hash)
 		return NULL;
 
-- 
1.9.1


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

* RE: [PATCH net v3 0/5] DPAA FMan driver fixes
  2020-08-03  7:07 [PATCH net v3 0/5] DPAA FMan driver fixes Florinel Iordache
                   ` (4 preceding siblings ...)
  2020-08-03  7:07 ` [PATCH net v3 5/5] fsl/fman: fix eth hash table allocation Florinel Iordache
@ 2020-08-03  8:26 ` Madalin Bucur (OSS)
  2020-08-03 23:20 ` David Miller
  6 siblings, 0 replies; 8+ messages in thread
From: Madalin Bucur (OSS) @ 2020-08-03  8:26 UTC (permalink / raw)
  To: Florinel Iordache, davem, kuba, netdev; +Cc: linux-kernel

> -----Original Message-----
> From: netdev-owner@vger.kernel.org <netdev-owner@vger.kernel.org> On
> Behalf Of Florinel Iordache
> Sent: 03 August 2020 10:07
> To: Madalin Bucur <madalin.bucur@nxp.com>; davem@davemloft.net;
> kuba@kernel.org; netdev@vger.kernel.org
> Cc: linux-kernel@vger.kernel.org; Florinel Iordache
> <florinel.iordache@nxp.com>
> Subject: [PATCH net v3 0/5] DPAA FMan driver fixes
> 
> Here are several fixes for the DPAA FMan driver.
> 
> v2 changes:
> * corrected patch 4 by removing the line added by mistake
> * used longer fixes tags with the first 12 characters of the SHA-1 ID
> 
> v3 changes:
> * remove the empty line inserted after fixes tag
> 
> Florinel Iordache (5):
>   fsl/fman: use 32-bit unsigned integer
>   fsl/fman: fix dereference null return value
>   fsl/fman: fix unreachable code
>   fsl/fman: check dereferencing null pointer
>   fsl/fman: fix eth hash table allocation
> 
>  drivers/net/ethernet/freescale/fman/fman.c       | 3 +--
>  drivers/net/ethernet/freescale/fman/fman_dtsec.c | 4 ++--
>  drivers/net/ethernet/freescale/fman/fman_mac.h   | 2 +-
>  drivers/net/ethernet/freescale/fman/fman_memac.c | 3 +--
>  drivers/net/ethernet/freescale/fman/fman_port.c  | 9 ++++++++-
>  drivers/net/ethernet/freescale/fman/fman_tgec.c  | 2 +-
>  6 files changed, 14 insertions(+), 9 deletions(-)
> 
> --
> 1.9.1

For the series,

Acked-by: Madalin Bucur <madalin.bucur@oss.nxp.com>

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

* Re: [PATCH net v3 0/5] DPAA FMan driver fixes
  2020-08-03  7:07 [PATCH net v3 0/5] DPAA FMan driver fixes Florinel Iordache
                   ` (5 preceding siblings ...)
  2020-08-03  8:26 ` [PATCH net v3 0/5] DPAA FMan driver fixes Madalin Bucur (OSS)
@ 2020-08-03 23:20 ` David Miller
  6 siblings, 0 replies; 8+ messages in thread
From: David Miller @ 2020-08-03 23:20 UTC (permalink / raw)
  To: florinel.iordache; +Cc: madalin.bucur, kuba, netdev, linux-kernel

From: Florinel Iordache <florinel.iordache@nxp.com>
Date: Mon,  3 Aug 2020 10:07:29 +0300

> Here are several fixes for the DPAA FMan driver.
> 
> v2 changes:
> * corrected patch 4 by removing the line added by mistake
> * used longer fixes tags with the first 12 characters of the SHA-1 ID
> 
> v3 changes:
> * remove the empty line inserted after fixes tag

Series applied, thank you.

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

end of thread, other threads:[~2020-08-03 23:20 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-03  7:07 [PATCH net v3 0/5] DPAA FMan driver fixes Florinel Iordache
2020-08-03  7:07 ` [PATCH net v3 1/5] fsl/fman: use 32-bit unsigned integer Florinel Iordache
2020-08-03  7:07 ` [PATCH net v3 2/5] fsl/fman: fix dereference null return value Florinel Iordache
2020-08-03  7:07 ` [PATCH net v3 3/5] fsl/fman: fix unreachable code Florinel Iordache
2020-08-03  7:07 ` [PATCH net v3 4/5] fsl/fman: check dereferencing null pointer Florinel Iordache
2020-08-03  7:07 ` [PATCH net v3 5/5] fsl/fman: fix eth hash table allocation Florinel Iordache
2020-08-03  8:26 ` [PATCH net v3 0/5] DPAA FMan driver fixes Madalin Bucur (OSS)
2020-08-03 23:20 ` David Miller

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