]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
net/mlx5: Move command entry freeing outside of spinlock
authorLi RongQing <lirongqing@baidu.com>
Tue, 31 Mar 2026 12:26:04 +0000 (08:26 -0400)
committerJakub Kicinski <kuba@kernel.org>
Thu, 2 Apr 2026 01:53:09 +0000 (18:53 -0700)
Move the kfree() call outside the critical section to reduce lock
holding time. This aligns with the general principle of minimizing
work under locks.

Signed-off-by: Li RongQing <lirongqing@baidu.com>
Reviewed-by: Tariq Toukan <tariqt@nvidia.com>
Link: https://patch.msgid.link/20260331122604.1933-1-lirongqing@baidu.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/ethernet/mellanox/mlx5/core/cmd.c

index 6c99c7f361634eb25a2d8539c61bf8b2e78bad00..c89417c1a1f96dbfdf27971d799be40a1d17405d 100644 (file)
@@ -196,17 +196,18 @@ static void cmd_ent_put(struct mlx5_cmd_work_ent *ent)
        unsigned long flags;
 
        spin_lock_irqsave(&cmd->alloc_lock, flags);
-       if (!refcount_dec_and_test(&ent->refcnt))
-               goto out;
+       if (!refcount_dec_and_test(&ent->refcnt)) {
+               spin_unlock_irqrestore(&cmd->alloc_lock, flags);
+               return;
+       }
 
        if (ent->idx >= 0) {
                cmd_free_index(cmd, ent->idx);
                up(ent->page_queue ? &cmd->vars.pages_sem : &cmd->vars.sem);
        }
+       spin_unlock_irqrestore(&cmd->alloc_lock, flags);
 
        cmd_free_ent(ent);
-out:
-       spin_unlock_irqrestore(&cmd->alloc_lock, flags);
 }
 
 static struct mlx5_cmd_layout *get_inst(struct mlx5_cmd *cmd, int idx)