Netdev List
 help / color / mirror / Atom feed
From: Eric Dumazet <eric.dumazet@gmail.com>
To: Jonas Bonn <jonas@southpole.se>
Cc: netdev@vger.kernel.org
Subject: Re: [PATCH 4/8] ethoc: prevent overflow of rx counter
Date: Wed, 24 Nov 2010 18:34:27 +0100	[thread overview]
Message-ID: <1290620067.3464.80.camel@edumazet-laptop> (raw)
In-Reply-To: <1290606058-26703-5-git-send-email-jonas@southpole.se>

Le mercredi 24 novembre 2010 à 14:40 +0100, Jonas Bonn a écrit :
> Rewind cur_rx to prevent it from overflowing.
> 
> Signed-off-by: Jonas Bonn <jonas@southpole.se>
> ---
>  drivers/net/ethoc.c |    3 +++
>  1 files changed, 3 insertions(+), 0 deletions(-)
> 
> diff --git a/drivers/net/ethoc.c b/drivers/net/ethoc.c
> index 53c03f2..7d1b5d8 100644
> --- a/drivers/net/ethoc.c
> +++ b/drivers/net/ethoc.c
> @@ -408,6 +408,9 @@ static int ethoc_rx(struct net_device *dev, int limit)
>  	struct ethoc *priv = netdev_priv(dev);
>  	int count;
>  
> +	/* Prevent overflow of priv->cur_rx by rewinding it */	
> +	priv->cur_rx = priv->cur_rx % priv->num_rx;
> +
>  	for (count = 0; count < limit; ++count) {
>  		unsigned int entry;
>  		struct ethoc_bd bd;


Hmm... please try following code instead (no divides)

diff --git a/drivers/net/ethoc.c b/drivers/net/ethoc.c
index c5a2fe0..591b698 100644
--- a/drivers/net/ethoc.c
+++ b/drivers/net/ethoc.c
@@ -413,7 +413,7 @@ static int ethoc_rx(struct net_device *dev, int limit)
 		unsigned int entry;
 		struct ethoc_bd bd;
 
-		entry = priv->num_tx + (priv->cur_rx % priv->num_rx);
+		entry = priv->num_tx + priv->cur_rx;
 		ethoc_read_bd(priv, entry, &bd);
 		if (bd.stat & RX_BD_EMPTY)
 			break;
@@ -446,7 +446,8 @@ static int ethoc_rx(struct net_device *dev, int limit)
 		bd.stat &= ~RX_BD_STATS;
 		bd.stat |=  RX_BD_EMPTY;
 		ethoc_write_bd(priv, entry, &bd);
-		priv->cur_rx++;
+		if (++priv->cur_rx == priv->num_rx)
+			priv->cur_rx = 0;
 	}
 
 	return count;



  parent reply	other threads:[~2010-11-24 17:34 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-11-24 13:40 ethoc driver updates Jonas Bonn
2010-11-24 13:40 ` [PATCH 1/8] ethoc: Add device tree configuration Jonas Bonn
2010-11-24 19:35   ` David Miller
2010-11-24 13:40 ` [PATCH 2/8] ethoc: remove unused spinlock Jonas Bonn
2010-11-24 13:40 ` [PATCH 3/8] ethoc: enable interrupts after napi_complete Jonas Bonn
2010-11-24 18:45   ` Laurent Chavey
     [not found]   ` <AANLkTim=Y6NGk8MSq=hJTrBKaYuk4SJ_7wA=f+UBy3d0@mail.gmail.com>
2010-11-24 19:33     ` Laurent Chavey
2010-11-24 13:40 ` [PATCH 4/8] ethoc: prevent overflow of rx counter Jonas Bonn
2010-11-24 16:30   ` Ben Hutchings
2010-11-24 17:34   ` Eric Dumazet [this message]
2010-11-24 19:36   ` David Miller
2010-11-24 13:40 ` [PATCH 5/8] ethoc: Double check pending RX packet Jonas Bonn
2010-11-24 19:37   ` David Miller
2010-11-24 13:40 ` [PATCH 6/8] ethoc: rework interrupt handling Jonas Bonn
2010-11-24 19:38   ` David Miller
2010-11-24 13:40 ` [PATCH 7/8] ethoc: rework mdio read/write Jonas Bonn
2010-11-24 13:40 ` [PATCH 8/8] ethoc: fix function return type Jonas Bonn

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1290620067.3464.80.camel@edumazet-laptop \
    --to=eric.dumazet@gmail.com \
    --cc=jonas@southpole.se \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox