Netdev Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH net v2 0/5] DPAA FMan driver fixes
@ 2020-07-31 10:49 Florinel Iordache
  2020-07-31 10:49 ` [PATCH net v2 1/5] fsl/fman: use 32-bit unsigned integer Florinel Iordache
                   ` (4 more replies)
  0 siblings, 5 replies; 7+ messages in thread
From: Florinel Iordache @ 2020-07-31 10:49 UTC (permalink / raw)
  To: madalin.bucur, davem, kuba, netdev, Markus.Elfring
  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

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] 7+ messages in thread

* [PATCH net v2 1/5] fsl/fman: use 32-bit unsigned integer
  2020-07-31 10:49 [PATCH net v2 0/5] DPAA FMan driver fixes Florinel Iordache
@ 2020-07-31 10:49 ` Florinel Iordache
  2020-07-31 10:49 ` [PATCH net v2 2/5] fsl/fman: fix dereference null return value Florinel Iordache
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 7+ messages in thread
From: Florinel Iordache @ 2020-07-31 10:49 UTC (permalink / raw)
  To: madalin.bucur, davem, kuba, netdev, Markus.Elfring
  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	[flat|nested] 7+ messages in thread

* [PATCH net v2 2/5] fsl/fman: fix dereference null return value
  2020-07-31 10:49 [PATCH net v2 0/5] DPAA FMan driver fixes Florinel Iordache
  2020-07-31 10:49 ` [PATCH net v2 1/5] fsl/fman: use 32-bit unsigned integer Florinel Iordache
@ 2020-07-31 10:49 ` Florinel Iordache
  2020-07-31 10:49 ` [PATCH net v2 3/5] fsl/fman: fix unreachable code Florinel Iordache
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 7+ messages in thread
From: Florinel Iordache @ 2020-07-31 10:49 UTC (permalink / raw)
  To: madalin.bucur, davem, kuba, netdev, Markus.Elfring
  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	[flat|nested] 7+ messages in thread

* [PATCH net v2 3/5] fsl/fman: fix unreachable code
  2020-07-31 10:49 [PATCH net v2 0/5] DPAA FMan driver fixes Florinel Iordache
  2020-07-31 10:49 ` [PATCH net v2 1/5] fsl/fman: use 32-bit unsigned integer Florinel Iordache
  2020-07-31 10:49 ` [PATCH net v2 2/5] fsl/fman: fix dereference null return value Florinel Iordache
@ 2020-07-31 10:49 ` Florinel Iordache
  2020-07-31 10:49 ` [PATCH net v2 4/5] fsl/fman: check dereferencing null pointer Florinel Iordache
  2020-07-31 10:49 ` [PATCH net v2 5/5] fsl/fman: fix eth hash table allocation Florinel Iordache
  4 siblings, 0 replies; 7+ messages in thread
From: Florinel Iordache @ 2020-07-31 10:49 UTC (permalink / raw)
  To: madalin.bucur, davem, kuba, netdev, Markus.Elfring
  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	[flat|nested] 7+ messages in thread

* [PATCH net v2 4/5] fsl/fman: check dereferencing null pointer
  2020-07-31 10:49 [PATCH net v2 0/5] DPAA FMan driver fixes Florinel Iordache
                   ` (2 preceding siblings ...)
  2020-07-31 10:49 ` [PATCH net v2 3/5] fsl/fman: fix unreachable code Florinel Iordache
@ 2020-07-31 10:49 ` Florinel Iordache
  2020-07-31 10:49 ` [PATCH net v2 5/5] fsl/fman: fix eth hash table allocation Florinel Iordache
  4 siblings, 0 replies; 7+ messages in thread
From: Florinel Iordache @ 2020-07-31 10:49 UTC (permalink / raw)
  To: madalin.bucur, davem, kuba, netdev, Markus.Elfring
  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	[flat|nested] 7+ messages in thread

* [PATCH net v2 5/5] fsl/fman: fix eth hash table allocation
  2020-07-31 10:49 [PATCH net v2 0/5] DPAA FMan driver fixes Florinel Iordache
                   ` (3 preceding siblings ...)
  2020-07-31 10:49 ` [PATCH net v2 4/5] fsl/fman: check dereferencing null pointer Florinel Iordache
@ 2020-07-31 10:49 ` Florinel Iordache
  2020-07-31 20:12   ` Jakub Kicinski
  4 siblings, 1 reply; 7+ messages in thread
From: Florinel Iordache @ 2020-07-31 10:49 UTC (permalink / raw)
  To: madalin.bucur, davem, kuba, netdev, Markus.Elfring
  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	[flat|nested] 7+ messages in thread

* Re: [PATCH net v2 5/5] fsl/fman: fix eth hash table allocation
  2020-07-31 10:49 ` [PATCH net v2 5/5] fsl/fman: fix eth hash table allocation Florinel Iordache
@ 2020-07-31 20:12   ` Jakub Kicinski
  0 siblings, 0 replies; 7+ messages in thread
From: Jakub Kicinski @ 2020-07-31 20:12 UTC (permalink / raw)
  To: Florinel Iordache
  Cc: madalin.bucur, davem, netdev, Markus.Elfring, linux-kernel

On Fri, 31 Jul 2020 13:49:22 +0300 Florinel Iordache wrote:
> Fixes: 57ba4c9b56d8 ("fsl/fman: Add FMan MAC support")
> 
> Signed-off-by: Florinel Iordache <florinel.iordache@nxp.com>

Please repost without the empty lines between these tags.

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

end of thread, back to index

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-31 10:49 [PATCH net v2 0/5] DPAA FMan driver fixes Florinel Iordache
2020-07-31 10:49 ` [PATCH net v2 1/5] fsl/fman: use 32-bit unsigned integer Florinel Iordache
2020-07-31 10:49 ` [PATCH net v2 2/5] fsl/fman: fix dereference null return value Florinel Iordache
2020-07-31 10:49 ` [PATCH net v2 3/5] fsl/fman: fix unreachable code Florinel Iordache
2020-07-31 10:49 ` [PATCH net v2 4/5] fsl/fman: check dereferencing null pointer Florinel Iordache
2020-07-31 10:49 ` [PATCH net v2 5/5] fsl/fman: fix eth hash table allocation Florinel Iordache
2020-07-31 20:12   ` Jakub Kicinski

Netdev Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/netdev/0 netdev/git/0.git
	git clone --mirror https://lore.kernel.org/netdev/1 netdev/git/1.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 netdev netdev/ https://lore.kernel.org/netdev \
		netdev@vger.kernel.org
	public-inbox-index netdev

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.netdev


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git