]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
net/mlx5e: Verify unique vhca_id count instead of range
authorShay Drory <shayd@nvidia.com>
Sun, 31 May 2026 11:39:53 +0000 (14:39 +0300)
committerJakub Kicinski <kuba@kernel.org>
Thu, 4 Jun 2026 00:42:21 +0000 (17:42 -0700)
Change verify_num_vhca_ids() to count the number of unique vhca_ids
and verify this count doesn't exceed max_num_vhca_id, rather than
validating individual vhca_id values are within a specific range.

The previous implementation checked if each vhca_id was in the range
[0, max_num_vhca_id - 1], which is overly restrictive. The hardware
capability max_rqt_vhca_id represents the maximum number of unique
vhca_ids that can be used, not a range constraint on individual IDs.

Signed-off-by: Shay Drory <shayd@nvidia.com>
Reviewed-by: Mark Bloch <mbloch@nvidia.com>
Signed-off-by: Tariq Toukan <tariqt@nvidia.com>
Link: https://patch.msgid.link/20260531113954.395443-14-tariqt@nvidia.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/ethernet/mellanox/mlx5/core/en/rqt.c

index a3382f6a6b74c893923475132d153cb5f966974d..8511363f7bec265447e581252a6d0abc09d6328d 100644 (file)
@@ -8,13 +8,28 @@ static bool verify_num_vhca_ids(struct mlx5_core_dev *mdev, u32 *vhca_ids,
                                unsigned int size)
 {
        unsigned int max_num_vhca_id = MLX5_CAP_GEN_2(mdev, max_rqt_vhca_id);
-       int i;
+       unsigned int unique_count = 0;
+       int i, j;
+
+       /* Count unique vhca_ids */
+       for (i = 0; i < size; i++) {
+               bool is_unique = true;
+
+               /* Check if vhca_ids[i] was already seen */
+               for (j = 0; j < i; j++) {
+                       if (vhca_ids[j] == vhca_ids[i]) {
+                               is_unique = false;
+                               break;
+                       }
+               }
+               if (is_unique)
+                       unique_count++;
+       }
 
-       /* Verify that all vhca_ids are in range [0, max_num_vhca_ids - 1] */
-       for (i = 0; i < size; i++)
-               if (vhca_ids[i] >= max_num_vhca_id)
-                       return false;
-       return true;
+       /* Verify that number of unique vhca_ids doesn't exceed
+        * max_num_vhca_id
+        */
+       return unique_count <= max_num_vhca_id;
 }
 
 static bool rqt_verify_vhca_ids(struct mlx5_core_dev *mdev, u32 *vhca_ids,