diff --git a/scst/include/scst.h b/scst/include/scst.h index 24a40fcaa..35af18bd8 100644 --- a/scst/include/scst.h +++ b/scst/include/scst.h @@ -2317,6 +2317,9 @@ struct scst_cmd { /* Set by WRITE VERIFY commands to trigger a verify after write */ unsigned int do_verify:1; + /* For debugging purposes. */ + unsigned int owns_refcnt:1; + /**************************************************************/ /* cmd's async flags */ diff --git a/scst/src/scst_targ.c b/scst/src/scst_targ.c index 450265082..bee0ae2de 100644 --- a/scst/src/scst_targ.c +++ b/scst/src/scst_targ.c @@ -4504,6 +4504,7 @@ static int scst_pre_xmit_response1(struct scst_cmd *cmd) * latency, so we should decrement them after cmd completed. */ smp_mb__before_atomic_dec(); + cmd->owns_refcnt = false; scst_tgt_dev_dec_cmd_count(cmd->tgt_dev); percpu_ref_put(&cmd->dev->refcnt); #ifdef CONFIG_SCST_PER_DEVICE_CMD_COUNT_LIMIT @@ -4693,6 +4694,8 @@ static int scst_finish_cmd(struct scst_cmd *cmd) TRACE_ENTRY(); + WARN_ON_ONCE(cmd->owns_refcnt); + if (unlikely(cmd->delivery_status != SCST_CMD_DELIVERY_SUCCESS)) { if ((cmd->tgt_dev != NULL) && (cmd->status == SAM_STAT_CHECK_CONDITION) && @@ -5156,6 +5159,7 @@ static int __scst_init_cmd(struct scst_cmd *cmd) failure = true; } + cmd->owns_refcnt = true; percpu_ref_get(&dev->refcnt); #ifdef CONFIG_SCST_PER_DEVICE_CMD_COUNT_LIMIT atomic_inc(&dev->dev_cmd_count);