When searching for a free entry in either mlx4_register_vlan() or
mlx4_register_mac(), and there is no free entry, the loop terminates without
updating the local variable free thus causing out of array bounds access. Fix
this by adding a proper check outside the loop.
Signed-off-by: Eli Cohen <eli@mellanox.co.il>
Signed-off-by: David S. Miller <davem@davemloft.net>
                        goto out;
                }
        }
+
+       if (free < 0) {
+               err = -ENOMEM;
+               goto out;
+       }
+
        mlx4_dbg(dev, "Free MAC index is %d\n", free);
 
        if (table->total == table->max) {
                }
        }
 
+       if (free < 0) {
+               err = -ENOMEM;
+               goto out;
+       }
+
        if (table->total == table->max) {
                /* No free vlan entries */
                err = -ENOSPC;