Re: [PATCH V2 1/2] net: Fixup netif_attrmask_next_and warning

From: Guo Ren
Date: Fri Oct 14 2022 - 02:39:19 EST


On Fri, Oct 14, 2022 at 11:35 AM Jakub Kicinski <kuba@xxxxxxxxxx> wrote:
>
> On Thu, 13 Oct 2022 23:04:58 -0400 guoren@xxxxxxxxxx wrote:
> > - for (j = -1; j = netif_attrmask_next_and(j, online_mask, mask, nr_ids),
> > - j < nr_ids;) {
> > + for (j = -1; j < nr_ids;
> > + j = netif_attrmask_next_and(j, online_mask, mask, nr_ids)) {
>
> 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).

>
> Can we instead revert 854701ba4c and take the larger rework Yury
> has posted a week ago into net-next?



--
Best Regards
Guo Ren