fc_port_t *fcport = sp->fcport;
        struct qla_hw_data *ha = fcport->vha->hw;
        int rval, abts_done_called = 1;
+       bool io_wait_for_abort_done;
+       uint32_t handle;
 
        ql_dbg(ql_dbg_io, fcport->vha, 0xffff,
               "%s called for sp=%p, hndl=%x on fcport=%p desc=%p deleted=%d\n",
                goto out;
        }
 
+       /*
+        * sp may not be valid after abort_command if return code is either
+        * SUCCESS or ERR_FROM_FW codes, so cache the value here.
+        */
+       io_wait_for_abort_done = ql2xabts_wait_nvme &&
+                                       QLA_ABTS_WAIT_ENABLED(sp);
+       handle = sp->handle;
+
        rval = ha->isp_ops->abort_command(sp);
 
        ql_dbg(ql_dbg_io, fcport->vha, 0x212b,
            "%s: %s command for sp=%p, handle=%x on fcport=%p rval=%x\n",
            __func__, (rval != QLA_SUCCESS) ? "Failed to abort" : "Aborted",
-           sp, sp->handle, fcport, rval);
+           sp, handle, fcport, rval);
 
        /*
         * If async tmf is enabled, the abort callback is called only on
         * are waited until ABTS complete. This kref is decreased
         * at qla24xx_abort_sp_done function.
         */
-       if (abts_done_called && ql2xabts_wait_nvme && QLA_ABTS_WAIT_ENABLED(sp))
+       if (abts_done_called && io_wait_for_abort_done)
                return;
 out:
        /* kref_get was done before work was schedule. */