diff mbox

[net-next,1/3] net: bcmgenet: cleanup for bcmgenet_xmit()

Message ID 1459815001-91703-1-git-send-email-pgynther@google.com
State Accepted, archived
Delegated to: David Miller
Headers show

Commit Message

Petri Gynther April 5, 2016, 12:09 a.m. UTC
1. Readability: Move nr_frags assignment a few lines down in order
   to bundle index -> ring -> txq calculations together.
2. Readability: Add parentheses around nr_frags + 1.
3. Minor fix: Stop the Tx queue and throw the error message only if
   the Tx queue hasn't already been stopped.

Signed-off-by: Petri Gynther <pgynther@google.com>
---
 drivers/net/ethernet/broadcom/genet/bcmgenet.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

Comments

Florian Fainelli April 5, 2016, 12:58 a.m. UTC | #1
2016-04-04 17:09 GMT-07:00 Petri Gynther <pgynther@google.com>:
> 1. Readability: Move nr_frags assignment a few lines down in order
>    to bundle index -> ring -> txq calculations together.
> 2. Readability: Add parentheses around nr_frags + 1.
> 3. Minor fix: Stop the Tx queue and throw the error message only if
>    the Tx queue hasn't already been stopped.
>
> Signed-off-by: Petri Gynther <pgynther@google.com>

Acked-by: Florian Fainelli <f.fainelli@gmail.com>
David Laight April 6, 2016, 8:57 a.m. UTC | #2
From: Petri Gynther
> Sent: 05 April 2016 01:10
...
> 2. Readability: Add parentheses around nr_frags + 1.
...
> -	if (ring->free_bds <= nr_frags + 1) {
...
> +	if (ring->free_bds <= (nr_frags + 1)) {

The extra () are not needed and do not improve readability.

	David
Petri Gynther April 6, 2016, 7:09 p.m. UTC | #3
On Wed, Apr 6, 2016 at 1:57 AM, David Laight <David.Laight@aculab.com> wrote:
> From: Petri Gynther
>> Sent: 05 April 2016 01:10
> ...
>> 2. Readability: Add parentheses around nr_frags + 1.
> ...
>> -     if (ring->free_bds <= nr_frags + 1) {
> ...
>> +     if (ring->free_bds <= (nr_frags + 1)) {
>
> The extra () are not needed and do not improve readability.
>
>         David
>

Not needed from C language point of view, but I personally like it
better that way.

Also, making it consistent with these:
bcmgenet.c:1227: if (ring->free_bds > (MAX_SKB_FRAGS + 1)) {
bcmgenet.c:1523: if (ring->free_bds <= (MAX_SKB_FRAGS + 1))
David Miller April 6, 2016, 8:09 p.m. UTC | #4
From: Petri Gynther <pgynther@google.com>
Date: Mon,  4 Apr 2016 17:09:59 -0700

> 1. Readability: Move nr_frags assignment a few lines down in order
>    to bundle index -> ring -> txq calculations together.
> 2. Readability: Add parentheses around nr_frags + 1.
> 3. Minor fix: Stop the Tx queue and throw the error message only if
>    the Tx queue hasn't already been stopped.
> 
> Signed-off-by: Petri Gynther <pgynther@google.com>

Applied.
diff mbox

Patch

diff --git a/drivers/net/ethernet/broadcom/genet/bcmgenet.c b/drivers/net/ethernet/broadcom/genet/bcmgenet.c
index cf6445d..7f85a84 100644
--- a/drivers/net/ethernet/broadcom/genet/bcmgenet.c
+++ b/drivers/net/ethernet/broadcom/genet/bcmgenet.c
@@ -1447,15 +1447,19 @@  static netdev_tx_t bcmgenet_xmit(struct sk_buff *skb, struct net_device *dev)
 	else
 		index -= 1;
 
-	nr_frags = skb_shinfo(skb)->nr_frags;
 	ring = &priv->tx_rings[index];
 	txq = netdev_get_tx_queue(dev, ring->queue);
 
+	nr_frags = skb_shinfo(skb)->nr_frags;
+
 	spin_lock_irqsave(&ring->lock, flags);
-	if (ring->free_bds <= nr_frags + 1) {
-		netif_tx_stop_queue(txq);
-		netdev_err(dev, "%s: tx ring %d full when queue %d awake\n",
-			   __func__, index, ring->queue);
+	if (ring->free_bds <= (nr_frags + 1)) {
+		if (!netif_tx_queue_stopped(txq)) {
+			netif_tx_stop_queue(txq);
+			netdev_err(dev,
+				   "%s: tx ring %d full when queue %d awake\n",
+				   __func__, index, ring->queue);
+		}
 		ret = NETDEV_TX_BUSY;
 		goto out;
 	}