gve: fix the wrong AdminQ buffer queue index check
authorHaiyue Wang <haiyue.wang@intel.com>
Fri, 28 Jan 2022 10:47:14 +0000 (18:47 +0800)
committerDavid S. Miller <davem@davemloft.net>
Fri, 28 Jan 2022 15:07:56 +0000 (15:07 +0000)
commit1f84a9450d75e08af70d9e2f2d5e1c0ac0c881d2
treef029e8003b0e43efa873a5d8bcf65e4599b5a660
parent501c8f5e3901f0de3244137e72fb39611f77a77c
gve: fix the wrong AdminQ buffer queue index check

The 'tail' and 'head' are 'unsigned int' type free-running count, when
'head' is overflow, the 'int i (= tail) < u32 head' will be false:

Only '- loop 0: idx = 63' result is shown, so it needs to use 'int' type
to compare, it can handle the overflow correctly.

typedef uint32_t u32;

int main()
{
        u32 tail, head;
        int stail, shead;
        int i, loop;

        tail = 0xffffffff;
        head = 0x00000000;

        for (i = tail, loop = 0; i < head; i++) {
                unsigned int idx = i & 63;

                printf("+ loop %d: idx = %u\n", loop++, idx);
        }

        stail = tail;
        shead = head;
        for (i = stail, loop = 0; i < shead; i++) {
                unsigned int idx = i & 63;

                printf("- loop %d: idx = %u\n", loop++, idx);
        }

        return 0;
}

Fixes: 5cdad90de62c ("gve: Batch AQ commands for creating and destroying queues.")
Signed-off-by: Haiyue Wang <haiyue.wang@intel.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/google/gve/gve_adminq.c