diff options
-rw-r--r-- | drivers/target/target_core_transport.c | 5 | ||||
-rw-r--r-- | include/target/target_core_base.h | 2 |
2 files changed, 4 insertions, 3 deletions
diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c index 91953da0f62..dee2be1f917 100644 --- a/drivers/target/target_core_transport.c +++ b/drivers/target/target_core_transport.c @@ -568,10 +568,11 @@ static void transport_lun_remove_cmd(struct se_cmd *cmd) { struct se_lun *lun = cmd->se_lun; - if (!lun || !cmd->lun_ref_active) + if (!lun) return; - percpu_ref_put(&lun->lun_ref); + if (cmpxchg(&cmd->lun_ref_active, true, false)) + percpu_ref_put(&lun->lun_ref); } void transport_cmd_finish_abort(struct se_cmd *cmd, int remove) diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h index 321301c0a64..e3569f829f7 100644 --- a/include/target/target_core_base.h +++ b/include/target/target_core_base.h @@ -497,7 +497,7 @@ struct se_cmd { void *priv; /* Used for lun->lun_ref counting */ - bool lun_ref_active; + int lun_ref_active; }; struct se_ua { |