[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAJF2gTQtZOHgN7eJ-nhwF3RMUzJUC=ZjOnRzoR11Fso2b3z3gQ@mail.gmail.com>
Date: Sat, 15 Oct 2022 09:38:24 +0800
From: Guo Ren <guoren@...nel.org>
To: Jakub Kicinski <kuba@...nel.org>
Cc: andriy.shevchenko@...ux.intel.com, davem@...emloft.net,
edumazet@...gle.com, pabeni@...hat.com, linux@...musvillemoes.dk,
yury.norov@...il.com, caraitto@...gle.com, willemb@...gle.com,
jonolson@...gle.com, amritha.nambiar@...el.com,
linux-kernel@...r.kernel.org, netdev@...r.kernel.org,
Guo Ren <guoren@...ux.alibaba.com>
Subject: Re: [PATCH V2 1/2] net: Fixup netif_attrmask_next_and warning
On Fri, Oct 14, 2022 at 11:52 PM Jakub Kicinski <kuba@...nel.org> wrote:
>
> On Fri, 14 Oct 2022 14:38:56 +0800 Guo Ren wrote:
> > > This does not look equivalent, have you tested it?
> > >
> > > nr_ids is unsigned, doesn't it mean we'll never enter the loop?
> >
> > Yes, you are right. Any unsigned int would break the result.
> > (gdb) p (int)-1 < (int)2
> > $1 = 1
> > (gdb) p (int)-1 < (unsigned int)2
> > $2 = 0
> > (gdb) p (unsigned int)-1 < (int)2
> > $4 = 0
> >
> > So it should be:
> > - for (j = -1; j = netif_attrmask_next_and(j, online_mask, mask, nr_ids),
> > - j < nr_ids;) {
> > + for (j = -1; j < (int)nr_ids;
> > + j = netif_attrmask_next_and(j, online_mask, mask, nr_ids)) {
> >
> > Right? Of cause, nr_ids couldn't be 0xffffffff (-1).
>
> No. You can't enter the loop with -1 as the iterator either.
> Let's move on.
Oops, how about the below:
for (j = netif_attrmask_next_and(-1, online_mask, mask, nr_ids);
j < (int)nr_ids;
j = netif_attrmask_next_and(j, online_mask, mask, nr_ids)) {
--
Best Regards
Guo Ren
Powered by blists - more mailing lists