]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
net/mlx5: HWS, handle returned error value in pool alloc
authorVlad Dogaru <vdogaru@nvidia.com>
Thu, 2 Jan 2025 18:14:11 +0000 (20:14 +0200)
committerJakub Kicinski <kuba@kernel.org>
Tue, 7 Jan 2025 00:33:41 +0000 (16:33 -0800)
Handle all negative return values as errors, not just -1.
The code previously treated -ENOMEM (and potentially other negative
values) as valid segment numbers, leading to incorrect behavior.
This fix ensures that any negative return value is treated as an error.

Signed-off-by: Vlad Dogaru <vdogaru@nvidia.com>
Signed-off-by: Yevgeny Kliteynik <kliteyn@nvidia.com>
Reviewed-by: Mark Bloch <mbloch@nvidia.com>
Signed-off-by: Tariq Toukan <tariqt@nvidia.com>
Link: https://patch.msgid.link/20250102181415.1477316-13-tariqt@nvidia.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/ethernet/mellanox/mlx5/core/steering/hws/pool.c

index fed2d913f3b89f80cddee0873a16d97ed2f93958..50a81d360bb2ff26cc6d7744b6753dc1b76daa20 100644 (file)
@@ -183,7 +183,7 @@ static int hws_pool_buddy_get_mem_chunk(struct mlx5hws_pool *pool,
        *seg = -1;
 
        /* Find the next free place from the buddy array */
-       while (*seg == -1) {
+       while (*seg < 0) {
                for (i = 0; i < MLX5HWS_POOL_RESOURCE_ARR_SZ; i++) {
                        buddy = hws_pool_buddy_get_next_buddy(pool, i,
                                                              order,
@@ -194,7 +194,7 @@ static int hws_pool_buddy_get_mem_chunk(struct mlx5hws_pool *pool,
                        }
 
                        *seg = mlx5hws_buddy_alloc_mem(buddy, order);
-                       if (*seg != -1)
+                       if (*seg >= 0)
                                goto found;
 
                        if (pool->flags & MLX5HWS_POOL_FLAGS_ONE_RESOURCE) {