Merge git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net
[linux-2.6-microblaze.git] / drivers / net / ethernet / mellanox / mlx5 / core / cmd.c
index 3b61224..989e7cb 100644 (file)
@@ -131,11 +131,8 @@ static int cmd_alloc_index(struct mlx5_cmd *cmd)
 
 static void cmd_free_index(struct mlx5_cmd *cmd, int idx)
 {
-       unsigned long flags;
-
-       spin_lock_irqsave(&cmd->alloc_lock, flags);
+       lockdep_assert_held(&cmd->alloc_lock);
        set_bit(idx, &cmd->bitmask);
-       spin_unlock_irqrestore(&cmd->alloc_lock, flags);
 }
 
 static void cmd_ent_get(struct mlx5_cmd_work_ent *ent)
@@ -145,17 +142,21 @@ static void cmd_ent_get(struct mlx5_cmd_work_ent *ent)
 
 static void cmd_ent_put(struct mlx5_cmd_work_ent *ent)
 {
+       struct mlx5_cmd *cmd = ent->cmd;
+       unsigned long flags;
+
+       spin_lock_irqsave(&cmd->alloc_lock, flags);
        if (!refcount_dec_and_test(&ent->refcnt))
-               return;
+               goto out;
 
        if (ent->idx >= 0) {
-               struct mlx5_cmd *cmd = ent->cmd;
-
                cmd_free_index(cmd, ent->idx);
                up(ent->page_queue ? &cmd->pages_sem : &cmd->sem);
        }
 
        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)