Skip to content

Commit

Permalink
net: renesas: rswitch: Fix the output value of quote from rswitch_rx()
Browse files Browse the repository at this point in the history
[ Upstream commit e05bb97 ]

If the RX descriptor doesn't have any data, the output value of quote
from rswitch_rx() will be increased unexpectedily. So, fix it.

Reported-by: Volodymyr Babchuk <[email protected]>
Fixes: 3590918 ("net: ethernet: renesas: Add support for "Ethernet Switch"")
Signed-off-by: Yoshihiro Shimoda <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
Signed-off-by: Sasha Levin <[email protected]>
  • Loading branch information
shimoday authored and gregkh committed Mar 22, 2023
1 parent 79a971e commit 193aff3
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions drivers/net/ethernet/renesas/rswitch.c
Original file line number Diff line number Diff line change
Expand Up @@ -673,13 +673,14 @@ static bool rswitch_rx(struct net_device *ndev, int *quota)
u16 pkt_len;
u32 get_ts;

if (*quota <= 0)
return true;

boguscnt = min_t(int, gq->ring_size, *quota);
limit = boguscnt;

desc = &gq->rx_ring[gq->cur];
while ((desc->desc.die_dt & DT_MASK) != DT_FEMPTY) {
if (--boguscnt < 0)
break;
dma_rmb();
pkt_len = le16_to_cpu(desc->desc.info_ds) & RX_DS;
skb = gq->skbs[gq->cur];
Expand All @@ -705,6 +706,9 @@ static bool rswitch_rx(struct net_device *ndev, int *quota)

gq->cur = rswitch_next_queue_index(gq, true, 1);
desc = &gq->rx_ring[gq->cur];

if (--boguscnt <= 0)
break;
}

num = rswitch_get_num_cur_queues(gq);
Expand All @@ -716,7 +720,7 @@ static bool rswitch_rx(struct net_device *ndev, int *quota)
goto err;
gq->dirty = rswitch_next_queue_index(gq, false, num);

*quota -= limit - (++boguscnt);
*quota -= limit - boguscnt;

return boguscnt <= 0;

Expand Down

0 comments on commit 193aff3

Please sign in to comment.