Skip to content

Commit dc41327

Browse files
Moshe Shemeshgregkh
authored andcommitted
net/mlx5: Fix command bad flow on command entry allocation failure
[ Upstream commit 219c81f7d1d5a89656cb3b53d3b4e11e93608d80 ] When driver fail to allocate an entry to send command to FW, it must notify the calling function and release the memory allocated for this command. Fixes: e126ba9 ('mlx5: Add driver for Mellanox Connect-IB adapters') Signed-off-by: Moshe Shemesh <moshe@mellanox.com> Cc: kernel-team@fb.com Signed-off-by: Saeed Mahameed <saeedm@mellanox.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent de66696 commit dc41327

1 file changed

Lines changed: 17 additions & 2 deletions

File tree

  • drivers/net/ethernet/mellanox/mlx5/core

drivers/net/ethernet/mellanox/mlx5/core/cmd.c

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,10 @@ static void dump_command(struct mlx5_core_dev *dev,
630630
pr_debug("\n");
631631
}
632632

633+
static void free_msg(struct mlx5_core_dev *dev, struct mlx5_cmd_msg *msg);
634+
static void mlx5_free_cmd_msg(struct mlx5_core_dev *dev,
635+
struct mlx5_cmd_msg *msg);
636+
633637
static void cmd_work_handler(struct work_struct *work)
634638
{
635639
struct mlx5_cmd_work_ent *ent = container_of(work, struct mlx5_cmd_work_ent, work);
@@ -638,16 +642,27 @@ static void cmd_work_handler(struct work_struct *work)
638642
struct mlx5_cmd_layout *lay;
639643
struct semaphore *sem;
640644
unsigned long flags;
645+
int alloc_ret;
641646

642647
sem = ent->page_queue ? &cmd->pages_sem : &cmd->sem;
643648
down(sem);
644649
if (!ent->page_queue) {
645-
ent->idx = alloc_ent(cmd);
646-
if (ent->idx < 0) {
650+
alloc_ret = alloc_ent(cmd);
651+
if (alloc_ret < 0) {
652+
if (ent->callback) {
653+
ent->callback(-EAGAIN, ent->context);
654+
mlx5_free_cmd_msg(dev, ent->out);
655+
free_msg(dev, ent->in);
656+
free_cmd(ent);
657+
} else {
658+
ent->ret = -EAGAIN;
659+
complete(&ent->done);
660+
}
647661
mlx5_core_err(dev, "failed to allocate command entry\n");
648662
up(sem);
649663
return;
650664
}
665+
ent->idx = alloc_ret;
651666
} else {
652667
ent->idx = cmd->max_reg_cmds;
653668
spin_lock_irqsave(&cmd->alloc_lock, flags);

0 commit comments

Comments
 (0)