diff --git a/scst/src/scst_lib.c b/scst/src/scst_lib.c index 0eed3e010..0bdc78e09 100644 --- a/scst/src/scst_lib.c +++ b/scst/src/scst_lib.c @@ -1776,9 +1776,9 @@ EXPORT_SYMBOL(scst_set_cmd_error_status); static int scst_set_lun_not_supported_request_sense(struct scst_cmd *cmd, int key, int asc, int ascq) { - int res; int sense_len, len; struct scatterlist *sg; + int res = 0; TRACE_ENTRY(); @@ -1796,6 +1796,12 @@ static int scst_set_lun_not_supported_request_sense(struct scst_cmd *cmd, } if (cmd->sg == NULL) { + if (cmd->bufflen == 0) { + int bufflen = cmd->cdb[4]; + + cmd->bufflen = bufflen ?: 18; + } + /* * If target driver preparing data buffer using tgt_alloc_data_buf() * callback, it is responsible to copy the sense to its buffer @@ -1808,9 +1814,6 @@ static int scst_set_lun_not_supported_request_sense(struct scst_cmd *cmd, goto go; } - if (cmd->bufflen == 0) - cmd->bufflen = cmd->cdb[4]; - cmd->sg = scst_alloc_sg(cmd->bufflen, GFP_ATOMIC, &cmd->sg_cnt); if (cmd->sg == NULL) { PRINT_ERROR("Unable to alloc sg for REQUEST SENSE (sense %x/%x/%x)", @@ -1837,12 +1840,12 @@ go: cmd->data_direction = SCST_DATA_READ; scst_set_resp_data_len(cmd, sense_len); - res = 0; cmd->completed = 1; cmd->resid_possible = 1; out: TRACE_EXIT_RES(res); + return res; }