netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Grant Grundler <grundler@chromium.org>
To: Hayes Wang <hayeswang@realtek.com>
Cc: Prashant Malani <pmalani@chromium.org>,
	"grundler@chromium.org" <grundler@chromium.org>,
	"netdev@vger.kernel.org" <netdev@vger.kernel.org>,
	nic_swsd <nic_swsd@realtek.com>
Subject: Re: [PATCH] r8152: Use guard clause and fix comment typos
Date: Tue, 24 Sep 2019 16:47:59 -0700	[thread overview]
Message-ID: <CANEJEGsN44m190YSw=NYozV72Dt3fuPohUwWEMH2XWWBGsCgBg@mail.gmail.com> (raw)
In-Reply-To: <0835B3720019904CB8F7AA43166CEEB2F18E1587@RTITMBSVM03.realtek.com.tw>

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
>

  reply	other threads:[~2019-09-24 23:49 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2019-09-25  0:28     ` Grant Grundler
2019-09-26  7:00 ` David Miller

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='CANEJEGsN44m190YSw=NYozV72Dt3fuPohUwWEMH2XWWBGsCgBg@mail.gmail.com' \
    --to=grundler@chromium.org \
    --cc=hayeswang@realtek.com \
    --cc=netdev@vger.kernel.org \
    --cc=nic_swsd@realtek.com \
    --cc=pmalani@chromium.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;
as well as URLs for NNTP newsgroup(s).