linux-renesas-soc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] net: ethernet: renesas: rswitch: Fix endless loop in error paths
@ 2022-11-07  8:10 Yoshihiro Shimoda
  2022-11-09  2:00 ` patchwork-bot+netdevbpf
  0 siblings, 1 reply; 2+ messages in thread
From: Yoshihiro Shimoda @ 2022-11-07  8:10 UTC (permalink / raw)
  To: davem, edumazet, kuba, pabeni
  Cc: netdev, linux-renesas-soc, Yoshihiro Shimoda, coverity-bot

Coverity reported that the error path in rswitch_gwca_queue_alloc_skb()
has an issue to cause endless loop. So, fix the issue by changing
variables' types from u32 to int. After changed the types,
rswitch_tx_free() should use rswitch_get_num_cur_queues() to
calculate number of current queues.

Reported-by: coverity-bot <keescook+coverity-bot@chromium.org>
Addresses-Coverity-ID: 1527147 ("Control flow issues")
Fixes: 3590918b5d07 ("net: ethernet: renesas: Add support for "Ethernet Switch"")
Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
---
 drivers/net/ethernet/renesas/rswitch.c | 17 +++++++++--------
 drivers/net/ethernet/renesas/rswitch.h |  6 +++---
 2 files changed, 12 insertions(+), 11 deletions(-)

diff --git a/drivers/net/ethernet/renesas/rswitch.c b/drivers/net/ethernet/renesas/rswitch.c
index f0168fedfef9..3bd5e6239855 100644
--- a/drivers/net/ethernet/renesas/rswitch.c
+++ b/drivers/net/ethernet/renesas/rswitch.c
@@ -219,9 +219,9 @@ static void rswitch_ack_data_irq(struct rswitch_private *priv, int index)
 	iowrite32(BIT(index % 32), priv->addr + offs);
 }
 
-static u32 rswitch_next_queue_index(struct rswitch_gwca_queue *gq, bool cur, u32 num)
+static int rswitch_next_queue_index(struct rswitch_gwca_queue *gq, bool cur, int num)
 {
-	u32 index = cur ? gq->cur : gq->dirty;
+	int index = cur ? gq->cur : gq->dirty;
 
 	if (index + num >= gq->ring_size)
 		index = (index + num) % gq->ring_size;
@@ -231,7 +231,7 @@ static u32 rswitch_next_queue_index(struct rswitch_gwca_queue *gq, bool cur, u32
 	return index;
 }
 
-static u32 rswitch_get_num_cur_queues(struct rswitch_gwca_queue *gq)
+static int rswitch_get_num_cur_queues(struct rswitch_gwca_queue *gq)
 {
 	if (gq->cur >= gq->dirty)
 		return gq->cur - gq->dirty;
@@ -250,9 +250,9 @@ static bool rswitch_is_queue_rxed(struct rswitch_gwca_queue *gq)
 }
 
 static int rswitch_gwca_queue_alloc_skb(struct rswitch_gwca_queue *gq,
-					u32 start_index, u32 num)
+					int start_index, int num)
 {
-	u32 i, index;
+	int i, index;
 
 	for (i = 0; i < num; i++) {
 		index = (i + start_index) % gq->ring_size;
@@ -410,12 +410,12 @@ static int rswitch_gwca_queue_format(struct net_device *ndev,
 
 static int rswitch_gwca_queue_ts_fill(struct net_device *ndev,
 				      struct rswitch_gwca_queue *gq,
-				      u32 start_index, u32 num)
+				      int start_index, int num)
 {
 	struct rswitch_device *rdev = netdev_priv(ndev);
 	struct rswitch_ext_ts_desc *desc;
 	dma_addr_t dma_addr;
-	u32 i, index;
+	int i, index;
 
 	for (i = 0; i < num; i++) {
 		index = (i + start_index) % gq->ring_size;
@@ -736,7 +736,8 @@ static int rswitch_tx_free(struct net_device *ndev, bool free_txed_only)
 	int free_num = 0;
 	int size;
 
-	for (; gq->cur - gq->dirty > 0; gq->dirty = rswitch_next_queue_index(gq, false, 1)) {
+	for (; rswitch_get_num_cur_queues(gq) > 0;
+	     gq->dirty = rswitch_next_queue_index(gq, false, 1)) {
 		desc = &gq->ring[gq->dirty];
 		if (free_txed_only && (desc->desc.die_dt & DT_MASK) != DT_FEMPTY)
 			break;
diff --git a/drivers/net/ethernet/renesas/rswitch.h b/drivers/net/ethernet/renesas/rswitch.h
index 778177ec8d4f..edbdd1b98d3d 100644
--- a/drivers/net/ethernet/renesas/rswitch.h
+++ b/drivers/net/ethernet/renesas/rswitch.h
@@ -908,9 +908,9 @@ struct rswitch_gwca_queue {
 		struct rswitch_ext_ts_desc *ts_ring;
 	};
 	dma_addr_t ring_dma;
-	u32 ring_size;
-	u32 cur;
-	u32 dirty;
+	int ring_size;
+	int cur;
+	int dirty;
 	struct sk_buff **skbs;
 
 	struct net_device *ndev;	/* queue to ndev for irq */
-- 
2.25.1


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

* Re: [PATCH] net: ethernet: renesas: rswitch: Fix endless loop in error paths
  2022-11-07  8:10 [PATCH] net: ethernet: renesas: rswitch: Fix endless loop in error paths Yoshihiro Shimoda
@ 2022-11-09  2:00 ` patchwork-bot+netdevbpf
  0 siblings, 0 replies; 2+ messages in thread
From: patchwork-bot+netdevbpf @ 2022-11-09  2:00 UTC (permalink / raw)
  To: Yoshihiro Shimoda
  Cc: davem, edumazet, kuba, pabeni, netdev, linux-renesas-soc,
	keescook+coverity-bot

Hello:

This patch was applied to netdev/net-next.git (master)
by Jakub Kicinski <kuba@kernel.org>:

On Mon,  7 Nov 2022 17:10:21 +0900 you wrote:
> Coverity reported that the error path in rswitch_gwca_queue_alloc_skb()
> has an issue to cause endless loop. So, fix the issue by changing
> variables' types from u32 to int. After changed the types,
> rswitch_tx_free() should use rswitch_get_num_cur_queues() to
> calculate number of current queues.
> 
> Reported-by: coverity-bot <keescook+coverity-bot@chromium.org>
> Addresses-Coverity-ID: 1527147 ("Control flow issues")
> Fixes: 3590918b5d07 ("net: ethernet: renesas: Add support for "Ethernet Switch"")
> Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>
> 
> [...]

Here is the summary with links:
  - net: ethernet: renesas: rswitch: Fix endless loop in error paths
    https://git.kernel.org/netdev/net-next/c/380f9acdf747

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



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

end of thread, other threads:[~2022-11-09  2:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-07  8:10 [PATCH] net: ethernet: renesas: rswitch: Fix endless loop in error paths Yoshihiro Shimoda
2022-11-09  2:00 ` patchwork-bot+netdevbpf

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