]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
mlx4: Fix vlan table overflow
authorJoe Jin <joe.jin@oracle.com>
Thu, 15 Dec 2011 01:34:37 +0000 (09:34 +0800)
committerJoe Jin <joe.jin@oracle.com>
Thu, 15 Dec 2011 01:34:37 +0000 (09:34 +0800)
commit e72ebf5a578464204c8418d7d9b375333bb33161
Author: Yevgeny Petrilin <yevgenyp@mellanox.co.il>
Date:   Tue Oct 18 01:50:29 2011 +0000

    mlx4: Fix vlan table overflow

    Prevent overflow when trying to register more Vlans then the Vlan table in
    HW is configured to.
    Need to take into acount that the first 2 entries are reserved.

Signed-off-by: Yevgeny Petrilin <yevgenyp@mellanox.co.il>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Joe Jin <joe.jin@oracle.com>
drivers/net/mlx4/port.c

index ef10113da3568831999d4c38c9f92ac8e76f2c18..836338a2a0a7298037350745bb8eb85428263304 100644 (file)
@@ -65,7 +65,7 @@ void mlx4_init_vlan_table(struct mlx4_dev *dev, struct mlx4_vlan_table *table)
                table->entries[i] = 0;
                table->refs[i]   = 0;
        }
-       table->max   = 1 << dev->caps.log_num_vlans;
+       table->max   = (1 << dev->caps.log_num_vlans) - MLX4_VLAN_REGULAR;
        table->total = 0;
 }
 
@@ -358,6 +358,13 @@ int mlx4_register_vlan(struct mlx4_dev *dev, u8 port, u16 vlan, int *index)
        int free = -1;
 
        mutex_lock(&table->mutex);
+
+       if (table->total == table->max) {
+               /* No free vlan entries */
+               err = -ENOSPC;
+               goto out;
+       }
+
        for (i = MLX4_VLAN_REGULAR; i < MLX4_MAX_VLAN_NUM; i++) {
                if (free < 0 && (table->refs[i] == 0)) {
                        free = i;
@@ -379,12 +386,6 @@ int mlx4_register_vlan(struct mlx4_dev *dev, u8 port, u16 vlan, int *index)
                goto out;
        }
 
-       if (table->total == table->max) {
-               /* No free vlan entries */
-               err = -ENOSPC;
-               goto out;
-       }
-
        /* Register new MAC */
        table->refs[free] = 1;
        table->entries[free] = cpu_to_be32(vlan | MLX4_VLAN_VALID);