mirror of
https://github.com/armbian/linux-cix.git
synced 2026-01-06 12:30:45 -08:00
scsi: core: Kill DRIVER_SENSE
Replace the check for DRIVER_SENSE with a check for scsi_status_is_check_condition(). Audit all callsites to ensure the SAM status is set correctly. For backwards compability move the DRIVER_SENSE definition to sg.h, and update sg, bsg, and scsi_ioctl to set the DRIVER_SENSE driver_status whenever SAM_STAT_CHECK_CONDITION is present. [mkp: fix zeroday srp warning] Link: https://lore.kernel.org/r/20210427083046.31620-10-hare@suse.de Signed-off-by: Hannes Reinecke <hare@suse.de> Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com> fix
This commit is contained in:
committed by
Martin K. Petersen
parent
d0672a03e0
commit
464a00c9e0
@@ -97,6 +97,8 @@ static int bsg_scsi_complete_rq(struct request *rq, struct sg_io_v4 *hdr)
|
||||
hdr->device_status = sreq->result & 0xff;
|
||||
hdr->transport_status = host_byte(sreq->result);
|
||||
hdr->driver_status = driver_byte(sreq->result);
|
||||
if (scsi_status_is_check_condition(sreq->result))
|
||||
hdr->driver_status = DRIVER_SENSE;
|
||||
hdr->info = 0;
|
||||
if (hdr->device_status || hdr->transport_status || hdr->driver_status)
|
||||
hdr->info |= SG_INFO_CHECK;
|
||||
|
||||
@@ -257,6 +257,8 @@ static int blk_complete_sghdr_rq(struct request *rq, struct sg_io_hdr *hdr,
|
||||
hdr->msg_status = msg_byte(req->result);
|
||||
hdr->host_status = host_byte(req->result);
|
||||
hdr->driver_status = driver_byte(req->result);
|
||||
if (scsi_status_is_check_condition(hdr->status))
|
||||
hdr->driver_status = DRIVER_SENSE;
|
||||
hdr->info = 0;
|
||||
if (hdr->masked_status || hdr->host_status || hdr->driver_status)
|
||||
hdr->info |= SG_INFO_CHECK;
|
||||
|
||||
@@ -411,13 +411,12 @@ int ata_cmd_ioctl(struct scsi_device *scsidev, void __user *arg)
|
||||
rc = cmd_result;
|
||||
goto error;
|
||||
}
|
||||
if (driver_byte(cmd_result) == DRIVER_SENSE) {/* sense data available */
|
||||
if (scsi_sense_valid(&sshdr)) {/* sense data available */
|
||||
u8 *desc = sensebuf + 8;
|
||||
cmd_result &= ~(0xFF<<24); /* DRIVER_SENSE is not an error */
|
||||
|
||||
/* If we set cc then ATA pass-through will cause a
|
||||
* check condition even if no error. Filter that. */
|
||||
if (cmd_result & SAM_STAT_CHECK_CONDITION) {
|
||||
if (scsi_status_is_check_condition(cmd_result)) {
|
||||
if (sshdr.sense_key == RECOVERED_ERROR &&
|
||||
sshdr.asc == 0 && sshdr.ascq == 0x1d)
|
||||
cmd_result &= ~SAM_STAT_CHECK_CONDITION;
|
||||
@@ -496,9 +495,8 @@ int ata_task_ioctl(struct scsi_device *scsidev, void __user *arg)
|
||||
rc = cmd_result;
|
||||
goto error;
|
||||
}
|
||||
if (driver_byte(cmd_result) == DRIVER_SENSE) {/* sense data available */
|
||||
if (scsi_sense_valid(&sshdr)) {/* sense data available */
|
||||
u8 *desc = sensebuf + 8;
|
||||
cmd_result &= ~(0xFF<<24); /* DRIVER_SENSE is not an error */
|
||||
|
||||
/* If we set cc then ATA pass-through will cause a
|
||||
* check condition even if no error. Filter that. */
|
||||
@@ -864,8 +862,6 @@ static void ata_gen_passthru_sense(struct ata_queued_cmd *qc)
|
||||
|
||||
memset(sb, 0, SCSI_SENSE_BUFFERSIZE);
|
||||
|
||||
cmd->result = (DRIVER_SENSE << 24) | SAM_STAT_CHECK_CONDITION;
|
||||
|
||||
/*
|
||||
* Use ata_to_sense_error() to map status register bits
|
||||
* onto sense key, asc & ascq.
|
||||
@@ -962,8 +958,6 @@ static void ata_gen_ata_sense(struct ata_queued_cmd *qc)
|
||||
|
||||
memset(sb, 0, SCSI_SENSE_BUFFERSIZE);
|
||||
|
||||
cmd->result = (DRIVER_SENSE << 24) | SAM_STAT_CHECK_CONDITION;
|
||||
|
||||
if (ata_dev_disabled(dev)) {
|
||||
/* Device disabled after error recovery */
|
||||
/* LOGICAL UNIT NOT READY, HARD RESET REQUIRED */
|
||||
@@ -4201,7 +4195,6 @@ void ata_scsi_simulate(struct ata_device *dev, struct scsi_cmnd *cmd)
|
||||
|
||||
case REQUEST_SENSE:
|
||||
ata_scsi_set_sense(dev, cmd, 0, 0, 0);
|
||||
cmd->result = (DRIVER_SENSE << 24);
|
||||
break;
|
||||
|
||||
/* if we reach this, then writeback caching is disabled,
|
||||
|
||||
@@ -542,7 +542,7 @@ static void complete_cmd(struct Scsi_Host *instance,
|
||||
scsi_eh_restore_cmnd(cmd, &hostdata->ses);
|
||||
} else {
|
||||
scsi_eh_restore_cmnd(cmd, &hostdata->ses);
|
||||
set_driver_byte(cmd, DRIVER_SENSE);
|
||||
set_status_byte(cmd, SAM_STAT_CHECK_CONDITION);
|
||||
}
|
||||
hostdata->sensing = NULL;
|
||||
}
|
||||
|
||||
@@ -5964,7 +5964,6 @@ static void adv_isr_callback(ADV_DVC_VAR *adv_dvc_varp, ADV_SCSI_REQ_Q *scsiqp)
|
||||
ASC_DBG(2, "SAM_STAT_CHECK_CONDITION\n");
|
||||
ASC_DBG_PRT_SENSE(2, scp->sense_buffer,
|
||||
SCSI_SENSE_BUFFERSIZE);
|
||||
set_driver_byte(scp, DRIVER_SENSE);
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -6715,7 +6714,6 @@ static void asc_isr_callback(ASC_DVC_VAR *asc_dvc_varp, ASC_QDONE_INFO *qdonep)
|
||||
ASC_DBG(2, "SAM_STAT_CHECK_CONDITION\n");
|
||||
ASC_DBG_PRT_SENSE(2, scp->sense_buffer,
|
||||
SCSI_SENSE_BUFFERSIZE);
|
||||
set_driver_byte(scp, DRIVER_SENSE);
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
@@ -1928,7 +1928,7 @@ ahd_linux_handle_scsi_status(struct ahd_softc *ahd,
|
||||
memcpy(cmd->sense_buffer,
|
||||
ahd_get_sense_buf(ahd, scb)
|
||||
+ sense_offset, sense_size);
|
||||
cmd->result |= (DRIVER_SENSE << 24);
|
||||
set_status_byte(cmd, SAM_STAT_CHECK_CONDITION);
|
||||
|
||||
#ifdef AHD_DEBUG
|
||||
if (ahd_debug & AHD_SHOW_SENSE) {
|
||||
@@ -2018,6 +2018,7 @@ ahd_linux_queue_cmd_complete(struct ahd_softc *ahd, struct scsi_cmnd *cmd)
|
||||
int new_status = DID_OK;
|
||||
int do_fallback = 0;
|
||||
int scsi_status;
|
||||
struct scsi_sense_data *sense;
|
||||
|
||||
/*
|
||||
* Map CAM error codes into Linux Error codes. We
|
||||
@@ -2041,18 +2042,12 @@ ahd_linux_queue_cmd_complete(struct ahd_softc *ahd, struct scsi_cmnd *cmd)
|
||||
switch(scsi_status) {
|
||||
case SAM_STAT_COMMAND_TERMINATED:
|
||||
case SAM_STAT_CHECK_CONDITION:
|
||||
if ((cmd->result >> 24) != DRIVER_SENSE) {
|
||||
sense = (struct scsi_sense_data *)
|
||||
cmd->sense_buffer;
|
||||
if (sense->extra_len >= 5 &&
|
||||
(sense->add_sense_code == 0x47
|
||||
|| sense->add_sense_code == 0x48))
|
||||
do_fallback = 1;
|
||||
} else {
|
||||
struct scsi_sense_data *sense;
|
||||
|
||||
sense = (struct scsi_sense_data *)
|
||||
cmd->sense_buffer;
|
||||
if (sense->extra_len >= 5 &&
|
||||
(sense->add_sense_code == 0x47
|
||||
|| sense->add_sense_code == 0x48))
|
||||
do_fallback = 1;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
||||
@@ -1838,7 +1838,6 @@ ahc_linux_handle_scsi_status(struct ahc_softc *ahc,
|
||||
if (sense_size < SCSI_SENSE_BUFFERSIZE)
|
||||
memset(&cmd->sense_buffer[sense_size], 0,
|
||||
SCSI_SENSE_BUFFERSIZE - sense_size);
|
||||
cmd->result |= (DRIVER_SENSE << 24);
|
||||
#ifdef AHC_DEBUG
|
||||
if (ahc_debug & AHC_SHOW_SENSE) {
|
||||
int i;
|
||||
|
||||
@@ -1335,7 +1335,6 @@ static void arcmsr_report_sense_info(struct CommandControlBlock *ccb)
|
||||
memcpy(sensebuffer, ccb->arcmsr_cdb.SenseData, sense_data_length);
|
||||
sensebuffer->ErrorCode = SCSI_SENSE_CURRENT_ERRORS;
|
||||
sensebuffer->Valid = 1;
|
||||
pcmd->result |= (DRIVER_SENSE << 24);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -200,7 +200,7 @@ ch_do_scsi(scsi_changer *ch, unsigned char *cmd, int cmd_len,
|
||||
MAX_RETRIES, NULL);
|
||||
if (result < 0)
|
||||
return result;
|
||||
if (driver_byte(result) == DRIVER_SENSE) {
|
||||
if (scsi_sense_valid(&sshdr)) {
|
||||
if (debug)
|
||||
scsi_print_sense_hdr(ch->device, ch->name, &sshdr);
|
||||
errno = ch_find_errno(&sshdr);
|
||||
|
||||
@@ -369,8 +369,7 @@ retry:
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (result > 0 && driver_byte(result) == DRIVER_SENSE) {
|
||||
result &= ~(0xFF<<24); /* DRIVER_SENSE is not an error */
|
||||
if (result > 0 && scsi_sense_valid(&sshdr)) {
|
||||
if (result & SAM_STAT_CHECK_CONDITION) {
|
||||
switch (sshdr.sense_key) {
|
||||
case NO_SENSE:
|
||||
|
||||
@@ -3239,16 +3239,9 @@ static void srb_done(struct AdapterCtlBlk *acb, struct DeviceCtlBlk *dcb,
|
||||
}
|
||||
dprintkdbg(DBG_0, "srb_done: AUTO_REQSENSE2\n");
|
||||
|
||||
if (srb->total_xfer_length
|
||||
&& srb->total_xfer_length >= cmd->underflow)
|
||||
cmd->result =
|
||||
MK_RES_LNX(DRIVER_SENSE, DID_OK,
|
||||
srb->end_message, CHECK_CONDITION);
|
||||
/*SET_RES_DID(cmd->result,DID_OK) */
|
||||
else
|
||||
cmd->result =
|
||||
MK_RES_LNX(DRIVER_SENSE, DID_OK,
|
||||
srb->end_message, CHECK_CONDITION);
|
||||
cmd->result =
|
||||
MK_RES(0, DID_OK,
|
||||
srb->end_message, SAM_STAT_CHECK_CONDITION);
|
||||
|
||||
goto ckc_e;
|
||||
}
|
||||
|
||||
@@ -922,9 +922,7 @@ static void esp_cmd_is_done(struct esp *esp, struct esp_cmd_entry *ent,
|
||||
* saw originally. Also, report that we are providing
|
||||
* the sense data.
|
||||
*/
|
||||
cmd->result = ((DRIVER_SENSE << 24) |
|
||||
(DID_OK << 16) |
|
||||
(SAM_STAT_CHECK_CONDITION << 0));
|
||||
cmd->result = SAM_STAT_CHECK_CONDITION;
|
||||
|
||||
ent->flags &= ~ESP_CMD_FLAG_AUTOSENSE;
|
||||
if (esp_debug & ESP_DEBUG_AUTOSENSE) {
|
||||
|
||||
@@ -1583,9 +1583,7 @@ mega_cmd_done(adapter_t *adapter, u8 completed[], int nstatus, int status)
|
||||
memcpy(cmd->sense_buffer, pthru->reqsensearea,
|
||||
14);
|
||||
|
||||
cmd->result = (DRIVER_SENSE << 24) |
|
||||
(DID_OK << 16) |
|
||||
(CHECK_CONDITION << 1);
|
||||
cmd->result = SAM_STAT_CHECK_CONDITION;
|
||||
}
|
||||
else {
|
||||
if (mbox->m_out.cmd == MEGA_MBOXCMD_EXTPTHRU) {
|
||||
@@ -1593,9 +1591,7 @@ mega_cmd_done(adapter_t *adapter, u8 completed[], int nstatus, int status)
|
||||
memcpy(cmd->sense_buffer,
|
||||
epthru->reqsensearea, 14);
|
||||
|
||||
cmd->result = (DRIVER_SENSE << 24) |
|
||||
(DID_OK << 16) |
|
||||
(CHECK_CONDITION << 1);
|
||||
cmd->result = SAM_STAT_CHECK_CONDITION;
|
||||
} else
|
||||
scsi_build_sense(cmd, 0,
|
||||
ABORTED_COMMAND, 0, 0);
|
||||
|
||||
@@ -2299,8 +2299,7 @@ megaraid_mbox_dpc(unsigned long devp)
|
||||
memcpy(scp->sense_buffer, pthru->reqsensearea,
|
||||
14);
|
||||
|
||||
scp->result = DRIVER_SENSE << 24 |
|
||||
DID_OK << 16 | CHECK_CONDITION << 1;
|
||||
scp->result = SAM_STAT_CHECK_CONDITION;
|
||||
}
|
||||
else {
|
||||
if (mbox->cmd == MBOXCMD_EXTPTHRU) {
|
||||
@@ -2308,9 +2307,7 @@ megaraid_mbox_dpc(unsigned long devp)
|
||||
memcpy(scp->sense_buffer,
|
||||
epthru->reqsensearea, 14);
|
||||
|
||||
scp->result = DRIVER_SENSE << 24 |
|
||||
DID_OK << 16 |
|
||||
CHECK_CONDITION << 1;
|
||||
scp->result = SAM_STAT_CHECK_CONDITION;
|
||||
} else
|
||||
scsi_build_sense(scp, 0,
|
||||
ABORTED_COMMAND, 0, 0);
|
||||
|
||||
@@ -3617,8 +3617,6 @@ megasas_complete_cmd(struct megasas_instance *instance, struct megasas_cmd *cmd,
|
||||
SCSI_SENSE_BUFFERSIZE);
|
||||
memcpy(cmd->scmd->sense_buffer, cmd->sense,
|
||||
hdr->sense_len);
|
||||
|
||||
cmd->scmd->result |= DRIVER_SENSE << 24;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
@@ -2051,7 +2051,6 @@ map_cmd_status(struct fusion_context *fusion,
|
||||
SCSI_SENSE_BUFFERSIZE);
|
||||
memcpy(scmd->sense_buffer, sense,
|
||||
SCSI_SENSE_BUFFERSIZE);
|
||||
scmd->result |= DRIVER_SENSE << 24;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -1317,7 +1317,6 @@ static void mvumi_complete_cmd(struct mvumi_hba *mhba, struct mvumi_cmd *cmd,
|
||||
if (ob_frame->rsp_flag & CL_RSP_FLAG_SENSEDATA) {
|
||||
memcpy(cmd->scmd->sense_buffer, ob_frame->payload,
|
||||
sizeof(struct mvumi_sense_data));
|
||||
scmd->result |= (DRIVER_SENSE << 24);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
||||
@@ -185,13 +185,6 @@ void scsi_finish_command(struct scsi_cmnd *cmd)
|
||||
if (atomic_read(&sdev->device_blocked))
|
||||
atomic_set(&sdev->device_blocked, 0);
|
||||
|
||||
/*
|
||||
* If we have valid sense information, then some kind of recovery
|
||||
* must have taken place. Make a note of this.
|
||||
*/
|
||||
if (SCSI_SENSE_VALID(cmd))
|
||||
cmd->result |= (DRIVER_SENSE << 24);
|
||||
|
||||
SCSI_LOG_MLCOMPLETE(4, sdev_printk(KERN_INFO, sdev,
|
||||
"Notifying upper driver of completion "
|
||||
"(result %x)\n", cmd->result));
|
||||
|
||||
@@ -851,10 +851,10 @@ static struct device_driver sdebug_driverfs_driver = {
|
||||
};
|
||||
|
||||
static const int check_condition_result =
|
||||
(DRIVER_SENSE << 24) | SAM_STAT_CHECK_CONDITION;
|
||||
SAM_STAT_CHECK_CONDITION;
|
||||
|
||||
static const int illegal_condition_result =
|
||||
(DRIVER_SENSE << 24) | (DID_ABORT << 16) | SAM_STAT_CHECK_CONDITION;
|
||||
(DID_ABORT << 16) | SAM_STAT_CHECK_CONDITION;
|
||||
|
||||
static const int device_qfull_result =
|
||||
(DID_OK << 16) | SAM_STAT_TASK_SET_FULL;
|
||||
|
||||
@@ -103,8 +103,7 @@ static int ioctl_internal_command(struct scsi_device *sdev, char *cmd,
|
||||
|
||||
if (result < 0)
|
||||
goto out;
|
||||
if (driver_byte(result) == DRIVER_SENSE &&
|
||||
scsi_sense_valid(&sshdr)) {
|
||||
if (scsi_sense_valid(&sshdr)) {
|
||||
switch (sshdr.sense_key) {
|
||||
case ILLEGAL_REQUEST:
|
||||
if (cmd[0] == ALLOW_MEDIUM_REMOVAL)
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user