diff mbox

[VERY,EARLY,RFC,10/13] scsi: introduce set_status_byte and convert LLDDs to use it

Message ID 20180418150116.18807-11-jthumshirn@suse.de (mailing list archive)
State Changes Requested
Headers show

Commit Message

Johannes Thumshirn April 18, 2018, 3:01 p.m. UTC
<SmPL>
@@
struct scsi_cmnd *c;
expression E1;
@@
(
-c->result |= E1;
+set_status_byte(c, E1);
|
-c->result |= (E1);
+set_status_byte(c, E1);
)
</SmPL>

Signed-off-by: Johannes Thumshirn <jthumshirn@suse.de>
---
 drivers/ata/libata-scsi.c                | 20 ++++++++--------
 drivers/infiniband/ulp/srp/ib_srp.c      |  2 +-
 drivers/message/fusion/mptscsih.c        |  4 ++--
 drivers/s390/scsi/zfcp_fc.h              |  2 +-
 drivers/s390/scsi/zfcp_scsi.c            |  2 +-
 drivers/scsi/3w-9xxx.c                   |  3 ++-
 drivers/scsi/3w-sas.c                    |  4 +++-
 drivers/scsi/aacraid/aachba.c            |  6 ++---
 drivers/scsi/advansys.c                  |  7 ++----
 drivers/scsi/aic7xxx/aic79xx_osm.h       |  2 +-
 drivers/scsi/aic7xxx/aic7xxx_osm.h       |  2 +-
 drivers/scsi/atp870u.c                   |  7 +++---
 drivers/scsi/dpt_i2o.c                   |  2 +-
 drivers/scsi/hpsa.c                      |  4 ++--
 drivers/scsi/hptiop.c                    |  2 +-
 drivers/scsi/ibmvscsi/ibmvscsi.c         |  2 +-
 drivers/scsi/ipr.c                       |  6 ++---
 drivers/scsi/libfc/fc_fcp.c              |  2 +-
 drivers/scsi/libsas/sas_ata.c            |  5 ++--
 drivers/scsi/libsas/sas_expander.c       |  2 +-
 drivers/scsi/megaraid.c                  | 13 +++++++----
 drivers/scsi/megaraid/megaraid_mbox.c    |  4 ++--
 drivers/scsi/mpt3sas/mpt3sas_scsih.c     | 12 ++++++----
 drivers/scsi/mvsas/mv_sas.c              |  2 +-
 drivers/scsi/mvumi.c                     |  2 +-
 drivers/scsi/pm8001/pm8001_sas.c         |  5 ++--
 drivers/scsi/pmcraid.c                   |  4 ++--
 drivers/scsi/qla1280.c                   |  2 +-
 drivers/scsi/qla2xxx/qla_isr.c           |  6 ++---
 drivers/scsi/scsi_error.c                | 40 ++++++++++++++++----------------
 drivers/scsi/smartpqi/smartpqi_init.c    |  6 ++---
 drivers/scsi/storvsc_drv.c               |  2 +-
 drivers/scsi/virtio_scsi.c               |  2 +-
 drivers/staging/rts5208/rtsx_transport.c |  4 ++--
 drivers/target/loopback/tcm_loop.c       |  6 ++---
 drivers/usb/image/microtek.c             |  5 ++--
 drivers/usb/storage/datafab.c            |  4 ++--
 drivers/usb/storage/isd200.c             | 22 +++++++++---------
 drivers/usb/storage/jumpshot.c           |  4 ++--
 drivers/usb/storage/realtek_cr.c         | 12 ++++++----
 drivers/usb/storage/transport.c          | 17 +++++++-------
 drivers/usb/storage/uas.c                |  4 ++--
 drivers/usb/storage/usb.c                |  2 +-
 include/scsi/scsi.h                      |  6 ++++-
 include/scsi/scsi_cmnd.h                 |  6 +++++
 include/scsi/scsi_proto.h                | 25 ++++++++++----------
 46 files changed, 163 insertions(+), 140 deletions(-)
diff mbox

Patch

diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
index cedf4b70f06f..0d6547351d85 100644
--- a/drivers/ata/libata-scsi.c
+++ b/drivers/ata/libata-scsi.c
@@ -1550,7 +1550,7 @@  static unsigned int ata_scsi_start_stop_xlat(struct ata_queued_cmd *qc)
 	ata_scsi_set_invalid_field(qc->dev, scmd, fp, bp);
 	return 1;
  skip:
-	scmd->result = SAM_STAT_GOOD;
+	set_status_byte(scmd, SAM_STAT_GOOD);
 	return 1;
 }
 
@@ -1801,7 +1801,7 @@  static unsigned int ata_scsi_verify_xlat(struct ata_queued_cmd *qc)
 	return 1;
 
 nothing_to_do:
-	scmd->result = SAM_STAT_GOOD;
+	set_status_byte(scmd, SAM_STAT_GOOD);
 	return 1;
 }
 
@@ -1913,7 +1913,7 @@  static unsigned int ata_scsi_rw_xlat(struct ata_queued_cmd *qc)
 	return 1;
 
 nothing_to_do:
-	scmd->result = SAM_STAT_GOOD;
+	set_status_byte(scmd, SAM_STAT_GOOD);
 	return 1;
 }
 
@@ -1946,11 +1946,11 @@  static void ata_scsi_qc_complete(struct ata_queued_cmd *qc)
 	    ((cdb[2] & 0x20) || need_sense))
 		ata_gen_passthru_sense(qc);
 	else if (qc->flags & ATA_QCFLAG_SENSE_VALID)
-		cmd->result = SAM_STAT_CHECK_CONDITION;
+		set_status_byte(cmd, SAM_STAT_CHECK_CONDITION);
 	else if (need_sense)
 		ata_gen_ata_sense(qc);
 	else
-		cmd->result = SAM_STAT_GOOD;
+		set_status_byte(cmd, SAM_STAT_GOOD);
 
 	if (need_sense && !ap->ops->error_handler)
 		ata_dump_status(ap->print_id, &qc->result_tf);
@@ -2131,7 +2131,7 @@  static void ata_scsi_rbuf_fill(struct ata_scsi_args *args,
 	ata_scsi_rbuf_put(cmd, rc == 0, &flags);
 
 	if (rc == 0)
-		cmd->result = SAM_STAT_GOOD;
+		set_status_byte(cmd, SAM_STAT_GOOD);
 }
 
 /**
@@ -2910,14 +2910,14 @@  static void atapi_qc_complete(struct ata_queued_cmd *qc)
 		if (qc->cdb[0] == ALLOW_MEDIUM_REMOVAL && qc->dev->sdev)
 			qc->dev->sdev->locked = 0;
 
-		qc->scsicmd->result = SAM_STAT_CHECK_CONDITION;
+		set_status_byte(qc->scsicmd, SAM_STAT_CHECK_CONDITION);
 		ata_qc_done(qc);
 		return;
 	}
 
 	/* successful completion or old EH failure path */
 	if (unlikely(err_mask & AC_ERR_DEV)) {
-		cmd->result = SAM_STAT_CHECK_CONDITION;
+		set_status_byte(cmd, SAM_STAT_CHECK_CONDITION);
 		atapi_request_sense(qc);
 		return;
 	} else if (unlikely(err_mask)) {
@@ -2930,7 +2930,7 @@  static void atapi_qc_complete(struct ata_queued_cmd *qc)
 	} else {
 		if (cmd->cmnd[0] == INQUIRY && (cmd->cmnd[1] & 0x03) == 0)
 			atapi_fixup_inquiry(cmd);
-		cmd->result = SAM_STAT_GOOD;
+		set_status_byte(cmd, SAM_STAT_GOOD);
 	}
 
 	ata_qc_done(qc);
@@ -4111,7 +4111,7 @@  static unsigned int ata_scsi_mode_select_xlat(struct ata_queued_cmd *qc)
 	return 1;
 
  skip:
-	scmd->result = SAM_STAT_GOOD;
+	set_status_byte(scmd, SAM_STAT_GOOD);
 	return 1;
 }
 
diff --git a/drivers/infiniband/ulp/srp/ib_srp.c b/drivers/infiniband/ulp/srp/ib_srp.c
index 7be3970058a6..97ea52936764 100644
--- a/drivers/infiniband/ulp/srp/ib_srp.c
+++ b/drivers/infiniband/ulp/srp/ib_srp.c
@@ -2095,7 +2095,7 @@  static void srp_process_rsp(struct srp_rdma_ch *ch, struct srp_rsp *rsp)
 
 			return;
 		}
-		scmnd->result = rsp->status;
+		set_status_byte(scmnd, rsp->status);
 
 		if (rsp->flags & SRP_RSP_FLAG_SNSVALID) {
 			memcpy(scmnd->sense_buffer, rsp->data +
diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
index 9607eab5d4f6..cedd923fa67f 100644
--- a/drivers/message/fusion/mptscsih.c
+++ b/drivers/message/fusion/mptscsih.c
@@ -709,7 +709,7 @@  mptscsih_io_done(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *mr)
 			 * But not: DID_BUS_BUSY lest one risk
 			 * killing interrupt handler:-(
 			 */
-			sc->result = SAM_STAT_BUSY;
+			set_status_byte(sc, SAM_STAT_BUSY);
 			break;
 
 		case MPI_IOCSTATUS_SCSI_INVALID_BUS:		/* 0x0041 */
@@ -867,7 +867,7 @@  mptscsih_io_done(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *mr)
 
 				if (xfer_cnt < sc->underflow) {
 					if (scsi_status == SAM_STAT_BUSY)
-						sc->result = SAM_STAT_BUSY;
+						set_status_byte(sc, SAM_STAT_BUSY);
 					else {
 						sc->result = 0;
 						set_host_byte(sc,
diff --git a/drivers/s390/scsi/zfcp_fc.h b/drivers/s390/scsi/zfcp_fc.h
index 6a397ddaadf0..a0080a23fd2e 100644
--- a/drivers/s390/scsi/zfcp_fc.h
+++ b/drivers/s390/scsi/zfcp_fc.h
@@ -255,7 +255,7 @@  void zfcp_fc_eval_fcp_rsp(struct fcp_resp_with_ext *fcp_rsp,
 	u8 rsp_flags;
 
 	set_msg_byte(scsi, COMMAND_COMPLETE);
-	scsi->result |= fcp_rsp->resp.fr_status;
+	set_status_byte(scsi, fcp_rsp->resp.fr_status);
 
 	rsp_flags = fcp_rsp->resp.fr_flags;
 
diff --git a/drivers/s390/scsi/zfcp_scsi.c b/drivers/s390/scsi/zfcp_scsi.c
index 4d2ba5682493..952f3b9639d1 100644
--- a/drivers/s390/scsi/zfcp_scsi.c
+++ b/drivers/s390/scsi/zfcp_scsi.c
@@ -742,7 +742,7 @@  void zfcp_scsi_dif_sense_error(struct scsi_cmnd *scmd, int ascq)
 	scsi_build_sense_buffer(1, scmd->sense_buffer,
 				ILLEGAL_REQUEST, 0x10, ascq);
 	set_driver_byte(scmd, DRIVER_SENSE);
-	scmd->result |= SAM_STAT_CHECK_CONDITION;
+	set_status_byte(scmd, SAM_STAT_CHECK_CONDITION);
 	set_host_byte(scmd, DID_SOFT_ERROR);
 }
 
diff --git a/drivers/scsi/3w-9xxx.c b/drivers/scsi/3w-9xxx.c
index 5b339b4275b5..ccdf7b08d117 100644
--- a/drivers/scsi/3w-9xxx.c
+++ b/drivers/scsi/3w-9xxx.c
@@ -1008,8 +1008,9 @@  static int twa_fill_sense(TW_Device_Extension *tw_dev, int request_id, int copy_
 	}
 
 	if (copy_sense) {
+		u8 status = (full_command_packet->command.newcommand.status << 1);
 		memcpy(tw_dev->srb[request_id]->sense_buffer, full_command_packet->header.sense_data, TW_SENSE_DATA_LENGTH);
-		tw_dev->srb[request_id]->result = (full_command_packet->command.newcommand.status << 1);
+		set_status_byte(tw_dev->srb[request_id], status);
 		retval = TW_ISR_DONT_RESULT;
 		goto out;
 	}
diff --git a/drivers/scsi/3w-sas.c b/drivers/scsi/3w-sas.c
index 414658063747..6217d1951ea9 100644
--- a/drivers/scsi/3w-sas.c
+++ b/drivers/scsi/3w-sas.c
@@ -887,8 +887,10 @@  static int twl_fill_sense(TW_Device_Extension *tw_dev, int i, int request_id, in
 	}
 
 	if (copy_sense) {
+		u8 status = (full_command_packet->command.newcommand.status << 1);
+
 		memcpy(tw_dev->srb[request_id]->sense_buffer, header->sense_data, TW_SENSE_DATA_LENGTH);
-		tw_dev->srb[request_id]->result = (full_command_packet->command.newcommand.status << 1);
+		set_status_byte(tw_dev->srb[request_id], status);
 		goto out;
 	}
 out:
diff --git a/drivers/scsi/aacraid/aachba.c b/drivers/scsi/aacraid/aachba.c
index e977d9622ef9..3c71393018b7 100644
--- a/drivers/scsi/aacraid/aachba.c
+++ b/drivers/scsi/aacraid/aachba.c
@@ -3668,7 +3668,7 @@  static void aac_srb_callback(void *context, struct fib * fibptr)
 			== SAM_STAT_CHECK_CONDITION) {
 		int len;
 
-		scsicmd->result |= SAM_STAT_CHECK_CONDITION;
+		set_status_byte(scsicmd, SAM_STAT_CHECK_CONDITION);
 		len = min_t(u32, le32_to_cpu(srbreply->sense_data_size),
 			    SCSI_SENSE_BUFFERSIZE);
 #ifdef AAC_DETAILED_STATUS_INFO
@@ -3682,7 +3682,7 @@  static void aac_srb_callback(void *context, struct fib * fibptr)
 	/*
 	 * OR in the scsi status (already shifted up a bit)
 	 */
-	scsicmd->result |= le32_to_cpu(srbreply->scsi_status);
+	set_status_byte(scsicmd, le32_to_cpu(srbreply->scsi_status));
 
 	aac_fib_complete(fibptr);
 	scsicmd->scsi_done(scsicmd);
@@ -3692,7 +3692,7 @@  static void hba_resp_task_complete(struct aac_dev *dev,
 					struct scsi_cmnd *scsicmd,
 					struct aac_hba_resp *err) {
 
-	scsicmd->result = err->status;
+	set_status_byte(scsicmd, err->status);
 	/* set residual count */
 	scsi_set_resid(scsicmd, le32_to_cpu(err->residual_count));
 
diff --git a/drivers/scsi/advansys.c b/drivers/scsi/advansys.c
index 63c0d97d52a0..2bb709df4bb9 100644
--- a/drivers/scsi/advansys.c
+++ b/drivers/scsi/advansys.c
@@ -2089,9 +2089,6 @@  do { \
 #define ASC_BUSY        0
 #define ASC_ERROR       (-1)
 
-/* struct scsi_cmnd function return codes */
-#define STATUS_BYTE(byte)   (byte)
-
 #define ASC_STATS(shost, counter) ASC_STATS_ADD(shost, counter, 1)
 #ifndef ADVANSYS_STATS
 #define ASC_STATS_ADD(shost, counter, count)
@@ -6039,7 +6036,7 @@  static void adv_isr_callback(ADV_DVC_VAR *adv_dvc_varp, ADV_SCSI_REQ_Q *scsiqp)
 				set_scsi_result(scp, DRIVER_SENSE, 0, 0,
 						scsiqp->scsi_status);
 			} else {
-				scp->result = STATUS_BYTE(scsiqp->scsi_status);
+				set_status_byte(scp, scsiqp->scsi_status);
 			}
 			break;
 
@@ -6805,7 +6802,7 @@  static void asc_isr_callback(ASC_DVC_VAR *asc_dvc_varp, ASC_QDONE_INFO *qdonep)
 				set_scsi_result(scp, 0, DRIVER_SENSE, 0,
 					qdonep->d3.scsi_stat);
 			} else {
-				scp->result = STATUS_BYTE(qdonep->d3.scsi_stat);
+				set_status_byte(scp, qdonep->d3.scsi_stat);
 			}
 			break;
 
diff --git a/drivers/scsi/aic7xxx/aic79xx_osm.h b/drivers/scsi/aic7xxx/aic79xx_osm.h
index dd6307cd4ed1..4159ae10d876 100644
--- a/drivers/scsi/aic7xxx/aic79xx_osm.h
+++ b/drivers/scsi/aic7xxx/aic79xx_osm.h
@@ -538,7 +538,7 @@  static inline
 void ahd_cmd_set_scsi_status(struct scsi_cmnd *cmd, uint32_t status)
 {
 	cmd->result &= ~0xFFFF;
-	cmd->result |= status;
+	set_status_byte(cmd, status);
 }
 
 static inline
diff --git a/drivers/scsi/aic7xxx/aic7xxx_osm.h b/drivers/scsi/aic7xxx/aic7xxx_osm.h
index 4e83b5fc2b2c..4187aeabefa5 100644
--- a/drivers/scsi/aic7xxx/aic7xxx_osm.h
+++ b/drivers/scsi/aic7xxx/aic7xxx_osm.h
@@ -556,7 +556,7 @@  static inline
 void ahc_cmd_set_scsi_status(struct scsi_cmnd *cmd, uint32_t status)
 {
 	cmd->result &= ~0xFFFF;
-	cmd->result |= status;
+	set_status_byte(cmd, status);
 }
 
 static inline
diff --git a/drivers/scsi/atp870u.c b/drivers/scsi/atp870u.c
index d02ca00e27d3..56a85ddbfca0 100644
--- a/drivers/scsi/atp870u.c
+++ b/drivers/scsi/atp870u.c
@@ -463,13 +463,14 @@  static irqreturn_t atp870u_intr_handle(int irq, void *dev_id)
 			   dev->last_cmd[c] = 0xff;
 			}
 			if (i == 0x16) {
-				workreq->result = atp_readb_io(dev, c, 0x0f);
+				set_status_byte(workreq,
+						atp_readb_io(dev, c, 0x0f));
 				if (((dev->r1f[c][target_id] & 0x10) != 0) && is885(dev)) {
 					printk(KERN_WARNING "AEC67162 CRC ERROR !\n");
-					workreq->result = 0x02;
+					set_status_byte(workreq, SAM_STAT_CHECK_CONDITION);
 				}
 			} else
-				workreq->result = 0x02;
+				set_status_byte(workreq, SAM_STAT_CHECK_CONDITION);
 
 			if (is885(dev)) {
 				j = atp_readb_base(dev, 0x29) | 0x01;
diff --git a/drivers/scsi/dpt_i2o.c b/drivers/scsi/dpt_i2o.c
index 0203dedf2be8..07af610a2410 100644
--- a/drivers/scsi/dpt_i2o.c
+++ b/drivers/scsi/dpt_i2o.c
@@ -2496,7 +2496,7 @@  static s32 adpt_i2o_to_scsi(void __iomem *reply, struct scsi_cmnd* cmd)
 			((struct adpt_device*)(cmd->device->hostdata))->tid, cmd->cmnd[0]);
 	}
 
-	cmd->result |= (dev_status);
+	set_status_byte(cmd, dev_status);
 
 	if(cmd->scsi_done != NULL){
 		cmd->scsi_done(cmd);
diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
index 0a4aa7ad4437..7ad59c8babc6 100644
--- a/drivers/scsi/hpsa.c
+++ b/drivers/scsi/hpsa.c
@@ -2320,7 +2320,7 @@  static int handle_ioaccel_mode2_error(struct ctlr_info *h,
 		case IOACCEL2_STATUS_SR_TASK_COMP_GOOD:
 			break;
 		case IOACCEL2_STATUS_SR_TASK_COMP_CHK_COND:
-			cmd->result |= SAM_STAT_CHECK_CONDITION;
+			set_status_byte(cmd, SAM_STAT_CHECK_CONDITION);
 			if (c2->error_data.data_present !=
 					IOACCEL2_SENSE_DATA_PRESENT) {
 				memset(cmd->sense_buffer, 0,
@@ -2639,7 +2639,7 @@  static void complete_scsi_command(struct CommandList *cp)
 	switch (ei->CommandStatus) {
 
 	case CMD_TARGET_STATUS:
-		cmd->result |= ei->ScsiStatus;
+		set_status_byte(cmd, ei->ScsiStatus);
 		/* copy the sense data */
 		if (SCSI_SENSE_BUFFERSIZE < sizeof(ei->SenseInfo))
 			sense_data_size = SCSI_SENSE_BUFFERSIZE;
diff --git a/drivers/scsi/hptiop.c b/drivers/scsi/hptiop.c
index f4b7f2345491..84bfdc57e7ef 100644
--- a/drivers/scsi/hptiop.c
+++ b/drivers/scsi/hptiop.c
@@ -769,7 +769,7 @@  static void hptiop_finish_scsi_req(struct hptiop_hba *hba, u32 tag,
 	case IOP_RESULT_CHECK_CONDITION:
 		scsi_set_resid(scp,
 			scsi_bufflen(scp) - le32_to_cpu(req->dataxfer_length));
-		scp->result = SAM_STAT_CHECK_CONDITION;
+		set_status_byte(scp, SAM_STAT_CHECK_CONDITION);
 		memcpy(scp->sense_buffer, &req->sg_list, SCSI_SENSE_BUFFERSIZE);
 		goto skip_resid;
 		break;
diff --git a/drivers/scsi/ibmvscsi/ibmvscsi.c b/drivers/scsi/ibmvscsi/ibmvscsi.c
index f79e9e42e10b..a435a1f3bdbd 100644
--- a/drivers/scsi/ibmvscsi/ibmvscsi.c
+++ b/drivers/scsi/ibmvscsi/ibmvscsi.c
@@ -1000,7 +1000,7 @@  static void handle_cmd_rsp(struct srp_event_struct *evt_struct)
 	}
 	
 	if (cmnd) {
-		cmnd->result |= rsp->status;
+		set_status_byte(cmnd, rsp->status);
 		if (((cmnd->result >> 1) & 0x1f) == CHECK_CONDITION)
 			memcpy(cmnd->sense_buffer,
 			       rsp->data,
diff --git a/drivers/scsi/ipr.c b/drivers/scsi/ipr.c
index 817b4e8fc3f0..334fd09c574d 100644
--- a/drivers/scsi/ipr.c
+++ b/drivers/scsi/ipr.c
@@ -6255,7 +6255,7 @@  static void ipr_gen_sense(struct ipr_cmnd *ipr_cmd)
 	if (ioasc >= IPR_FIRST_DRIVER_IOASC)
 		return;
 
-	ipr_cmd->scsi_cmd->result = SAM_STAT_CHECK_CONDITION;
+	set_status_byte(ipr_cmd->scsi_cmd, SAM_STAT_CHECK_CONDITION);
 
 	if (ipr_is_vset_device(res) &&
 	    ioasc == IPR_IOASC_MED_DO_NOT_REALLOC &&
@@ -6410,7 +6410,7 @@  static void ipr_erp_start(struct ipr_ioa_cfg *ioa_cfg,
 		 * exception: do not set DID_PASSTHROUGH on CHECK CONDITION
 		 * so SCSI mid-layer and upper layers handle it accordingly.
 		 */
-		if (scsi_cmd->result != SAM_STAT_CHECK_CONDITION)
+		if (status_byte(scsi_cmd->result) != SAM_STAT_CHECK_CONDITION)
 			set_host_byte(scsi_cmd, DID_PASSTHROUGH);
 		break;
 	case IPR_IOASC_BUS_WAS_RESET:
@@ -6426,7 +6426,7 @@  static void ipr_erp_start(struct ipr_ioa_cfg *ioa_cfg,
 			res->needs_sync_complete = 1;
 		break;
 	case IPR_IOASC_HW_DEV_BUS_STATUS:
-		scsi_cmd->result |= IPR_IOASC_SENSE_STATUS(ioasc);
+		set_status_byte(scsi_cmd, IPR_IOASC_SENSE_STATUS(ioasc));
 		if (IPR_IOASC_SENSE_STATUS(ioasc) == SAM_STAT_CHECK_CONDITION) {
 			if (!ipr_get_autosense(ipr_cmd)) {
 				if (!ipr_is_naca_model(res)) {
diff --git a/drivers/scsi/libfc/fc_fcp.c b/drivers/scsi/libfc/fc_fcp.c
index 9b955a0a77d0..614ab06e5a53 100644
--- a/drivers/scsi/libfc/fc_fcp.c
+++ b/drivers/scsi/libfc/fc_fcp.c
@@ -2064,7 +2064,7 @@  static void fc_io_compl(struct fc_fcp_pkt *fsp)
 				   "due to FC_CMD_ABORTED\n");
 			set_host_byte(sc_cmd, DID_ERROR);
 		}
-		sc_cmd->result |= fsp->io_status;
+		set_status_byte(sc_cmd, fsp->io_status);
 		break;
 	case FC_CMD_RESET:
 		FC_FCP_DBG(fsp, "Returning DID_RESET to scsi-ml "
diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
index 0cc1567eacc1..f87df4a56004 100644
--- a/drivers/scsi/libsas/sas_ata.c
+++ b/drivers/scsi/libsas/sas_ata.c
@@ -136,8 +136,9 @@  static void sas_ata_task_done(struct sas_task *task)
 		}
 	}
 
-	if (stat->stat == SAS_PROTO_RESPONSE || stat->stat == SAM_STAT_GOOD ||
-	    ((stat->stat == SAM_STAT_CHECK_CONDITION &&
+	if (stat->stat == SAS_PROTO_RESPONSE ||
+	    stat->stat == (enum exec_status)SAM_STAT_GOOD ||
+	    ((stat->stat == (enum exec_status) SAM_STAT_CHECK_CONDITION &&
 	      dev->sata_dev.class == ATA_DEV_ATAPI))) {
 		memcpy(dev->sata_dev.fis, resp->ending_fis, ATA_RESP_FIS_SIZE);
 
diff --git a/drivers/scsi/libsas/sas_expander.c b/drivers/scsi/libsas/sas_expander.c
index 8b7114348def..617c32b9378d 100644
--- a/drivers/scsi/libsas/sas_expander.c
+++ b/drivers/scsi/libsas/sas_expander.c
@@ -115,7 +115,7 @@  static int smp_execute_task_sg(struct domain_device *dev,
 			}
 		}
 		if (task->task_status.resp == SAS_TASK_COMPLETE &&
-		    task->task_status.stat == SAM_STAT_GOOD) {
+		    task->task_status.stat == (enum exec_status)SAM_STAT_GOOD) {
 			res = 0;
 			break;
 		}
diff --git a/drivers/scsi/megaraid.c b/drivers/scsi/megaraid.c
index 30671822725a..1cb1b67d08c6 100644
--- a/drivers/scsi/megaraid.c
+++ b/drivers/scsi/megaraid.c
@@ -1608,7 +1608,8 @@  mega_cmd_done(adapter_t *adapter, u8 completed[], int nstatus, int status)
 				} else {
 					cmd->sense_buffer[0] = 0x70;
 					cmd->sense_buffer[2] = ABORTED_COMMAND;
-					cmd->result |= (CHECK_CONDITION << 1);
+					set_status_byte(cmd,
+							(CHECK_CONDITION << 1));
 				}
 			}
 			break;
@@ -1616,7 +1617,7 @@  mega_cmd_done(adapter_t *adapter, u8 completed[], int nstatus, int status)
 		case 0x08:	/* ERR_DEST_DRIVE_FAILED, i.e.
 				   SCSI_STATUS_BUSY */
 			set_host_byte(cmd, DID_BUS_BUSY);
-			cmd->result |= status;
+			set_status_byte(cmd, status);
 			break;
 
 		default:
@@ -1627,7 +1628,8 @@  mega_cmd_done(adapter_t *adapter, u8 completed[], int nstatus, int status)
 			 */
 			if( cmd->cmnd[0] == TEST_UNIT_READY ) {
 				set_host_byte(cmd, DID_ERROR);
-				cmd->result |= (RESERVATION_CONFLICT << 1);
+				set_status_byte(cmd,
+						(RESERVATION_CONFLICT << 1));
 			}
 			else
 			/*
@@ -1639,13 +1641,14 @@  mega_cmd_done(adapter_t *adapter, u8 completed[], int nstatus, int status)
 					 cmd->cmnd[0] == RELEASE) ) {
 
 				set_host_byte(cmd, DID_ERROR);
-				cmd->result |= (RESERVATION_CONFLICT << 1);
+				set_status_byte(cmd,
+						(RESERVATION_CONFLICT << 1));
 			}
 			else
 #endif
 				{
 				set_host_byte(cmd, DID_BAD_TARGET);
-				cmd->result |= status;
+				set_status_byte(cmd, status);
 				}
 		}
 
diff --git a/drivers/scsi/megaraid/megaraid_mbox.c b/drivers/scsi/megaraid/megaraid_mbox.c
index 5684ea95ff9e..975e5a3c3786 100644
--- a/drivers/scsi/megaraid/megaraid_mbox.c
+++ b/drivers/scsi/megaraid/megaraid_mbox.c
@@ -1601,7 +1601,7 @@  megaraid_mbox_build_cmd(adapter_t *adapter, struct scsi_cmnd *scp, int *busy)
 				scp->sense_buffer[0] = 0x70;
 				scp->sense_buffer[2] = ILLEGAL_REQUEST;
 				scp->sense_buffer[12] = MEGA_INVALID_FIELD_IN_CDB;
-				scp->result = CHECK_CONDITION << 1;
+				set_status_byte(scp, CHECK_CONDITION << 1);
 				return NULL;
 			}
 
@@ -2377,7 +2377,7 @@  megaraid_mbox_dpc(unsigned long devp)
 				} else {
 					scp->sense_buffer[0] = 0x70;
 					scp->sense_buffer[2] = ABORTED_COMMAND;
-					scp->result = CHECK_CONDITION << 1;
+					set_status_byte(scp, CHECK_CONDITION << 1);
 				}
 			}
 			break;
diff --git a/drivers/scsi/mpt3sas/mpt3sas_scsih.c b/drivers/scsi/mpt3sas/mpt3sas_scsih.c
index 9fbba196372f..a274970712d3 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_scsih.c
+++ b/drivers/scsi/mpt3sas/mpt3sas_scsih.c
@@ -4650,7 +4650,7 @@  scsih_qcmd(struct Scsi_Host *shost, struct scsi_cmnd *scmd)
 	 */
 	do {
 		if (test_bit(0, &sas_device_priv_data->ata_command_pending)) {
-			scmd->result = SAM_STAT_BUSY;
+			set_status_byte(scmd, SAM_STAT_BUSY);
 			scmd->scsi_done(scmd);
 			return 0;
 		}
@@ -5298,7 +5298,8 @@  _scsih_io_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
 	switch (ioc_status) {
 	case MPI2_IOCSTATUS_BUSY:
 	case MPI2_IOCSTATUS_INSUFFICIENT_RESOURCES:
-		scmd->result = SAM_STAT_BUSY;
+		scmd->result = 0;
+		set_status_byte(scmd, SAM_STAT_BUSY);
 		break;
 
 	case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE:
@@ -5360,9 +5361,10 @@  _scsih_io_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
 			break;
 
 		if (xfer_cnt < scmd->underflow) {
-			if (scsi_status == SAM_STAT_BUSY)
-				scmd->result = SAM_STAT_BUSY;
-			else {
+			if (scsi_status == SAM_STAT_BUSY) {
+				scmd->result = 0;
+				set_status_byte(scmd, SAM_STAT_BUSY);
+			} else {
 				scmd->result = 0;
 				set_host_byte(scmd, DID_SOFT_ERROR);
 			}
diff --git a/drivers/scsi/mvsas/mv_sas.c b/drivers/scsi/mvsas/mv_sas.c
index cff43bd9f675..bdc61b46f8b0 100644
--- a/drivers/scsi/mvsas/mv_sas.c
+++ b/drivers/scsi/mvsas/mv_sas.c
@@ -1333,7 +1333,7 @@  static int mvs_exec_internal_tmf_task(struct domain_device *dev,
 		}
 
 		if (task->task_status.resp == SAS_TASK_COMPLETE &&
-		    task->task_status.stat == SAM_STAT_GOOD) {
+		    task->task_status.stat == (enum exec_status)SAM_STAT_GOOD) {
 			res = TMF_RESP_FUNC_COMPLETE;
 			break;
 		}
diff --git a/drivers/scsi/mvumi.c b/drivers/scsi/mvumi.c
index 21d30c572271..9cf3c83d9f08 100644
--- a/drivers/scsi/mvumi.c
+++ b/drivers/scsi/mvumi.c
@@ -1316,7 +1316,7 @@  static void mvumi_complete_cmd(struct mvumi_hba *mhba, struct mvumi_cmd *cmd,
 	struct scsi_cmnd *scmd = cmd->scmd;
 
 	cmd->scmd->SCp.ptr = NULL;
-	scmd->result = ob_frame->req_status;
+	set_status_byte(scmd, ob_frame->req_status);
 
 	switch (ob_frame->req_status) {
 	case SAM_STAT_GOOD:
diff --git a/drivers/scsi/pm8001/pm8001_sas.c b/drivers/scsi/pm8001/pm8001_sas.c
index 947d6017d004..7ad7bc1deebc 100644
--- a/drivers/scsi/pm8001/pm8001_sas.c
+++ b/drivers/scsi/pm8001/pm8001_sas.c
@@ -727,7 +727,8 @@  static int pm8001_exec_internal_tmf_task(struct domain_device *dev,
 		}
 
 		if (task->task_status.resp == SAS_TASK_COMPLETE &&
-			task->task_status.stat == SAM_STAT_GOOD) {
+			task->task_status.stat ==
+				(enum exec_status)SAM_STAT_GOOD) {
 			res = TMF_RESP_FUNC_COMPLETE;
 			break;
 		}
@@ -816,7 +817,7 @@  pm8001_exec_internal_task_abort(struct pm8001_hba_info *pm8001_ha,
 		}
 
 		if (task->task_status.resp == SAS_TASK_COMPLETE &&
-			task->task_status.stat == SAM_STAT_GOOD) {
+		    task->task_status.stat == (enum exec_status)SAM_STAT_GOOD) {
 			res = TMF_RESP_FUNC_COMPLETE;
 			break;
 
diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
index a1ae3d2219c3..91ffbf6977b4 100644
--- a/drivers/scsi/pmcraid.c
+++ b/drivers/scsi/pmcraid.c
@@ -2541,7 +2541,7 @@  static void pmcraid_frame_auto_sense(struct pmcraid_cmd *cmd)
 	u32 failing_lba = 0;
 
 	memset(sense_buf, 0, SCSI_SENSE_BUFFERSIZE);
-	cmd->scsi_cmd->result = SAM_STAT_CHECK_CONDITION;
+	set_status_byte(cmd->scsi_cmd, SAM_STAT_CHECK_CONDITION);
 
 	if (RES_IS_VSET(res->cfg_entry) &&
 	    ioasc == PMCRAID_IOASC_ME_READ_ERROR_NO_REALLOC &&
@@ -2662,7 +2662,7 @@  static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
 		break;
 
 	case PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR:
-		scsi_cmd->result |= PMCRAID_IOASC_SENSE_STATUS(ioasc);
+		set_status_byte(scsi_cmd, PMCRAID_IOASC_SENSE_STATUS(ioasc));
 		res->sync_reqd = 1;
 
 		/* if check_condition is not active return with error otherwise
diff --git a/drivers/scsi/qla1280.c b/drivers/scsi/qla1280.c
index a979089a23ab..9c1418cf9f6d 100644
--- a/drivers/scsi/qla1280.c
+++ b/drivers/scsi/qla1280.c
@@ -3707,7 +3707,7 @@  qla1280_status_entry(struct scsi_qla_host *ha, struct response *pkt,
 	/* Target busy or queue full */
 	if ((scsi_status & 0xFF) == SAM_STAT_TASK_SET_FULL ||
 	    (scsi_status & 0xFF) == SAM_STAT_BUSY) {
-		CMD_RESULT(cmd) = scsi_status & 0xff;
+		set_status_byte(cmd, scsi_status & 0xff);
 	} else {
 
 		/* Save ISP completion status */
diff --git a/drivers/scsi/qla2xxx/qla_isr.c b/drivers/scsi/qla2xxx/qla_isr.c
index 27050f593934..8370ca5b2bf9 100644
--- a/drivers/scsi/qla2xxx/qla_isr.c
+++ b/drivers/scsi/qla2xxx/qla_isr.c
@@ -2175,7 +2175,7 @@  qla2x00_handle_dif_error(srb_t *sp, struct sts_entry_24xx *sts24)
 		    0x10, 0x1);
 		set_driver_byte(cmd, DRIVER_SENSE);
 		set_host_byte(cmd, DID_ABORT);
-		cmd->result |= SAM_STAT_CHECK_CONDITION;
+		set_status_byte(cmd, SAM_STAT_CHECK_CONDITION);
 		return 1;
 	}
 
@@ -2185,7 +2185,7 @@  qla2x00_handle_dif_error(srb_t *sp, struct sts_entry_24xx *sts24)
 		    0x10, 0x3);
 		set_driver_byte(cmd, DRIVER_SENSE);
 		set_host_byte(cmd, DID_ABORT);
-		cmd->result |= SAM_STAT_CHECK_CONDITION;
+		set_status_byte(cmd, SAM_STAT_CHECK_CONDITION);
 		return 1;
 	}
 
@@ -2195,7 +2195,7 @@  qla2x00_handle_dif_error(srb_t *sp, struct sts_entry_24xx *sts24)
 		    0x10, 0x2);
 		set_driver_byte(cmd, DRIVER_SENSE);
 		set_host_byte(cmd, DID_ABORT);
-		cmd->result |= SAM_STAT_CHECK_CONDITION;
+		set_status_byte(cmd, SAM_STAT_CHECK_CONDITION);
 		return 1;
 	}
 
diff --git a/drivers/scsi/scsi_error.c b/drivers/scsi/scsi_error.c
index 02e9865501af..9955b05121f5 100644
--- a/drivers/scsi/scsi_error.c
+++ b/drivers/scsi/scsi_error.c
@@ -713,31 +713,31 @@  static int scsi_eh_completed_normally(struct scsi_cmnd *scmd)
 	 * anything special.
 	 */
 	switch (status_byte(scmd->result)) {
-	case GOOD:
+	case SAM_STAT_GOOD:
 		scsi_handle_queue_ramp_up(scmd->device);
 		/* FALLTHROUGH */
-	case COMMAND_TERMINATED:
+	case SAM_STAT_COMMAND_TERMINATED:
 		return SUCCESS;
-	case CHECK_CONDITION:
+	case SAM_STAT_CHECK_CONDITION:
 		return scsi_check_sense(scmd);
-	case CONDITION_GOOD:
-	case INTERMEDIATE_GOOD:
-	case INTERMEDIATE_C_GOOD:
+	case SAM_STAT_CONDITION_MET:
+	case SAM_STAT_INTERMEDIATE:
+	case SAM_STAT_INTERMEDIATE_CONDITION_MET:
 		/*
 		 * who knows?  FIXME(eric)
 		 */
 		return SUCCESS;
-	case RESERVATION_CONFLICT:
+	case SAM_STAT_RESERVATION_CONFLICT:
 		if (scmd->cmnd[0] == TEST_UNIT_READY)
 			/* it is a success, we probed the device and
 			 * found it */
 			return SUCCESS;
 		/* otherwise, we failed to send the command */
 		return FAILED;
-	case QUEUE_FULL:
+	case SAM_STAT_TASK_SET_FULL:
 		scsi_handle_queue_full(scmd->device);
 		/* fall through */
-	case BUSY:
+	case SAM_STAT_BUSY:
 		return NEEDS_RETRY;
 	default:
 		return FAILED;
@@ -1845,14 +1845,14 @@  int scsi_decide_disposition(struct scsi_cmnd *scmd)
 	 * check the status byte to see if this indicates anything special.
 	 */
 	switch (status_byte(scmd->result)) {
-	case QUEUE_FULL:
+	case SAM_STAT_TASK_SET_FULL:
 		scsi_handle_queue_full(scmd->device);
 		/*
 		 * the case of trying to send too many commands to a
 		 * tagged queueing device.
 		 */
 		/* FALLTHROUGH */
-	case BUSY:
+	case SAM_STAT_BUSY:
 		/*
 		 * device can't talk to us at the moment.  Should only
 		 * occur (SAM-3) when the task queue is empty, so will cause
@@ -1860,16 +1860,16 @@  int scsi_decide_disposition(struct scsi_cmnd *scmd)
 		 * device.
 		 */
 		return ADD_TO_MLQUEUE;
-	case GOOD:
+	case SAM_STAT_GOOD:
 		if (scmd->cmnd[0] == REPORT_LUNS)
 			scmd->device->sdev_target->expecting_lun_change = 0;
 		scsi_handle_queue_ramp_up(scmd->device);
 		/* FALLTHROUGH */
-	case COMMAND_TERMINATED:
+	case SAM_STAT_COMMAND_TERMINATED:
 		return SUCCESS;
-	case TASK_ABORTED:
+	case SAM_STAT_TASK_ABORTED:
 		goto maybe_retry;
-	case CHECK_CONDITION:
+	case SAM_STAT_CHECK_CONDITION:
 		rtn = scsi_check_sense(scmd);
 		if (rtn == NEEDS_RETRY)
 			goto maybe_retry;
@@ -1878,16 +1878,16 @@  int scsi_decide_disposition(struct scsi_cmnd *scmd)
 		 * to collect the sense and redo the decide
 		 * disposition */
 		return rtn;
-	case CONDITION_GOOD:
-	case INTERMEDIATE_GOOD:
-	case INTERMEDIATE_C_GOOD:
-	case ACA_ACTIVE:
+	case SAM_STAT_CONDITION_MET:
+	case SAM_STAT_INTERMEDIATE:
+	case SAM_STAT_INTERMEDIATE_CONDITION_MET:
+	case SAM_STAT_ACA_ACTIVE:
 		/*
 		 * who knows?  FIXME(eric)
 		 */
 		return SUCCESS;
 
-	case RESERVATION_CONFLICT:
+	case SAM_STAT_RESERVATION_CONFLICT:
 		sdev_printk(KERN_INFO, scmd->device,
 			    "reservation conflict\n");
 		set_host_byte(scmd, DID_NEXUS_FAILURE);
diff --git a/drivers/scsi/smartpqi/smartpqi_init.c b/drivers/scsi/smartpqi/smartpqi_init.c
index 592b6dbf8b35..5ef2ecbe75ec 100644
--- a/drivers/scsi/smartpqi/smartpqi_init.c
+++ b/drivers/scsi/smartpqi/smartpqi_init.c
@@ -2553,7 +2553,7 @@  static void pqi_process_raid_io_error(struct pqi_io_request *io_request)
 			sense_data_length);
 	}
 
-	scmd->result = scsi_status;
+	set_status_byte(scmd, scsi_status);
 	set_host_byte(scmd, host_byte);
 }
 
@@ -2643,7 +2643,7 @@  static void pqi_process_aio_io_error(struct pqi_io_request *io_request)
 		scsi_build_sense_buffer(0, scmd->sense_buffer, HARDWARE_ERROR,
 			0x3e, 0x1);
 
-	scmd->result = scsi_status;
+	set_status_byte(scmd, scsi_status);
 	set_host_byte(scmd, host_byte);
 }
 
@@ -4665,7 +4665,7 @@  static bool pqi_raid_bypass_retry_needed(struct pqi_io_request *io_request)
 		return false;
 
 	scmd = io_request->scmd;
-	if ((scmd->result & 0xff) == SAM_STAT_GOOD)
+	if (status_byte(scmd->result) == SAM_STAT_GOOD)
 		return false;
 	if (host_byte(scmd->result) == DID_NO_CONNECT)
 		return false;
diff --git a/drivers/scsi/storvsc_drv.c b/drivers/scsi/storvsc_drv.c
index c8041f514294..6a5ca510a3b8 100644
--- a/drivers/scsi/storvsc_drv.c
+++ b/drivers/scsi/storvsc_drv.c
@@ -1010,7 +1010,7 @@  static void storvsc_command_completion(struct storvsc_cmd_request *cmd_request,
 	vm_srb = &cmd_request->vstor_packet.vm_srb;
 	data_transfer_length = vm_srb->data_transfer_length;
 
-	scmnd->result = vm_srb->scsi_status;
+	set_status_byte(scmnd, vm_srb->scsi_status);
 
 	if (scmnd->result) {
 		if (scsi_normalize_sense(scmnd->sense_buffer,
diff --git a/drivers/scsi/virtio_scsi.c b/drivers/scsi/virtio_scsi.c
index 45d04631888a..df5ddee8ab76 100644
--- a/drivers/scsi/virtio_scsi.c
+++ b/drivers/scsi/virtio_scsi.c
@@ -154,7 +154,7 @@  static void virtscsi_complete_cmd(struct virtio_scsi *vscsi, void *buf)
 		"cmd %p response %u status %#02x sense_len %u\n",
 		sc, resp->response, resp->status, resp->sense_len);
 
-	sc->result = resp->status;
+	set_status_byte(sc, resp->status);
 	virtscsi_compute_resid(sc, virtio32_to_cpu(vscsi->vdev, resp->resid));
 	switch (resp->response) {
 	case VIRTIO_SCSI_S_OK:
diff --git a/drivers/staging/rts5208/rtsx_transport.c b/drivers/staging/rts5208/rtsx_transport.c
index 5adaa744a8d0..4838a6e67758 100644
--- a/drivers/staging/rts5208/rtsx_transport.c
+++ b/drivers/staging/rts5208/rtsx_transport.c
@@ -185,7 +185,7 @@  void rtsx_invoke_transport(struct scsi_cmnd *srb, struct rtsx_chip *chip)
 		goto handle_errors;
 	}
 
-	srb->result = SAM_STAT_GOOD;
+	set_status_byte(srb, SAM_STAT_GOOD);
 
 	/*
 	 * If we have a failure, we're going to do a REQUEST_SENSE
@@ -194,7 +194,7 @@  void rtsx_invoke_transport(struct scsi_cmnd *srb, struct rtsx_chip *chip)
 	 */
 	if (result == TRANSPORT_FAILED) {
 		/* set the result so the higher layers expect this data */
-		srb->result = SAM_STAT_CHECK_CONDITION;
+		set_status_byte(srb, SAM_STAT_CHECK_CONDITION);
 		memcpy(srb->sense_buffer,
 		       (unsigned char *)&chip->sense_buffer[SCSI_LUN(srb)],
 		       sizeof(struct sense_data_t));
diff --git a/drivers/target/loopback/tcm_loop.c b/drivers/target/loopback/tcm_loop.c
index 60d5b918c4ac..eca8dc245099 100644
--- a/drivers/target/loopback/tcm_loop.c
+++ b/drivers/target/loopback/tcm_loop.c
@@ -582,7 +582,7 @@  static int tcm_loop_queue_data_in(struct se_cmd *se_cmd)
 	pr_debug("%s() called for scsi_cmnd: %p cdb: 0x%02x\n",
 		 __func__, sc, sc->cmnd[0]);
 
-	sc->result = SAM_STAT_GOOD;
+	set_status_byte(sc, SAM_STAT_GOOD);
 	set_host_byte(sc, DID_OK);
 	if ((se_cmd->se_cmd_flags & SCF_OVERFLOW_BIT) ||
 	    (se_cmd->se_cmd_flags & SCF_UNDERFLOW_BIT))
@@ -606,10 +606,10 @@  static int tcm_loop_queue_status(struct se_cmd *se_cmd)
 
 		memcpy(sc->sense_buffer, se_cmd->sense_buffer,
 				SCSI_SENSE_BUFFERSIZE);
-		sc->result = SAM_STAT_CHECK_CONDITION;
+		set_status_byte(sc, SAM_STAT_CHECK_CONDITION);
 		set_driver_byte(sc, DRIVER_SENSE);
 	} else
-		sc->result = se_cmd->scsi_status;
+		set_status_byte(sc, se_cmd->scsi_status);
 
 	set_host_byte(sc, DID_OK);
 	if ((se_cmd->se_cmd_flags & SCF_OVERFLOW_BIT) ||
diff --git a/drivers/usb/image/microtek.c b/drivers/usb/image/microtek.c
index f4ab82582fb0..1c36b23a5628 100644
--- a/drivers/usb/image/microtek.c
+++ b/drivers/usb/image/microtek.c
@@ -406,10 +406,11 @@  static void mts_transfer_cleanup( struct urb *transfer )
 
 static void mts_transfer_done( struct urb *transfer )
 {
+	enum status_byte scsi_stauts;
 	MTS_INT_INIT();
 
-	context->srb->result &= MTS_SCSI_ERR_MASK;
-	context->srb->result |= (unsigned)(*context->scsi_status)<<1;
+	scsi_status = (enum status_byte)(*context->scsi_status) << 1);
+	set_status_byte(context->srb, scsi_status);
 
 	mts_transfer_cleanup(transfer);
 }
diff --git a/drivers/usb/storage/datafab.c b/drivers/usb/storage/datafab.c
index 09353be199be..ead9f68fcfec 100644
--- a/drivers/usb/storage/datafab.c
+++ b/drivers/usb/storage/datafab.c
@@ -701,10 +701,10 @@  static int datafab_transport(struct scsi_cmnd *srb, struct us_data *us)
 		rc = datafab_id_device(us, info);
 		if (rc == USB_STOR_TRANSPORT_GOOD) {
 			info->sense_key = NO_SENSE;
-			srb->result = SUCCESS;
+			set_status_byte(srb, SAM_STAT_GOOD);
 		} else {
 			info->sense_key = UNIT_ATTENTION;
-			srb->result = SAM_STAT_CHECK_CONDITION;
+			set_status_byte(srb, SAM_STAT_CHECK_CONDITION);
 		}
 		return rc;
 	}
diff --git a/drivers/usb/storage/isd200.c b/drivers/usb/storage/isd200.c
index aa82a38c5bcc..ee1b4dabea88 100644
--- a/drivers/usb/storage/isd200.c
+++ b/drivers/usb/storage/isd200.c
@@ -629,12 +629,12 @@  static void isd200_invoke_transport( struct us_data *us,
 
 	case USB_STOR_TRANSPORT_GOOD:
 		/* Indicate a good result */
-		srb->result = SAM_STAT_GOOD;
+		set_status_byte(srb, SAM_STAT_GOOD);
 		break;
 
 	case USB_STOR_TRANSPORT_NO_SENSE:
 		usb_stor_dbg(us, "-- transport indicates protocol failure\n");
-		srb->result = SAM_STAT_CHECK_CONDITION;
+		set_status_byte(srb, SAM_STAT_CHECK_CONDITION);
 		return;
 
 	case USB_STOR_TRANSPORT_FAILED:
@@ -675,11 +675,11 @@  static void isd200_invoke_transport( struct us_data *us,
 		}
 		if (result == ISD200_GOOD) {
 			isd200_build_sense(us, srb);
-			srb->result = SAM_STAT_CHECK_CONDITION;
+			set_status_byte(srb, SAM_STAT_CHECK_CONDITION);
 
 			/* If things are really okay, then let's show that */
 			if ((srb->sense_buffer[2] & 0xf) == 0x0)
-				srb->result = SAM_STAT_GOOD;
+				set_status_byte(srb, SAM_STAT_GOOD);
 		} else {
 			srb->result = 0;
 			set_host_byte(srb, DID_ERROR);
@@ -692,7 +692,7 @@  static void isd200_invoke_transport( struct us_data *us,
 	 * condition, show that in the result code
 	 */
 	if (transferStatus == USB_STOR_TRANSPORT_FAILED)
-		srb->result = SAM_STAT_CHECK_CONDITION;
+		set_status_byte(srb, SAM_STAT_CHECK_CONDITION);
 	return;
 
 	/*
@@ -1241,7 +1241,7 @@  static int isd200_scsi_to_ata(struct scsi_cmnd *srb, struct us_data *us,
 		/* copy InquiryData */
 		usb_stor_set_xfer_buf((unsigned char *) &info->InquiryData,
 				sizeof(info->InquiryData), srb);
-		srb->result = SAM_STAT_GOOD;
+		set_status_byte(srb, SAM_STAT_GOOD);
 		sendToTransport = 0;
 		break;
 
@@ -1261,7 +1261,7 @@  static int isd200_scsi_to_ata(struct scsi_cmnd *srb, struct us_data *us,
 			isd200_srb_set_bufflen(srb, 0);
 		} else {
 			usb_stor_dbg(us, "   Media Status not supported, just report okay\n");
-			srb->result = SAM_STAT_GOOD;
+			set_status_byte(srb, SAM_STAT_GOOD);
 			sendToTransport = 0;
 		}
 		break;
@@ -1279,7 +1279,7 @@  static int isd200_scsi_to_ata(struct scsi_cmnd *srb, struct us_data *us,
 			isd200_srb_set_bufflen(srb, 0);
 		} else {
 			usb_stor_dbg(us, "   Media Status not supported, just report okay\n");
-			srb->result = SAM_STAT_GOOD;
+			set_status_byte(srb, SAM_STAT_GOOD);
 			sendToTransport = 0;
 		}
 		break;
@@ -1302,7 +1302,7 @@  static int isd200_scsi_to_ata(struct scsi_cmnd *srb, struct us_data *us,
 
 		usb_stor_set_xfer_buf((unsigned char *) &readCapacityData,
 				sizeof(readCapacityData), srb);
-		srb->result = SAM_STAT_GOOD;
+		set_status_byte(srb, SAM_STAT_GOOD);
 		sendToTransport = 0;
 	}
 	break;
@@ -1387,7 +1387,7 @@  static int isd200_scsi_to_ata(struct scsi_cmnd *srb, struct us_data *us,
 			isd200_srb_set_bufflen(srb, 0);
 		} else {
 			usb_stor_dbg(us, "   Not removeable media, just report okay\n");
-			srb->result = SAM_STAT_GOOD;
+			set_status_byte(srb, SAM_STAT_GOOD);
 			sendToTransport = 0;
 		}
 		break;
@@ -1413,7 +1413,7 @@  static int isd200_scsi_to_ata(struct scsi_cmnd *srb, struct us_data *us,
 			isd200_srb_set_bufflen(srb, 0);
 		} else {
 			usb_stor_dbg(us, "   Nothing to do, just report okay\n");
-			srb->result = SAM_STAT_GOOD;
+			set_status_byte(srb, SAM_STAT_GOOD);
 			sendToTransport = 0;
 		}
 		break;
diff --git a/drivers/usb/storage/jumpshot.c b/drivers/usb/storage/jumpshot.c
index 917f170c4124..4ff061b39831 100644
--- a/drivers/usb/storage/jumpshot.c
+++ b/drivers/usb/storage/jumpshot.c
@@ -626,10 +626,10 @@  static int jumpshot_transport(struct scsi_cmnd *srb, struct us_data *us)
 		rc = jumpshot_id_device(us, info);
 		if (rc == USB_STOR_TRANSPORT_GOOD) {
 			info->sense_key = NO_SENSE;
-			srb->result = SUCCESS;
+			set_status_byte(srb, SAM_STAT_GOOD);
 		} else {
 			info->sense_key = UNIT_ATTENTION;
-			srb->result = SAM_STAT_CHECK_CONDITION;
+			set_status_byte(srb, SAM_STAT_CHECK_CONDITION);
 		}
 		return rc;
 	}
diff --git a/drivers/usb/storage/realtek_cr.c b/drivers/usb/storage/realtek_cr.c
index 31b024441938..497fca11470c 100644
--- a/drivers/usb/storage/realtek_cr.c
+++ b/drivers/usb/storage/realtek_cr.c
@@ -824,9 +824,10 @@  static void rts51x_invoke_transport(struct scsi_cmnd *srb, struct us_data *us)
 			if ((srb->cmnd[0] == TEST_UNIT_READY) &&
 			    (chip->pwr_state == US_SUSPEND)) {
 				if (TST_LUN_READY(chip, srb->device->lun)) {
-					srb->result = SAM_STAT_GOOD;
+					set_status_byte(srb, SAM_STAT_GOOD);
 				} else {
-					srb->result = SAM_STAT_CHECK_CONDITION;
+					set_status_byte(srb,
+							SAM_STAT_CHECK_CONDITION);
 					memcpy(srb->sense_buffer,
 					       media_not_present,
 					       US_SENSE_SIZE);
@@ -837,12 +838,13 @@  static void rts51x_invoke_transport(struct scsi_cmnd *srb, struct us_data *us)
 			if (srb->cmnd[0] == ALLOW_MEDIUM_REMOVAL) {
 				int prevent = srb->cmnd[4] & 0x1;
 				if (prevent) {
-					srb->result = SAM_STAT_CHECK_CONDITION;
+					set_status_byte(srb,
+							SAM_STAT_CHECK_CONDITION);
 					memcpy(srb->sense_buffer,
 					       invalid_cmd_field,
 					       US_SENSE_SIZE);
 				} else {
-					srb->result = SAM_STAT_GOOD;
+					set_status_byte(srb, SAM_STAT_GOOD);
 				}
 				usb_stor_dbg(us, "ALLOW_MEDIUM_REMOVAL\n");
 				goto out;
@@ -852,7 +854,7 @@  static void rts51x_invoke_transport(struct scsi_cmnd *srb, struct us_data *us)
 			chip->proto_handler_backup(srb, us);
 			/* Check whether card is plugged in */
 			if (srb->cmnd[0] == TEST_UNIT_READY) {
-				if (srb->result == SAM_STAT_GOOD) {
+				if (status_byte(srb->result) == SAM_STAT_GOOD) {
 					SET_LUN_READY(chip, srb->device->lun);
 					if (card_first_show) {
 						card_first_show = 0;
diff --git a/drivers/usb/storage/transport.c b/drivers/usb/storage/transport.c
index 5413ddc3ce20..e295e9290c04 100644
--- a/drivers/usb/storage/transport.c
+++ b/drivers/usb/storage/transport.c
@@ -575,7 +575,7 @@  static void last_sector_hacks(struct us_data *us, struct scsi_cmnd *srb)
 		 */
 		if (++us->last_sector_retries < 3)
 			return;
-		srb->result = SAM_STAT_CHECK_CONDITION;
+		set_status_byte(srb, SAM_STAT_CHECK_CONDITION);
 		memcpy(srb->sense_buffer, record_not_found,
 				sizeof(record_not_found));
 	}
@@ -626,12 +626,12 @@  void usb_stor_invoke_transport(struct scsi_cmnd *srb, struct us_data *us)
 
 	/* if the transport provided its own sense data, don't auto-sense */
 	if (result == USB_STOR_TRANSPORT_NO_SENSE) {
-		srb->result = SAM_STAT_CHECK_CONDITION;
+		set_status_byte(srb, SAM_STAT_CHECK_CONDITION);
 		last_sector_hacks(us, srb);
 		return;
 	}
 
-	srb->result = SAM_STAT_GOOD;
+	set_status_byte(srb, SAM_STAT_GOOD);
 
 	/*
 	 * Determine if we need to auto-sense
@@ -801,7 +801,7 @@  void usb_stor_invoke_transport(struct scsi_cmnd *srb, struct us_data *us)
 #endif
 
 		/* set the result so the higher layers expect this data */
-		srb->result = SAM_STAT_CHECK_CONDITION;
+		set_status_byte(srb, SAM_STAT_CHECK_CONDITION);
 
 		scdd = scsi_sense_desc_find(srb->sense_buffer,
 					    SCSI_SENSE_BUFFERSIZE, 4);
@@ -820,7 +820,7 @@  void usb_stor_invoke_transport(struct scsi_cmnd *srb, struct us_data *us)
 			 * won't realize we did an unsolicited auto-sense.
 			 */
 			if (result == USB_STOR_TRANSPORT_GOOD) {
-				srb->result = SAM_STAT_GOOD;
+				set_status_byte(srb, SAM_STAT_GOOD);
 				srb->sense_buffer[0] = 0x0;
 			}
 
@@ -861,7 +861,7 @@  void usb_stor_invoke_transport(struct scsi_cmnd *srb, struct us_data *us)
 	 */
 	if (unlikely((us->fflags & US_FL_INITIAL_READ10) &&
 			srb->cmnd[0] == READ_10)) {
-		if (srb->result == SAM_STAT_GOOD) {
+		if (status_byte(srb->result) == SAM_STAT_GOOD) {
 			set_bit(US_FLIDX_READ10_WORKED, &us->dflags);
 		} else if (test_bit(US_FLIDX_READ10_WORKED, &us->dflags)) {
 			clear_bit(US_FLIDX_READ10_WORKED, &us->dflags);
@@ -882,8 +882,9 @@  void usb_stor_invoke_transport(struct scsi_cmnd *srb, struct us_data *us)
 	}
 
 	/* Did we transfer less than the minimum amount required? */
-	if ((srb->result == SAM_STAT_GOOD || srb->sense_buffer[2] == 0) &&
-			scsi_bufflen(srb) - scsi_get_resid(srb) < srb->underflow) {
+	if ((status_byte(srb->result) == SAM_STAT_GOOD ||
+	     srb->sense_buffer[2] == 0) &&
+	    scsi_bufflen(srb) - scsi_get_resid(srb) < srb->underflow) {
 		srb->result = 0;
 		set_host_byte(srb, DID_ERROR);
 	}
diff --git a/drivers/usb/storage/uas.c b/drivers/usb/storage/uas.c
index 20d183b105f6..9aa60d935ce5 100644
--- a/drivers/usb/storage/uas.c
+++ b/drivers/usb/storage/uas.c
@@ -170,7 +170,7 @@  static void uas_sense(struct urb *urb, struct scsi_cmnd *cmnd)
 		memcpy(cmnd->sense_buffer, sense_iu->sense, len);
 	}
 
-	cmnd->result = sense_iu->status;
+	set_status_byte(cmnd, sense_iu->status);
 }
 
 static void uas_log_cmd_state(struct scsi_cmnd *cmnd, const char *prefix,
@@ -636,7 +636,7 @@  static int uas_queuecommand_lck(struct scsi_cmnd *cmnd,
 			(cmnd->cmnd[0] == ATA_12 || cmnd->cmnd[0] == ATA_16)) {
 		memcpy(cmnd->sense_buffer, usb_stor_sense_invalidCDB,
 		       sizeof(usb_stor_sense_invalidCDB));
-		cmnd->result = SAM_STAT_CHECK_CONDITION;
+		set_status_byte(cmnd, SAM_STAT_CHECK_CONDITION);
 		cmnd->scsi_done(cmnd);
 		return 0;
 	}
diff --git a/drivers/usb/storage/usb.c b/drivers/usb/storage/usb.c
index d538aaed5f80..a4794feb2aec 100644
--- a/drivers/usb/storage/usb.c
+++ b/drivers/usb/storage/usb.c
@@ -375,7 +375,7 @@  static int usb_stor_control_thread(void * __us)
 
 			usb_stor_dbg(us, "Faking INQUIRY command\n");
 			fill_inquiry_response(us, data_ptr, 36);
-			srb->result = SAM_STAT_GOOD;
+			set_status_byte(srb, SAM_STAT_GOOD);
 		}
 
 		/* we've got a command, let's do it! */
diff --git a/include/scsi/scsi.h b/include/scsi/scsi.h
index f51320dfac9b..bec7c345191c 100644
--- a/include/scsi/scsi.h
+++ b/include/scsi/scsi.h
@@ -213,7 +213,11 @@  enum scsi_driver_byte {
  *      host_byte   = set by low-level driver to indicate status.
  *      driver_byte = set by mid-level.
  */
-#define status_byte(result) (((result) >> 1) & 0x7f)
+static inline enum scsi_status_byte status_byte(int result)
+{
+	return (result >> 1) & 0x7f;
+}
+
 static inline enum scsi_msg_byte msg_byte(int result)
 {
 	return (result >> 8) & 0xff;
diff --git a/include/scsi/scsi_cmnd.h b/include/scsi/scsi_cmnd.h
index 64342100ba4a..32bc3e5fad53 100644
--- a/include/scsi/scsi_cmnd.h
+++ b/include/scsi/scsi_cmnd.h
@@ -355,6 +355,12 @@  static inline void set_driver_byte(struct scsi_cmnd *cmd,
 	cmd->result = (cmd->result & 0x00ffffff) | (status << 24);
 }
 
+static inline void set_status_byte(struct scsi_cmnd *cmd,
+				   char status)
+{
+	cmd->result = (cmd->result & 0xffffff00) | status;
+}
+
 static inline void set_scsi_result(struct scsi_cmnd *cmd,
 				   enum scsi_driver_byte db,
 				   enum scsi_host_byte hb,
diff --git a/include/scsi/scsi_proto.h b/include/scsi/scsi_proto.h
index c36860111932..b9bb937a5679 100644
--- a/include/scsi/scsi_proto.h
+++ b/include/scsi/scsi_proto.h
@@ -190,18 +190,19 @@  struct scsi_varlen_cdb_hdr {
  *  SCSI Architecture Model (SAM) Status codes. Taken from SAM-3 draft
  *  T10/1561-D Revision 4 Draft dated 7th November 2002.
  */
-#define SAM_STAT_GOOD            0x00
-#define SAM_STAT_CHECK_CONDITION 0x02
-#define SAM_STAT_CONDITION_MET   0x04
-#define SAM_STAT_BUSY            0x08
-#define SAM_STAT_INTERMEDIATE    0x10
-#define SAM_STAT_INTERMEDIATE_CONDITION_MET 0x14
-#define SAM_STAT_RESERVATION_CONFLICT 0x18
-#define SAM_STAT_COMMAND_TERMINATED 0x22	/* obsolete in SAM-3 */
-#define SAM_STAT_TASK_SET_FULL   0x28
-#define SAM_STAT_ACA_ACTIVE      0x30
-#define SAM_STAT_TASK_ABORTED    0x40
-
+enum scsi_status_byte {
+	SAM_STAT_GOOD            = 0x00,
+	SAM_STAT_CHECK_CONDITION = 0x02,
+	SAM_STAT_CONDITION_MET   = 0x04,
+	SAM_STAT_BUSY            = 0x08,
+	SAM_STAT_INTERMEDIATE    = 0x10,
+	SAM_STAT_INTERMEDIATE_CONDITION_MET = 0x14,
+	SAM_STAT_RESERVATION_CONFLICT = 0x18,
+	SAM_STAT_COMMAND_TERMINATED = 0x22,	/* obsolete in SAM-3 */
+	SAM_STAT_TASK_SET_FULL   = 0x28,
+	SAM_STAT_ACA_ACTIVE      = 0x30,
+	SAM_STAT_TASK_ABORTED    = 0x40,
+};
 /*
  *  Status codes. These are deprecated as they are shifted 1 bit right
  *  from those found in the SCSI standards. This causes confusion for