diff --git a/scst/include/scst.h b/scst/include/scst.h index 603cf9703..a37e2a479 100644 --- a/scst/include/scst.h +++ b/scst/include/scst.h @@ -2407,7 +2407,7 @@ static inline int scst_cmd_aborted(struct scst_cmd *cmd) /* Returns sense data format for cmd's dev */ static inline bool scst_get_cmd_dev_d_sense(struct scst_cmd *cmd) { - return cmd->dev->d_sense; + return (cmd->dev != NULL) ? cmd->dev->d_sense : 0; } /* diff --git a/scst/src/scst_lib.c b/scst/src/scst_lib.c index 0f5b2446a..fbff1e1a4 100644 --- a/scst/src/scst_lib.c +++ b/scst/src/scst_lib.c @@ -141,8 +141,8 @@ void scst_set_cmd_error(struct scst_cmd *cmd, int key, int asc, int ascq) goto out; } - scst_set_sense(cmd->sense, SCST_SENSE_BUFFERSIZE, cmd->dev->d_sense, - key, asc, ascq); + scst_set_sense(cmd->sense, SCST_SENSE_BUFFERSIZE, + scst_get_cmd_dev_d_sense(cmd), key, asc, ascq); TRACE_BUFFER("Sense set", cmd->sense, SCST_SENSE_BUFFERSIZE); out: