netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] r8152: Use guard clause and fix comment typos
@ 2019-09-23 22:26 Prashant Malani
  2019-09-24  2:47 ` Hayes Wang
  2019-09-26  7:00 ` David Miller
  0 siblings, 2 replies; 5+ messages in thread
From: Prashant Malani @ 2019-09-23 22:26 UTC (permalink / raw)
  To: hayeswang; +Cc: grundler, netdev, nic_swsd, Prashant Malani

Use a guard clause in tx_bottom() to reduce the indentation of the
do-while loop. In doing so, convert the do-while to a while to make the
guard clause checks consistent.

Also, fix a couple of spelling and grammatical mistakes in the
r8152_csum_workaround() function comment.

Change-Id: I460befde150ad92248fd85b0f189ec2df2ab8431
Signed-off-by: Prashant Malani <pmalani@chromium.org>
Reviewed-by: Grant Grundler <grundler@chromium.org>
---
 drivers/net/usb/r8152.c | 36 ++++++++++++++++++------------------
 1 file changed, 18 insertions(+), 18 deletions(-)

diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c
index 08726090570e1..82bc69a5b24fb 100644
--- a/drivers/net/usb/r8152.c
+++ b/drivers/net/usb/r8152.c
@@ -1688,7 +1688,7 @@ static struct tx_agg *r8152_get_tx_agg(struct r8152 *tp)
 }
 
 /* r8152_csum_workaround()
- * The hw limites the value the transport offset. When the offset is out of the
+ * The hw limits the value of the transport offset. When the offset is out of
  * range, calculate the checksum by sw.
  */
 static void r8152_csum_workaround(struct r8152 *tp, struct sk_buff *skb,
@@ -2177,8 +2177,9 @@ static void tx_bottom(struct r8152 *tp)
 {
 	int res;
 
-	do {
+	while (1) {
 		struct tx_agg *agg;
+		struct net_device *netdev = tp->netdev;
 
 		if (skb_queue_empty(&tp->tx_queue))
 			break;
@@ -2188,26 +2189,25 @@ static void tx_bottom(struct r8152 *tp)
 			break;
 
 		res = r8152_tx_agg_fill(tp, agg);
-		if (res) {
-			struct net_device *netdev = tp->netdev;
+		if (!res)
+			break;
 
-			if (res == -ENODEV) {
-				rtl_set_unplug(tp);
-				netif_device_detach(netdev);
-			} else {
-				struct net_device_stats *stats = &netdev->stats;
-				unsigned long flags;
+		if (res == -ENODEV) {
+			rtl_set_unplug(tp);
+			netif_device_detach(netdev);
+		} else {
+			struct net_device_stats *stats = &netdev->stats;
+			unsigned long flags;
 
-				netif_warn(tp, tx_err, netdev,
-					   "failed tx_urb %d\n", res);
-				stats->tx_dropped += agg->skb_num;
+			netif_warn(tp, tx_err, netdev,
+				   "failed tx_urb %d\n", res);
+			stats->tx_dropped += agg->skb_num;
 
-				spin_lock_irqsave(&tp->tx_lock, flags);
-				list_add_tail(&agg->list, &tp->tx_free);
-				spin_unlock_irqrestore(&tp->tx_lock, flags);
-			}
+			spin_lock_irqsave(&tp->tx_lock, flags);
+			list_add_tail(&agg->list, &tp->tx_free);
+			spin_unlock_irqrestore(&tp->tx_lock, flags);
 		}
-	} while (res == 0);
+	}
 }
 
 static void bottom_half(unsigned long data)
-- 
2.23.0.351.gc4317032e6-goog


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

* RE: [PATCH] r8152: Use guard clause and fix comment typos
  2019-09-23 22:26 [PATCH] r8152: Use guard clause and fix comment typos Prashant Malani
@ 2019-09-24  2:47 ` Hayes Wang
  2019-09-24 23:47   ` Grant Grundler
  2019-09-26  7:00 ` David Miller
  1 sibling, 1 reply; 5+ messages in thread
From: Hayes Wang @ 2019-09-24  2:47 UTC (permalink / raw)
  To: Prashant Malani; +Cc: grundler, netdev, nic_swsd

Prashant Malani [mailto:pmalani@chromium.org]
> Sent: Tuesday, September 24, 2019 6:27 AM
> To: Hayes Wang
[...]
> -	do {
> +	while (1) {
>  		struct tx_agg *agg;
> +		struct net_device *netdev = tp->netdev;
> 
>  		if (skb_queue_empty(&tp->tx_queue))
>  			break;
> @@ -2188,26 +2189,25 @@ static void tx_bottom(struct r8152 *tp)
>  			break;
> 
>  		res = r8152_tx_agg_fill(tp, agg);
> -		if (res) {
> -			struct net_device *netdev = tp->netdev;
> +		if (!res)
> +			break;

I let the loop run continually until an error occurs or the queue is empty.
However, you stop the loop when r8152_tx_agg_fill() is successful.
If an error occurs continually, the loop may not be broken.

> -			if (res == -ENODEV) {
> -				rtl_set_unplug(tp);
> -				netif_device_detach(netdev);
> -			} else {
> -				struct net_device_stats *stats = &netdev->stats;
> -				unsigned long flags;
> +		if (res == -ENODEV) {
> +			rtl_set_unplug(tp);
> +			netif_device_detach(netdev);
> +		} else {
> +			struct net_device_stats *stats = &netdev->stats;
> +			unsigned long flags;
> 
> -				netif_warn(tp, tx_err, netdev,
> -					   "failed tx_urb %d\n", res);
> -				stats->tx_dropped += agg->skb_num;
> +			netif_warn(tp, tx_err, netdev,
> +				   "failed tx_urb %d\n", res);
> +			stats->tx_dropped += agg->skb_num;
> 
> -				spin_lock_irqsave(&tp->tx_lock, flags);
> -				list_add_tail(&agg->list, &tp->tx_free);
> -				spin_unlock_irqrestore(&tp->tx_lock, flags);
> -			}
> +			spin_lock_irqsave(&tp->tx_lock, flags);
> +			list_add_tail(&agg->list, &tp->tx_free);
> +			spin_unlock_irqrestore(&tp->tx_lock, flags);
>  		}
> -	} while (res == 0);
> +	}

I think the behavior is different from the current one.

Best Regards,
Hayes


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

* Re: [PATCH] r8152: Use guard clause and fix comment typos
  2019-09-24  2:47 ` Hayes Wang
@ 2019-09-24 23:47   ` Grant Grundler
  2019-09-25  0:28     ` Grant Grundler
  0 siblings, 1 reply; 5+ messages in thread
From: Grant Grundler @ 2019-09-24 23:47 UTC (permalink / raw)
  To: Hayes Wang; +Cc: Prashant Malani, grundler, netdev, nic_swsd

On Mon, Sep 23, 2019 at 7:47 PM Hayes Wang <hayeswang@realtek.com> wrote:
>
> Prashant Malani [mailto:pmalani@chromium.org]
> > Sent: Tuesday, September 24, 2019 6:27 AM
> > To: Hayes Wang
> [...]
> > -     do {
> > +     while (1) {
> >               struct tx_agg *agg;
> > +             struct net_device *netdev = tp->netdev;
> >
> >               if (skb_queue_empty(&tp->tx_queue))
> >                       break;
> > @@ -2188,26 +2189,25 @@ static void tx_bottom(struct r8152 *tp)
> >                       break;
> >
> >               res = r8152_tx_agg_fill(tp, agg);
> > -             if (res) {
> > -                     struct net_device *netdev = tp->netdev;
> > +             if (!res)
> > +                     break;
>
> I let the loop run continually until an error occurs or the queue is empty.
> However, you stop the loop when r8152_tx_agg_fill() is successful.

Hayes,
Are you sure about both assertions?
The do/while loop exits if "res == 0". Isn't that the same as "!res"?

> If an error occurs continually, the loop may not be broken.

And what prevents that from happening with the current code?

Should current code break out of the loop in -ENODEV case, right?

That would be more obvious if the code inside the loop were:
    ...
    res = r8152_tx_agg_fill(tp, agg);
    if (res == -ENODEV) {
       ...
       break;
     }
     if (!res)
         break;
    ...

(Or whatever the right code is to "loop until an error occurs or queue
is empty").

cheers,
grant

>
> > -                     if (res == -ENODEV) {
> > -                             rtl_set_unplug(tp);
> > -                             netif_device_detach(netdev);
> > -                     } else {
> > -                             struct net_device_stats *stats = &netdev->stats;
> > -                             unsigned long flags;
> > +             if (res == -ENODEV) {
> > +                     rtl_set_unplug(tp);
> > +                     netif_device_detach(netdev);
> > +             } else {
> > +                     struct net_device_stats *stats = &netdev->stats;
> > +                     unsigned long flags;
> >
> > -                             netif_warn(tp, tx_err, netdev,
> > -                                        "failed tx_urb %d\n", res);
> > -                             stats->tx_dropped += agg->skb_num;
> > +                     netif_warn(tp, tx_err, netdev,
> > +                                "failed tx_urb %d\n", res);
> > +                     stats->tx_dropped += agg->skb_num;
> >
> > -                             spin_lock_irqsave(&tp->tx_lock, flags);
> > -                             list_add_tail(&agg->list, &tp->tx_free);
> > -                             spin_unlock_irqrestore(&tp->tx_lock, flags);
> > -                     }
> > +                     spin_lock_irqsave(&tp->tx_lock, flags);
> > +                     list_add_tail(&agg->list, &tp->tx_free);
> > +                     spin_unlock_irqrestore(&tp->tx_lock, flags);
> >               }
> > -     } while (res == 0);
> > +     }
>
> I think the behavior is different from the current one.
>
> Best Regards,
> Hayes
>

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

* Re: [PATCH] r8152: Use guard clause and fix comment typos
  2019-09-24 23:47   ` Grant Grundler
@ 2019-09-25  0:28     ` Grant Grundler
  0 siblings, 0 replies; 5+ messages in thread
From: Grant Grundler @ 2019-09-25  0:28 UTC (permalink / raw)
  To: Grant Grundler; +Cc: Hayes Wang, Prashant Malani, netdev, nic_swsd

On Tue, Sep 24, 2019 at 4:47 PM Grant Grundler <grundler@chromium.org> wrote:
>
> On Mon, Sep 23, 2019 at 7:47 PM Hayes Wang <hayeswang@realtek.com> wrote:
> >
> > Prashant Malani [mailto:pmalani@chromium.org]
> > > Sent: Tuesday, September 24, 2019 6:27 AM
> > > To: Hayes Wang
> > [...]
> > > -     do {
> > > +     while (1) {
> > >               struct tx_agg *agg;
> > > +             struct net_device *netdev = tp->netdev;
> > >
> > >               if (skb_queue_empty(&tp->tx_queue))
> > >                       break;
> > > @@ -2188,26 +2189,25 @@ static void tx_bottom(struct r8152 *tp)
> > >                       break;
> > >
> > >               res = r8152_tx_agg_fill(tp, agg);
> > > -             if (res) {
> > > -                     struct net_device *netdev = tp->netdev;
> > > +             if (!res)
> > > +                     break;
> >
> > I let the loop run continually until an error occurs or the queue is empty.
> > However, you stop the loop when r8152_tx_agg_fill() is successful.
>
> Hayes,
> Are you sure about both assertions?
> The do/while loop exits if "res == 0". Isn't that the same as "!res"?

Hayes,
Sorry, You are correct.

thanks,
grant

>
> > If an error occurs continually, the loop may not be broken.
>
> And what prevents that from happening with the current code?
>
> Should current code break out of the loop in -ENODEV case, right?
>
> That would be more obvious if the code inside the loop were:
>     ...
>     res = r8152_tx_agg_fill(tp, agg);
>     if (res == -ENODEV) {
>        ...
>        break;
>      }
>      if (!res)
>          break;
>     ...
>
> (Or whatever the right code is to "loop until an error occurs or queue
> is empty").
>
> cheers,
> grant
>
> >
> > > -                     if (res == -ENODEV) {
> > > -                             rtl_set_unplug(tp);
> > > -                             netif_device_detach(netdev);
> > > -                     } else {
> > > -                             struct net_device_stats *stats = &netdev->stats;
> > > -                             unsigned long flags;
> > > +             if (res == -ENODEV) {
> > > +                     rtl_set_unplug(tp);
> > > +                     netif_device_detach(netdev);
> > > +             } else {
> > > +                     struct net_device_stats *stats = &netdev->stats;
> > > +                     unsigned long flags;
> > >
> > > -                             netif_warn(tp, tx_err, netdev,
> > > -                                        "failed tx_urb %d\n", res);
> > > -                             stats->tx_dropped += agg->skb_num;
> > > +                     netif_warn(tp, tx_err, netdev,
> > > +                                "failed tx_urb %d\n", res);
> > > +                     stats->tx_dropped += agg->skb_num;
> > >
> > > -                             spin_lock_irqsave(&tp->tx_lock, flags);
> > > -                             list_add_tail(&agg->list, &tp->tx_free);
> > > -                             spin_unlock_irqrestore(&tp->tx_lock, flags);
> > > -                     }
> > > +                     spin_lock_irqsave(&tp->tx_lock, flags);
> > > +                     list_add_tail(&agg->list, &tp->tx_free);
> > > +                     spin_unlock_irqrestore(&tp->tx_lock, flags);
> > >               }
> > > -     } while (res == 0);
> > > +     }
> >
> > I think the behavior is different from the current one.
> >
> > Best Regards,
> > Hayes
> >

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

* Re: [PATCH] r8152: Use guard clause and fix comment typos
  2019-09-23 22:26 [PATCH] r8152: Use guard clause and fix comment typos Prashant Malani
  2019-09-24  2:47 ` Hayes Wang
@ 2019-09-26  7:00 ` David Miller
  1 sibling, 0 replies; 5+ messages in thread
From: David Miller @ 2019-09-26  7:00 UTC (permalink / raw)
  To: pmalani; +Cc: hayeswang, grundler, netdev, nic_swsd

From: Prashant Malani <pmalani@chromium.org>
Date: Mon, 23 Sep 2019 15:26:57 -0700

> Use a guard clause in tx_bottom() to reduce the indentation of the
> do-while loop. In doing so, convert the do-while to a while to make the
> guard clause checks consistent.
> 
> Also, fix a couple of spelling and grammatical mistakes in the
> r8152_csum_workaround() function comment.
> 
> Change-Id: I460befde150ad92248fd85b0f189ec2df2ab8431
> Signed-off-by: Prashant Malani <pmalani@chromium.org>
> Reviewed-by: Grant Grundler <grundler@chromium.org>

This is only approiate for net-next, so please resubmit this when the
net-next tree opens back up.

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

end of thread, other threads:[~2019-09-26  7:00 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-23 22:26 [PATCH] r8152: Use guard clause and fix comment typos Prashant Malani
2019-09-24  2:47 ` Hayes Wang
2019-09-24 23:47   ` Grant Grundler
2019-09-25  0:28     ` Grant Grundler
2019-09-26  7:00 ` David Miller

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