Messages in this thread | | | From | Guo Ren <> | Date | Sat, 15 Oct 2022 09:38:24 +0800 | 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@kernel.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
| |