]> Pileus Git - ~andy/linux/blobdiff - drivers/target/target_core_transport.c
target: Fix percpu_ref_put race in transport_lun_remove_cmd
[~andy/linux] / drivers / target / target_core_transport.c
index 51a9736be7269bb1d7f63a2ff20f42aec7eb9bd9..c50fd9f11aab8b0dfb8b90991378a51bf8255d1b 100644 (file)
@@ -594,10 +594,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)