diff mbox

[VERY,EARLY,RFC,06/13] scsi: introduce set_scsi_result

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

Commit Message

Johannes Thumshirn April 18, 2018, 3:01 p.m. UTC
Introduce set_scsi_result() for setting the bytes of the scsi_cmnd's result
filed and flip over all users that set at least two bytes to using it.

The conversion has been done using the following coccinelle spatch:
<SmPL>
@@
struct scsi_cmnd *c;
expression E1, E2, E3, E4;
@@

(
- c->result = E1 << 24 | E2 << 16 | E3 << 8 | E4;
+ set_scsi_result(c, E1, E2, E3, E4);
|
- c->result = E1 << 24 | E2 << 16 | E3 << 8;
+ set_scsi_result(c, E1, E2, E3, 0);
|
- c->result = E2 << 16 | E3 << 8 | E4;
+ set_scsi_result(c, 0, E2, E3, E4);
|
- c->result = E2 << 16 | E3 << 8;
+ set_scsi_result(c, 0, E2, E3, 0);
|
- c->result = (E2 << 16) | E4;
+ set_scsi_result(c, 0, E2, 0, E4);
|
- c->result = (E2 << 16) | (E4);
+ set_scsi_result(c, 0, E2, 0, E4);
)

@@
struct scsi_cmnd *c;
expression E1, E2;
identifier ScsiResult;
@@

-c->result = ScsiResult(E1, E2);
+set_scsi_result(c, 0, E1, 0, E2);

@@
identifier ScsiResult, host_code,scsi_code;
@@
(
-#define ScsiResult(host_code, scsi_code) (((host_code) << 16) | scsi_code)
|
-#define ScsiResult(host_code, scsi_code) (((host_code) << 16) + ((scsi_code) & 0x7f))
)
</SmPL>

Signed-off-by: Johannes Thumshirn <jthumshirn@suse.de>
---
 drivers/ata/libata-scsi.c                   |   8 +-
 drivers/infiniband/ulp/srp/ib_srp.c         |   7 +-
 drivers/message/fusion/mptscsih.c           |   6 +-
 drivers/scsi/3w-9xxx.c                      |   3 +-
 drivers/scsi/3w-xxxx.c                      |   9 +-
 drivers/scsi/NCR5380.c                      |   6 +-
 drivers/scsi/a100u2w.c                      |   2 +-
 drivers/scsi/aacraid/aachba.c               | 200 +++++++++++++++-------------
 drivers/scsi/aacraid/commsup.c              |   5 +-
 drivers/scsi/advansys.c                     |  26 ++--
 drivers/scsi/arcmsr/arcmsr_hba.c            |   5 +-
 drivers/scsi/arm/acornscsi.c                |   3 +-
 drivers/scsi/arm/fas216.c                   |   4 +-
 drivers/scsi/be2iscsi/be_main.c             |   2 +-
 drivers/scsi/bfa/bfad_im.c                  |  16 +--
 drivers/scsi/bfa/bfad_im.h                  |   1 -
 drivers/scsi/bnx2fc/bnx2fc_io.c             |   6 +-
 drivers/scsi/csiostor/csio_scsi.c           |   4 +-
 drivers/scsi/cxlflash/main.c                |   3 +-
 drivers/scsi/dc395x.c                       |  23 ++--
 drivers/scsi/dpt_i2o.c                      |   4 +-
 drivers/scsi/esas2r/esas2r_main.c           |   7 +-
 drivers/scsi/esp_scsi.c                     |   7 +-
 drivers/scsi/fnic/fnic_scsi.c               |  22 +--
 drivers/scsi/gdth.c                         |  17 ++-
 drivers/scsi/hptiop.c                       |   2 +-
 drivers/scsi/imm.c                          |   2 +-
 drivers/scsi/initio.c                       |   2 +-
 drivers/scsi/ips.c                          |   5 +-
 drivers/scsi/libfc/fc_fcp.c                 |   9 +-
 drivers/scsi/libiscsi.c                     |  18 ++-
 drivers/scsi/libsas/sas_scsi_host.c         |   2 +-
 drivers/scsi/lpfc/lpfc_crtn.h               |   1 -
 drivers/scsi/lpfc/lpfc_scsi.c               |  51 +++----
 drivers/scsi/megaraid.c                     |  10 +-
 drivers/scsi/megaraid/megaraid_mbox.c       |  23 ++--
 drivers/scsi/megaraid/megaraid_sas_base.c   |   7 +-
 drivers/scsi/megaraid/megaraid_sas_fusion.c |   4 +-
 drivers/scsi/mesh.c                         |   2 +-
 drivers/scsi/mpt3sas/mpt3sas_scsih.c        |  14 +-
 drivers/scsi/mvumi.c                        |   6 +-
 drivers/scsi/ncr53c8xx.c                    |  24 ++--
 drivers/scsi/nsp32.c                        |   5 +-
 drivers/scsi/pcmcia/nsp_cs.c                |  12 +-
 drivers/scsi/pcmcia/sym53c500_cs.c          |   4 +-
 drivers/scsi/ppa.c                          |   3 +-
 drivers/scsi/ps3rom.c                       |   3 +-
 drivers/scsi/qedf/qedf_io.c                 |  12 +-
 drivers/scsi/qla4xxx/ql4_isr.c              |   8 +-
 drivers/scsi/snic/snic_scsi.c               |   4 +-
 drivers/scsi/stex.c                         |  17 ++-
 drivers/scsi/sym53c8xx_2/sym_glue.c         |   2 +-
 drivers/scsi/sym53c8xx_2/sym_glue.h         |   2 +-
 drivers/scsi/vmw_pvscsi.c                   |   2 +-
 drivers/scsi/wd33c93.c                      |  17 ++-
 drivers/usb/storage/cypress_atacb.c         |   5 +-
 include/scsi/scsi_cmnd.h                    |   8 ++
 57 files changed, 360 insertions(+), 322 deletions(-)
diff mbox

Patch

diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
index 89a9d4a2efc8..f34650ada9d7 100644
--- a/drivers/ata/libata-scsi.c
+++ b/drivers/ata/libata-scsi.c
@@ -357,7 +357,7 @@  void ata_scsi_set_sense(struct ata_device *dev, struct scsi_cmnd *cmd,
 	if (!cmd)
 		return;
 
-	cmd->result = (DRIVER_SENSE << 24) | SAM_STAT_CHECK_CONDITION;
+	set_scsi_result(cmd, DRIVER_SENSE, 0, 0, SAM_STAT_CHECK_CONDITION);
 
 	scsi_build_sense_buffer(d_sense, cmd->sense_buffer, sk, asc, ascq);
 }
@@ -873,7 +873,7 @@  static struct ata_queued_cmd *ata_scsi_qc_new(struct ata_device *dev,
 		qc->sg = scsi_sglist(cmd);
 		qc->n_elem = scsi_sg_count(cmd);
 	} else {
-		cmd->result = (DID_OK << 16) | (QUEUE_FULL << 1);
+		set_scsi_result(cmd, 0, DID_OK, 0, (QUEUE_FULL << 1));
 		cmd->scsi_done(cmd);
 	}
 
@@ -1093,7 +1093,7 @@  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;
+	set_scsi_result(cmd, DRIVER_SENSE, 0, 0, SAM_STAT_CHECK_CONDITION);
 
 	/*
 	 * Use ata_to_sense_error() to map status register bits
@@ -1192,7 +1192,7 @@  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;
+	set_scsi_result(cmd, DRIVER_SENSE, 0, 0, SAM_STAT_CHECK_CONDITION);
 
 	if (ata_dev_disabled(dev)) {
 		/* Device disabled after error recovery */
diff --git a/drivers/infiniband/ulp/srp/ib_srp.c b/drivers/infiniband/ulp/srp/ib_srp.c
index c35d2cd37d70..dc32bca59980 100644
--- a/drivers/infiniband/ulp/srp/ib_srp.c
+++ b/drivers/infiniband/ulp/srp/ib_srp.c
@@ -2350,8 +2350,11 @@  static int srp_queuecommand(struct Scsi_Host *shost, struct scsi_cmnd *scmnd)
 		 * max_pages_per_mr sg-list elements, tell the SCSI mid-layer
 		 * to reduce queue depth temporarily.
 		 */
-		scmnd->result = len == -ENOMEM ?
-			DID_OK << 16 | QUEUE_FULL << 1 : DID_ERROR << 16;
+		if (len == -ENOMEM)
+			set_scsi_result(scmnd, 0, DID_OK, 0,
+					SAM_STAT_TASK_SET_FULL);
+		else
+			set_host_byte(scmnd, DID_ERROR);
 		goto err_iu;
 	}
 
diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
index 6ba07c7feb92..b1551710bfe4 100644
--- a/drivers/message/fusion/mptscsih.c
+++ b/drivers/message/fusion/mptscsih.c
@@ -806,7 +806,7 @@  mptscsih_io_done(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *mr)
 			if((xfer_cnt==0)||(sc->underflow > xfer_cnt))
 				sc->result=DID_SOFT_ERROR << 16;
 			else /* Sufficient data transfer occurred */
-				sc->result = (DID_OK << 16) | scsi_status;
+				set_scsi_result(sc, 0, DID_OK, 0, scsi_status);
 			dreplyprintk(ioc, printk(MYIOC_s_DEBUG_FMT
 			    "RESIDUAL_MISMATCH: result=%x on channel=%d id=%d\n",
 			    ioc->name, sc->result, sc->device->channel, sc->device->id));
@@ -817,7 +817,7 @@  mptscsih_io_done(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *mr)
 			 *  Do upfront check for valid SenseData and give it
 			 *  precedence!
 			 */
-			sc->result = (DID_OK << 16) | scsi_status;
+			set_scsi_result(sc, 0, DID_OK, 0, scsi_status);
 			if (!(scsi_state & MPI_SCSI_STATE_AUTOSENSE_VALID)) {
 
 				/*
@@ -884,7 +884,7 @@  mptscsih_io_done(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *mr)
 			scsi_set_resid(sc, 0);
 		case MPI_IOCSTATUS_SCSI_RECOVERED_ERROR:	/* 0x0040 */
 		case MPI_IOCSTATUS_SUCCESS:			/* 0x0000 */
-			sc->result = (DID_OK << 16) | scsi_status;
+			set_scsi_result(sc, 0, DID_OK, 0, scsi_status);
 			if (scsi_state == 0) {
 				;
 			} else if (scsi_state &
diff --git a/drivers/scsi/3w-9xxx.c b/drivers/scsi/3w-9xxx.c
index b42c9c479d4b..dda26ef8d675 100644
--- a/drivers/scsi/3w-9xxx.c
+++ b/drivers/scsi/3w-9xxx.c
@@ -1333,7 +1333,8 @@  static irqreturn_t twa_interrupt(int irq, void *dev_instance)
 				/* If error, command failed */
 				if (error == 1) {
 					/* Ask for a host reset */
-					cmd->result = (DID_OK << 16) | (CHECK_CONDITION << 1);
+					set_scsi_result(cmd, 0, DID_OK, 0,
+							(CHECK_CONDITION << 1));
 				}
 
 				/* Report residual bytes for single sgl */
diff --git a/drivers/scsi/3w-xxxx.c b/drivers/scsi/3w-xxxx.c
index 2a9a1326023b..dc234f5d61d2 100644
--- a/drivers/scsi/3w-xxxx.c
+++ b/drivers/scsi/3w-xxxx.c
@@ -429,7 +429,9 @@  static int tw_decode_sense(TW_Device_Extension *tw_dev, int request_id, int fill
 					/* Additional sense code qualifier */
 					tw_dev->srb[request_id]->sense_buffer[13] = tw_sense_table[i][3];
 
-					tw_dev->srb[request_id]->result = (DID_OK << 16) | (CHECK_CONDITION << 1);
+					set_scsi_result(tw_dev->srb[request_id],
+							0, DID_OK, 0,
+							(CHECK_CONDITION << 1));
 					return TW_ISR_DONT_RESULT; /* Special case for isr to not over-write result */
 				}
 			}
@@ -1970,7 +1972,8 @@  static int tw_scsi_queue_lck(struct scsi_cmnd *SCpnt, void (*done)(struct scsi_c
 			printk(KERN_NOTICE "3w-xxxx: scsi%d: Unknown scsi opcode: 0x%x\n", tw_dev->host->host_no, *command);
 			tw_dev->state[request_id] = TW_S_COMPLETED;
 			tw_state_request_finish(tw_dev, request_id);
-			SCpnt->result = (DRIVER_SENSE << 24) | SAM_STAT_CHECK_CONDITION;
+			set_scsi_result(SCpnt, DRIVER_SENSE, 0, 0,
+					SAM_STAT_CHECK_CONDITION);
 			scsi_build_sense_buffer(1, SCpnt->sense_buffer, ILLEGAL_REQUEST, 0x20, 0);
 			done(SCpnt);
 			retval = 0;
@@ -2153,7 +2156,7 @@  static irqreturn_t tw_interrupt(int irq, void *dev_instance)
 				/* If error, command failed */
 				if (error == 1) {
 					/* Ask for a host reset */
-					tw_dev->srb[request_id]->result = (DID_OK << 16) | (CHECK_CONDITION << 1);
+					set_scsi_result(tw_dev->srb[request_id], 0, DID_OK, 0, CHECK_CONDITION << 1);
 				}
 
 				/* Now complete the io */
diff --git a/drivers/scsi/NCR5380.c b/drivers/scsi/NCR5380.c
index 90ea0f5d9bdb..d670cfe4d0e7 100644
--- a/drivers/scsi/NCR5380.c
+++ b/drivers/scsi/NCR5380.c
@@ -1794,9 +1794,9 @@  static void NCR5380_information_transfer(struct Scsi_Host *instance)
 
 					hostdata->connected = NULL;
 
-					cmd->result &= ~0xffff;
-					cmd->result |= cmd->SCp.Status;
-					cmd->result |= cmd->SCp.Message << 8;
+					set_scsi_result(cmd, 0, 0,
+							cmd->SCp.Message,
+							cmd->SCp.Status);
 
 					if (cmd->cmnd[0] == REQUEST_SENSE)
 						complete_cmd(instance, cmd);
diff --git a/drivers/scsi/a100u2w.c b/drivers/scsi/a100u2w.c
index 8086bd0ac9fd..6249cc59edf5 100644
--- a/drivers/scsi/a100u2w.c
+++ b/drivers/scsi/a100u2w.c
@@ -1040,7 +1040,7 @@  static void inia100_scb_handler(struct orc_host *host, struct orc_scb *scb)
 		memcpy((unsigned char *) &cmd->sense_buffer[0],
 		   (unsigned char *) &escb->sglist[0], SENSE_SIZE);
 	}
-	cmd->result = scb->tastat | (scb->hastat << 16);
+	set_scsi_result(cmd, 0, scb->hastat, 0, scb->tastat);
 	scsi_dma_unmap(cmd);
 	cmd->scsi_done(cmd);	/* Notify system DONE           */
 	orc_release_scb(host, scb);	/* Release SCB for current channel */
diff --git a/drivers/scsi/aacraid/aachba.c b/drivers/scsi/aacraid/aachba.c
index e7961cbd2c55..4892db8f24c3 100644
--- a/drivers/scsi/aacraid/aachba.c
+++ b/drivers/scsi/aacraid/aachba.c
@@ -115,8 +115,6 @@ 
 #define ASENCODE_LUN_FAILED_SELF_CONFIG		0x00
 #define ASENCODE_OVERLAPPED_COMMAND		0x00
 
-#define AAC_STAT_GOOD (DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD)
-
 #define BYTE0(x) (unsigned char)(x)
 #define BYTE1(x) (unsigned char)((x) >> 8)
 #define BYTE2(x) (unsigned char)((x) >> 16)
@@ -571,7 +569,7 @@  static void get_container_name_callback(void *context, struct fib * fibptr)
 		}
 	}
 
-	scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
+	set_scsi_result(scsicmd, 0, DID_OK, COMMAND_COMPLETE, SAM_STAT_GOOD);
 
 	aac_fib_complete(fibptr);
 	scsicmd->scsi_done(scsicmd);
@@ -1104,7 +1102,7 @@  static void get_container_serial_callback(void *context, struct fib * fibptr)
 		}
 	}
 
-	scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
+	set_scsi_result(scsicmd, 0, DID_OK, COMMAND_COMPLETE, SAM_STAT_GOOD);
 
 	aac_fib_complete(fibptr);
 	scsicmd->scsi_done(scsicmd);
@@ -1203,8 +1201,8 @@  static int aac_bounds_32(struct aac_dev * dev, struct scsi_cmnd * cmd, u64 lba)
 	if (lba & 0xffffffff00000000LL) {
 		int cid = scmd_id(cmd);
 		dprintk((KERN_DEBUG "aacraid: Illegal lba\n"));
-		cmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
-			SAM_STAT_CHECK_CONDITION;
+		set_scsi_result(cmd, 0, DID_OK, COMMAND_COMPLETE,
+				SAM_STAT_CHECK_CONDITION);
 		set_sense(&dev->fsa_dev[cid].sense_data,
 		  HARDWARE_ERROR, SENCODE_INTERNAL_TARGET_FAILURE,
 		  ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0);
@@ -2378,13 +2376,13 @@  static void io_callback(void *context, struct fib * fibptr)
 	readreply = (struct aac_read_reply *)fib_data(fibptr);
 	switch (le32_to_cpu(readreply->status)) {
 	case ST_OK:
-		scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
-			SAM_STAT_GOOD;
+		set_scsi_result(scsicmd, 0, DID_OK, COMMAND_COMPLETE,
+				SAM_STAT_GOOD);
 		dev->fsa_dev[cid].sense_data.sense_key = NO_SENSE;
 		break;
 	case ST_NOT_READY:
-		scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
-			SAM_STAT_CHECK_CONDITION;
+		set_scsi_result(scsicmd, 0, DID_OK, COMMAND_COMPLETE,
+				SAM_STAT_CHECK_CONDITION);
 		set_sense(&dev->fsa_dev[cid].sense_data, NOT_READY,
 		  SENCODE_BECOMING_READY, ASENCODE_BECOMING_READY, 0, 0);
 		memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
@@ -2392,8 +2390,8 @@  static void io_callback(void *context, struct fib * fibptr)
 			     SCSI_SENSE_BUFFERSIZE));
 		break;
 	case ST_MEDERR:
-		scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
-			SAM_STAT_CHECK_CONDITION;
+		set_scsi_result(scsicmd, 0, DID_OK, COMMAND_COMPLETE,
+				SAM_STAT_CHECK_CONDITION);
 		set_sense(&dev->fsa_dev[cid].sense_data, MEDIUM_ERROR,
 		  SENCODE_UNRECOVERED_READ_ERROR, ASENCODE_NO_SENSE, 0, 0);
 		memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
@@ -2405,8 +2403,8 @@  static void io_callback(void *context, struct fib * fibptr)
 		printk(KERN_WARNING "io_callback: io failed, status = %d\n",
 		  le32_to_cpu(readreply->status));
 #endif
-		scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
-			SAM_STAT_CHECK_CONDITION;
+		set_scsi_result(scsicmd, 0, DID_OK, COMMAND_COMPLETE,
+				SAM_STAT_CHECK_CONDITION);
 		set_sense(&dev->fsa_dev[cid].sense_data,
 		  HARDWARE_ERROR, SENCODE_INTERNAL_TARGET_FAILURE,
 		  ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0);
@@ -2481,8 +2479,8 @@  static int aac_read(struct scsi_cmnd * scsicmd)
 	if ((lba + count) > (dev->fsa_dev[scmd_id(scsicmd)].size)) {
 		cid = scmd_id(scsicmd);
 		dprintk((KERN_DEBUG "aacraid: Illegal lba\n"));
-		scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
-			SAM_STAT_CHECK_CONDITION;
+		set_scsi_result(scsicmd, 0, DID_OK, COMMAND_COMPLETE,
+				SAM_STAT_CHECK_CONDITION);
 		set_sense(&dev->fsa_dev[cid].sense_data,
 			  HARDWARE_ERROR, SENCODE_INTERNAL_TARGET_FAILURE,
 			  ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0);
@@ -2514,7 +2512,8 @@  static int aac_read(struct scsi_cmnd * scsicmd)
 	/*
 	 *	For some reason, the Fib didn't queue, return QUEUE_FULL
 	 */
-	scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_TASK_SET_FULL;
+	set_scsi_result(scsicmd, 0, DID_OK, COMMAND_COMPLETE,
+			SAM_STAT_TASK_SET_FULL);
 	scsicmd->scsi_done(scsicmd);
 	aac_fib_complete(cmd_fibcontext);
 	aac_fib_free(cmd_fibcontext);
@@ -2573,8 +2572,8 @@  static int aac_write(struct scsi_cmnd * scsicmd)
 	if ((lba + count) > (dev->fsa_dev[scmd_id(scsicmd)].size)) {
 		cid = scmd_id(scsicmd);
 		dprintk((KERN_DEBUG "aacraid: Illegal lba\n"));
-		scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
-			SAM_STAT_CHECK_CONDITION;
+		set_scsi_result(scsicmd, 0, DID_OK, COMMAND_COMPLETE,
+				SAM_STAT_CHECK_CONDITION);
 		set_sense(&dev->fsa_dev[cid].sense_data,
 			  HARDWARE_ERROR, SENCODE_INTERNAL_TARGET_FAILURE,
 			  ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0);
@@ -2606,7 +2605,8 @@  static int aac_write(struct scsi_cmnd * scsicmd)
 	/*
 	 *	For some reason, the Fib didn't queue, return QUEUE_FULL
 	 */
-	scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_TASK_SET_FULL;
+	set_scsi_result(scsicmd, 0, DID_OK, COMMAND_COMPLETE,
+			SAM_STAT_TASK_SET_FULL);
 	scsicmd->scsi_done(scsicmd);
 
 	aac_fib_complete(cmd_fibcontext);
@@ -2631,8 +2631,8 @@  static void synchronize_callback(void *context, struct fib *fibptr)
 
 	synchronizereply = fib_data(fibptr);
 	if (le32_to_cpu(synchronizereply->status) == CT_OK)
-		cmd->result = DID_OK << 16 |
-			COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
+		set_scsi_result(cmd, 0, DID_OK, COMMAND_COMPLETE,
+				SAM_STAT_GOOD);
 	else {
 		struct scsi_device *sdev = cmd->device;
 		struct aac_dev *dev = fibptr->dev;
@@ -2640,8 +2640,8 @@  static void synchronize_callback(void *context, struct fib *fibptr)
 		printk(KERN_WARNING
 		     "synchronize_callback: synchronize failed, status = %d\n",
 		     le32_to_cpu(synchronizereply->status));
-		cmd->result = DID_OK << 16 |
-			COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
+		set_scsi_result(cmd, 0, DID_OK, COMMAND_COMPLETE,
+				SAM_STAT_CHECK_CONDITION);
 		set_sense(&dev->fsa_dev[cid].sense_data,
 		  HARDWARE_ERROR, SENCODE_INTERNAL_TARGET_FAILURE,
 		  ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0);
@@ -2785,7 +2785,7 @@  static void aac_start_stop_callback(void *context, struct fib *fibptr)
 
 	BUG_ON(fibptr == NULL);
 
-	scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_GOOD;
+	set_scsi_result(scsicmd, 0, DID_OK, COMMAND_COMPLETE, SAM_STAT_GOOD);
 
 	aac_fib_complete(fibptr);
 	aac_fib_free(fibptr);
@@ -2802,8 +2802,8 @@  static int aac_start_stop(struct scsi_cmnd *scsicmd)
 
 	if (!(aac->supplement_adapter_info.supported_options2 &
 	      AAC_OPTION_POWER_MANAGEMENT)) {
-		scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
-				  SAM_STAT_GOOD;
+		set_scsi_result(scsicmd, 0, DID_OK, COMMAND_COMPLETE,
+				SAM_STAT_GOOD);
 		scsicmd->scsi_done(scsicmd);
 		return 0;
 	}
@@ -2933,7 +2933,8 @@  int aac_scsi_cmd(struct scsi_cmnd * scsicmd)
 		(scsicmd->cmnd[0] != TEST_UNIT_READY))
 	{
 		dprintk((KERN_WARNING "Only INQUIRY & TUR command supported for controller, rcvd = 0x%x.\n", scsicmd->cmnd[0]));
-		scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
+		set_scsi_result(scsicmd, 0, DID_OK, COMMAND_COMPLETE,
+				SAM_STAT_CHECK_CONDITION);
 		set_sense(&dev->fsa_dev[cid].sense_data,
 		  ILLEGAL_REQUEST, SENCODE_INVALID_COMMAND,
 		  ASENCODE_INVALID_COMMAND, 0, 0);
@@ -2962,7 +2963,8 @@  int aac_scsi_cmd(struct scsi_cmnd * scsicmd)
 
 	case SYNCHRONIZE_CACHE:
 		if (((aac_cache & 6) == 6) && dev->cache_protected) {
-			scsicmd->result = AAC_STAT_GOOD;
+			set_scsi_result(scsicmd, 0, DID_OK, COMMAND_COMPLETE,
+					SAM_STAT_GOOD);
 			break;
 		}
 		/* Issue FIB to tell Firmware to flush it's cache */
@@ -2990,7 +2992,9 @@  int aac_scsi_cmd(struct scsi_cmnd * scsicmd)
 				arr[1] = scsicmd->cmnd[2];
 				scsi_sg_copy_from_buffer(scsicmd, &inq_data,
 							 sizeof(inq_data));
-				scsicmd->result = AAC_STAT_GOOD;
+				set_scsi_result(scsicmd, 0, DID_OK,
+						COMMAND_COMPLETE,
+						SAM_STAT_GOOD);
 			} else if (scsicmd->cmnd[2] == 0x80) {
 				/* unit serial number page */
 				arr[3] = setinqserial(dev, &arr[4],
@@ -3001,7 +3005,9 @@  int aac_scsi_cmd(struct scsi_cmnd * scsicmd)
 				if (aac_wwn != 2)
 					return aac_get_container_serial(
 						scsicmd);
-				scsicmd->result = AAC_STAT_GOOD;
+				set_scsi_result(scsicmd, 0, DID_OK,
+						COMMAND_COMPLETE,
+						SAM_STAT_GOOD);
 			} else if (scsicmd->cmnd[2] == 0x83) {
 				/* vpd page 0x83 - Device Identification Page */
 				char *sno = (char *)&inq_data;
@@ -3010,12 +3016,14 @@  int aac_scsi_cmd(struct scsi_cmnd * scsicmd)
 				if (aac_wwn != 2)
 					return aac_get_container_serial(
 						scsicmd);
-				scsicmd->result = AAC_STAT_GOOD;
+				set_scsi_result(scsicmd, 0, DID_OK,
+						COMMAND_COMPLETE,
+						SAM_STAT_GOOD);
 			} else {
 				/* vpd page not implemented */
-				scsicmd->result = DID_OK << 16 |
-				  COMMAND_COMPLETE << 8 |
-				  SAM_STAT_CHECK_CONDITION;
+				set_scsi_result(scsicmd, 0, DID_OK,
+						COMMAND_COMPLETE,
+						SAM_STAT_CHECK_CONDITION);
 				set_sense(&dev->fsa_dev[cid].sense_data,
 				  ILLEGAL_REQUEST, SENCODE_INVALID_CDB_FIELD,
 				  ASENCODE_NO_SENSE, 7, 2);
@@ -3041,7 +3049,8 @@  int aac_scsi_cmd(struct scsi_cmnd * scsicmd)
 			inq_data.inqd_pdt = INQD_PDT_PROC;	/* Processor device */
 			scsi_sg_copy_from_buffer(scsicmd, &inq_data,
 						 sizeof(inq_data));
-			scsicmd->result = AAC_STAT_GOOD;
+			set_scsi_result(scsicmd, 0, DID_OK, COMMAND_COMPLETE,
+					SAM_STAT_GOOD);
 			break;
 		}
 		if (dev->in_reset)
@@ -3090,7 +3099,8 @@  int aac_scsi_cmd(struct scsi_cmnd * scsicmd)
 		/* Do not cache partition table for arrays */
 		scsicmd->device->removable = 1;
 
-		scsicmd->result = AAC_STAT_GOOD;
+		set_scsi_result(scsicmd, 0, DID_OK, COMMAND_COMPLETE,
+				SAM_STAT_GOOD);
 		break;
 	}
 
@@ -3116,7 +3126,8 @@  int aac_scsi_cmd(struct scsi_cmnd * scsicmd)
 		scsi_sg_copy_from_buffer(scsicmd, cp, sizeof(cp));
 		/* Do not cache partition table for arrays */
 		scsicmd->device->removable = 1;
-		scsicmd->result = AAC_STAT_GOOD;
+		set_scsi_result(scsicmd, 0, DID_OK, COMMAND_COMPLETE,
+				SAM_STAT_GOOD);
 		break;
 	}
 
@@ -3195,7 +3206,8 @@  int aac_scsi_cmd(struct scsi_cmnd * scsicmd)
 		scsi_sg_copy_from_buffer(scsicmd,
 					 (char *)&mpd,
 					 mode_buf_length);
-		scsicmd->result = AAC_STAT_GOOD;
+		set_scsi_result(scsicmd, 0, DID_OK, COMMAND_COMPLETE,
+				SAM_STAT_GOOD);
 		break;
 	}
 	case MODE_SENSE_10:
@@ -3272,7 +3284,8 @@  int aac_scsi_cmd(struct scsi_cmnd * scsicmd)
 					 (char *)&mpd10,
 					 mode_buf_length);
 
-		scsicmd->result = AAC_STAT_GOOD;
+		set_scsi_result(scsicmd, 0, DID_OK, COMMAND_COMPLETE,
+				SAM_STAT_GOOD);
 		break;
 	}
 	case REQUEST_SENSE:
@@ -3281,7 +3294,8 @@  int aac_scsi_cmd(struct scsi_cmnd * scsicmd)
 				sizeof(struct sense_data));
 		memset(&dev->fsa_dev[cid].sense_data, 0,
 				sizeof(struct sense_data));
-		scsicmd->result = AAC_STAT_GOOD;
+		set_scsi_result(scsicmd, 0, DID_OK, COMMAND_COMPLETE,
+				SAM_STAT_GOOD);
 		break;
 
 	case ALLOW_MEDIUM_REMOVAL:
@@ -3291,15 +3305,16 @@  int aac_scsi_cmd(struct scsi_cmnd * scsicmd)
 		else
 			fsa_dev_ptr[cid].locked = 0;
 
-		scsicmd->result = AAC_STAT_GOOD;
+		set_scsi_result(scsicmd, 0, DID_OK, COMMAND_COMPLETE,
+				SAM_STAT_GOOD);
 		break;
 	/*
 	 *	These commands are all No-Ops
 	 */
 	case TEST_UNIT_READY:
 		if (fsa_dev_ptr[cid].sense_data.sense_key == NOT_READY) {
-			scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
-				SAM_STAT_CHECK_CONDITION;
+			set_scsi_result(scsicmd, 0, DID_OK, COMMAND_COMPLETE,
+					SAM_STAT_CHECK_CONDITION);
 			set_sense(&dev->fsa_dev[cid].sense_data,
 				  NOT_READY, SENCODE_BECOMING_READY,
 				  ASENCODE_BECOMING_READY, 0, 0);
@@ -3315,7 +3330,8 @@  int aac_scsi_cmd(struct scsi_cmnd * scsicmd)
 	case REZERO_UNIT:
 	case REASSIGN_BLOCKS:
 	case SEEK_10:
-		scsicmd->result = AAC_STAT_GOOD;
+		set_scsi_result(scsicmd, 0, DID_OK, COMMAND_COMPLETE,
+				SAM_STAT_GOOD);
 		break;
 
 	case START_STOP:
@@ -3328,8 +3344,8 @@  int aac_scsi_cmd(struct scsi_cmnd * scsicmd)
 	 */
 		dprintk((KERN_WARNING "Unhandled SCSI Command: 0x%x.\n",
 				scsicmd->cmnd[0]));
-		scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
-				SAM_STAT_CHECK_CONDITION;
+		set_scsi_result(scsicmd, 0, DID_OK, COMMAND_COMPLETE,
+				SAM_STAT_CHECK_CONDITION);
 		set_sense(&dev->fsa_dev[cid].sense_data,
 			  ILLEGAL_REQUEST, SENCODE_INVALID_COMMAND,
 			  ASENCODE_INVALID_COMMAND, 0, 0);
@@ -3516,9 +3532,8 @@  static void aac_srb_callback(void *context, struct fib * fibptr)
 				le32_to_cpu(srbreply->status));
 		len = min_t(u32, le32_to_cpu(srbreply->sense_data_size),
 			    SCSI_SENSE_BUFFERSIZE);
-		scsicmd->result = DID_ERROR << 16
-				| COMMAND_COMPLETE << 8
-				| SAM_STAT_CHECK_CONDITION;
+		set_scsi_result(scsicmd, 0, DID_ERROR, COMMAND_COMPLETE,
+				SAM_STAT_CHECK_CONDITION);
 		memcpy(scsicmd->sense_buffer,
 				srbreply->sense_data, len);
 	}
@@ -3530,7 +3545,7 @@  static void aac_srb_callback(void *context, struct fib * fibptr)
 	case SRB_STATUS_ERROR_RECOVERY:
 	case SRB_STATUS_PENDING:
 	case SRB_STATUS_SUCCESS:
-		scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
+		set_scsi_result(scsicmd, 0, DID_OK, COMMAND_COMPLETE, 0);
 		break;
 	case SRB_STATUS_DATA_OVERRUN:
 		switch (scsicmd->cmnd[0]) {
@@ -3547,60 +3562,56 @@  static void aac_srb_callback(void *context, struct fib * fibptr)
 				pr_warn("aacraid: SCSI CMD underflow\n");
 			else
 				pr_warn("aacraid: SCSI CMD Data Overrun\n");
-			scsicmd->result = DID_ERROR << 16
-					| COMMAND_COMPLETE << 8;
+			set_scsi_result(scsicmd, 0, DID_ERROR,
+					COMMAND_COMPLETE, 0);
 			break;
 		case INQUIRY:
-			scsicmd->result = DID_OK << 16
-					| COMMAND_COMPLETE << 8;
+			set_scsi_result(scsicmd, 0, DID_OK, COMMAND_COMPLETE,
+					0);
 			break;
 		default:
-			scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
+			set_scsi_result(scsicmd, 0, DID_OK, COMMAND_COMPLETE,
+					0);
 			break;
 		}
 		break;
 	case SRB_STATUS_ABORTED:
-		scsicmd->result = DID_ABORT << 16 | ABORT << 8;
+		set_scsi_result(scsicmd, 0, DID_ABORT, ABORT, 0);
 		break;
 	case SRB_STATUS_ABORT_FAILED:
 		/*
 		 * Not sure about this one - but assuming the
 		 * hba was trying to abort for some reason
 		 */
-		scsicmd->result = DID_ERROR << 16 | ABORT << 8;
+		set_scsi_result(scsicmd, 0, DID_ERROR, ABORT, 0);
 		break;
 	case SRB_STATUS_PARITY_ERROR:
-		scsicmd->result = DID_PARITY << 16
-				| MSG_PARITY_ERROR << 8;
+		set_scsi_result(scsicmd, 0, DID_PARITY, MSG_PARITY_ERROR, 0);
 		break;
 	case SRB_STATUS_NO_DEVICE:
 	case SRB_STATUS_INVALID_PATH_ID:
 	case SRB_STATUS_INVALID_TARGET_ID:
 	case SRB_STATUS_INVALID_LUN:
 	case SRB_STATUS_SELECTION_TIMEOUT:
-		scsicmd->result = DID_NO_CONNECT << 16
-				| COMMAND_COMPLETE << 8;
+		set_scsi_result(scsicmd, 0, DID_NO_CONNECT, COMMAND_COMPLETE,
+				0);
 		break;
 
 	case SRB_STATUS_COMMAND_TIMEOUT:
 	case SRB_STATUS_TIMEOUT:
-		scsicmd->result = DID_TIME_OUT << 16
-				| COMMAND_COMPLETE << 8;
+		set_scsi_result(scsicmd, 0, DID_TIME_OUT, COMMAND_COMPLETE, 0);
 		break;
 
 	case SRB_STATUS_BUSY:
-		scsicmd->result = DID_BUS_BUSY << 16
-				| COMMAND_COMPLETE << 8;
+		set_scsi_result(scsicmd, 0, DID_BUS_BUSY, COMMAND_COMPLETE, 0);
 		break;
 
 	case SRB_STATUS_BUS_RESET:
-		scsicmd->result = DID_RESET << 16
-				| COMMAND_COMPLETE << 8;
+		set_scsi_result(scsicmd, 0, DID_RESET, COMMAND_COMPLETE, 0);
 		break;
 
 	case SRB_STATUS_MESSAGE_REJECTED:
-		scsicmd->result = DID_ERROR << 16
-				| MESSAGE_REJECT << 8;
+		set_scsi_result(scsicmd, 0, DID_ERROR, MESSAGE_REJECT, 0);
 		break;
 	case SRB_STATUS_REQUEST_FLUSHED:
 	case SRB_STATUS_ERROR:
@@ -3636,17 +3647,17 @@  static void aac_srb_callback(void *context, struct fib * fibptr)
 			|| (scsicmd->cmnd[0] == ATA_16)) {
 
 			if (scsicmd->cmnd[2] & (0x01 << 5)) {
-				scsicmd->result = DID_OK << 16
-					| COMMAND_COMPLETE << 8;
+				set_scsi_result(scsicmd, 0, DID_OK,
+						COMMAND_COMPLETE, 0);
 			break;
 			} else {
-				scsicmd->result = DID_ERROR << 16
-					| COMMAND_COMPLETE << 8;
+				set_scsi_result(scsicmd, 0, DID_ERROR,
+						COMMAND_COMPLETE, 0);
 			break;
 			}
 		} else {
-			scsicmd->result = DID_ERROR << 16
-				| COMMAND_COMPLETE << 8;
+			set_scsi_result(scsicmd, 0, DID_ERROR,
+					COMMAND_COMPLETE, 0);
 			break;
 		}
 	}
@@ -3684,7 +3695,7 @@  static void hba_resp_task_complete(struct aac_dev *dev,
 
 	switch (err->status) {
 	case SAM_STAT_GOOD:
-		scsicmd->result |= DID_OK << 16 | COMMAND_COMPLETE << 8;
+		set_scsi_result(scsicmd, 0, DID_OK, COMMAND_COMPLETE, 0);
 		break;
 	case SAM_STAT_CHECK_CONDITION:
 	{
@@ -3695,19 +3706,19 @@  static void hba_resp_task_complete(struct aac_dev *dev,
 		if (len)
 			memcpy(scsicmd->sense_buffer,
 				err->sense_response_buf, len);
-		scsicmd->result |= DID_OK << 16 | COMMAND_COMPLETE << 8;
+		set_scsi_result(scsicmd, 0, DID_OK, COMMAND_COMPLETE, 0);
 		break;
 	}
 	case SAM_STAT_BUSY:
-		scsicmd->result |= DID_BUS_BUSY << 16 | COMMAND_COMPLETE << 8;
+		set_scsi_result(scsicmd, 0, DID_BUS_BUSY, COMMAND_COMPLETE, 0);
 		break;
 	case SAM_STAT_TASK_ABORTED:
-		scsicmd->result |= DID_ABORT << 16 | ABORT << 8;
+		set_scsi_result(scsicmd, 0, DID_ABORT, ABORT, 0);
 		break;
 	case SAM_STAT_RESERVATION_CONFLICT:
 	case SAM_STAT_TASK_SET_FULL:
 	default:
-		scsicmd->result |= DID_ERROR << 16 | COMMAND_COMPLETE << 8;
+		set_scsi_result(scsicmd, 0, DID_ERROR, COMMAND_COMPLETE, 0);
 		break;
 	}
 }
@@ -3727,27 +3738,29 @@  static void hba_resp_task_failure(struct aac_dev *dev,
 			dev->hba_map[bus][cid].devtype = AAC_DEVTYPE_ARC_RAW;
 			dev->hba_map[bus][cid].rmw_nexus = 0xffffffff;
 		}
-		scsicmd->result = DID_NO_CONNECT << 16 | COMMAND_COMPLETE << 8;
+		set_scsi_result(scsicmd, 0, DID_NO_CONNECT, COMMAND_COMPLETE,
+				0);
 		break;
 	}
 	case HBA_RESP_STAT_IO_ERROR:
 	case HBA_RESP_STAT_NO_PATH_TO_DEVICE:
-		scsicmd->result = DID_OK << 16 |
-			COMMAND_COMPLETE << 8 | SAM_STAT_BUSY;
+		set_scsi_result(scsicmd, 0, DID_OK, COMMAND_COMPLETE,
+				SAM_STAT_BUSY);
 		break;
 	case HBA_RESP_STAT_IO_ABORTED:
-		scsicmd->result = DID_ABORT << 16 | ABORT << 8;
+		set_scsi_result(scsicmd, 0, DID_ABORT, ABORT, 0);
 		break;
 	case HBA_RESP_STAT_INVALID_DEVICE:
-		scsicmd->result = DID_NO_CONNECT << 16 | COMMAND_COMPLETE << 8;
+		set_scsi_result(scsicmd, 0, DID_NO_CONNECT, COMMAND_COMPLETE,
+				0);
 		break;
 	case HBA_RESP_STAT_UNDERRUN:
 		/* UNDERRUN is OK */
-		scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
+		set_scsi_result(scsicmd, 0, DID_OK, COMMAND_COMPLETE, 0);
 		break;
 	case HBA_RESP_STAT_OVERRUN:
 	default:
-		scsicmd->result = DID_ERROR << 16 | COMMAND_COMPLETE << 8;
+		set_scsi_result(scsicmd, 0, DID_ERROR, COMMAND_COMPLETE, 0);
 		break;
 	}
 }
@@ -3782,7 +3795,7 @@  void aac_hba_callback(void *context, struct fib *fibptr)
 
 	if (fibptr->flags & FIB_CONTEXT_FLAG_FASTRESP) {
 		/* fast response */
-		scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
+		set_scsi_result(scsicmd, 0, DID_OK, COMMAND_COMPLETE, 0);
 		goto out;
 	}
 
@@ -3794,17 +3807,18 @@  void aac_hba_callback(void *context, struct fib *fibptr)
 		hba_resp_task_failure(dev, scsicmd, err);
 		break;
 	case HBA_RESP_SVCRES_TMF_REJECTED:
-		scsicmd->result = DID_ERROR << 16 | MESSAGE_REJECT << 8;
+		set_scsi_result(scsicmd, 0, DID_ERROR, MESSAGE_REJECT, 0);
 		break;
 	case HBA_RESP_SVCRES_TMF_LUN_INVALID:
-		scsicmd->result = DID_NO_CONNECT << 16 | COMMAND_COMPLETE << 8;
+		set_scsi_result(scsicmd, 0, DID_NO_CONNECT, COMMAND_COMPLETE,
+				0);
 		break;
 	case HBA_RESP_SVCRES_TMF_COMPLETE:
 	case HBA_RESP_SVCRES_TMF_SUCCEEDED:
-		scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
+		set_scsi_result(scsicmd, 0, DID_OK, COMMAND_COMPLETE, 0);
 		break;
 	default:
-		scsicmd->result = DID_ERROR << 16 | COMMAND_COMPLETE << 8;
+		set_scsi_result(scsicmd, 0, DID_ERROR, COMMAND_COMPLETE, 0);
 		break;
 	}
 
diff --git a/drivers/scsi/aacraid/commsup.c b/drivers/scsi/aacraid/commsup.c
index 0156c9623c35..a7a9ad34bcf0 100644
--- a/drivers/scsi/aacraid/commsup.c
+++ b/drivers/scsi/aacraid/commsup.c
@@ -1625,9 +1625,8 @@  static int _aac_reset_adapter(struct aac_dev *aac, int forced, u8 reset_type)
 	while ((command = command_list)) {
 		command_list = (struct scsi_cmnd *)command->SCp.buffer;
 		command->SCp.buffer = NULL;
-		command->result = DID_OK << 16
-		  | COMMAND_COMPLETE << 8
-		  | SAM_STAT_TASK_SET_FULL;
+		set_scsi_result(command, 0, DID_OK, COMMAND_COMPLETE,
+				SAM_STAT_TASK_SET_FULL);
 		command->SCp.phase = AAC_OWNER_ERROR_HANDLER;
 		command->scsi_done(command);
 	}
diff --git a/drivers/scsi/advansys.c b/drivers/scsi/advansys.c
index c9a52905070e..0f93fe6c58b0 100644
--- a/drivers/scsi/advansys.c
+++ b/drivers/scsi/advansys.c
@@ -6039,8 +6039,8 @@  static void adv_isr_callback(ADV_DVC_VAR *adv_dvc_varp, ADV_SCSI_REQ_Q *scsiqp)
 				 * 0x2. Host drivers are supposed to return
 				 * the status byte as it is defined by SCSI.
 				 */
-				scp->result = DRIVER_BYTE(DRIVER_SENSE) |
-				    STATUS_BYTE(scsiqp->scsi_status);
+				set_scsi_result(scp, DRIVER_SENSE, 0, 0,
+						scsiqp->scsi_status);
 			} else {
 				scp->result = STATUS_BYTE(scsiqp->scsi_status);
 			}
@@ -6056,14 +6056,12 @@  static void adv_isr_callback(ADV_DVC_VAR *adv_dvc_varp, ADV_SCSI_REQ_Q *scsiqp)
 
 	case QD_ABORTED_BY_HOST:
 		ASC_DBG(1, "QD_ABORTED_BY_HOST\n");
-		scp->result =
-		    HOST_BYTE(DID_ABORT) | STATUS_BYTE(scsiqp->scsi_status);
+		set_scsi_result(scp, 0, DID_ABORT, 0, scsiqp->scsi_status);
 		break;
 
 	default:
 		ASC_DBG(1, "done_status 0x%x\n", scsiqp->done_status);
-		scp->result =
-		    HOST_BYTE(DID_ERROR) | STATUS_BYTE(scsiqp->scsi_status);
+		set_scsi_result(scp, 0, DID_ERROR, 0, scsiqp->scsi_status);
 		break;
 	}
 
@@ -6807,8 +6805,8 @@  static void asc_isr_callback(ASC_DVC_VAR *asc_dvc_varp, ASC_QDONE_INFO *qdonep)
 				 * 0x2. Host drivers are supposed to return
 				 * the status byte as it is defined by SCSI.
 				 */
-				scp->result = DRIVER_BYTE(DRIVER_SENSE) |
-				    STATUS_BYTE(qdonep->d3.scsi_stat);
+				set_scsi_result(scp, 0, DRIVER_SENSE, 0,
+					qdonep->d3.scsi_stat);
 			} else {
 				scp->result = STATUS_BYTE(qdonep->d3.scsi_stat);
 			}
@@ -6824,18 +6822,14 @@  static void asc_isr_callback(ASC_DVC_VAR *asc_dvc_varp, ASC_QDONE_INFO *qdonep)
 
 	case QD_ABORTED_BY_HOST:
 		ASC_DBG(1, "QD_ABORTED_BY_HOST\n");
-		scp->result =
-		    HOST_BYTE(DID_ABORT) | MSG_BYTE(qdonep->d3.
-						    scsi_msg) |
-		    STATUS_BYTE(qdonep->d3.scsi_stat);
+		set_scsi_result(scp, 0,	DID_ABORT, qdonep->d3.scsi_msg,
+			qdonep->d3.scsi_stat);
 		break;
 
 	default:
 		ASC_DBG(1, "done_stat 0x%x\n", qdonep->d3.done_stat);
-		scp->result =
-		    HOST_BYTE(DID_ERROR) | MSG_BYTE(qdonep->d3.
-						    scsi_msg) |
-		    STATUS_BYTE(qdonep->d3.scsi_stat);
+		set_scsi_result(scp, 0, DID_ERROR, qdonep->d3.scsi_msg,
+				qdonep->d3.scsi_stat);
 		break;
 	}
 
diff --git a/drivers/scsi/arcmsr/arcmsr_hba.c b/drivers/scsi/arcmsr/arcmsr_hba.c
index 732b5d9242f1..a99d44d36e5f 100644
--- a/drivers/scsi/arcmsr/arcmsr_hba.c
+++ b/drivers/scsi/arcmsr/arcmsr_hba.c
@@ -1202,7 +1202,7 @@  static void arcmsr_report_sense_info(struct CommandControlBlock *ccb)
 
 	struct scsi_cmnd *pcmd = ccb->pcmd;
 	struct SENSE_DATA *sensebuffer = (struct SENSE_DATA *)pcmd->sense_buffer;
-	pcmd->result = (DID_OK << 16) | (CHECK_CONDITION << 1);
+	set_scsi_result(pcmd, 0, DID_OK, 0, (CHECK_CONDITION << 1));
 	if (sensebuffer) {
 		int sense_data_length =
 			sizeof(struct SENSE_DATA) < SCSI_SENSE_BUFFERSIZE
@@ -3019,7 +3019,8 @@  static int arcmsr_queue_command_lck(struct scsi_cmnd *cmd,
 	if (!ccb)
 		return SCSI_MLQUEUE_HOST_BUSY;
 	if (arcmsr_build_ccb( acb, ccb, cmd ) == FAILED) {
-		cmd->result = (DID_ERROR << 16) | (RESERVATION_CONFLICT << 1);
+		set_scsi_result(cmd, 0, DID_ERROR, 0,
+				(RESERVATION_CONFLICT << 1));
 		cmd->scsi_done(cmd);
 		return 0;
 	}
diff --git a/drivers/scsi/arm/acornscsi.c b/drivers/scsi/arm/acornscsi.c
index 421fe869a11e..e5e30fe58b84 100644
--- a/drivers/scsi/arm/acornscsi.c
+++ b/drivers/scsi/arm/acornscsi.c
@@ -803,7 +803,8 @@  static void acornscsi_done(AS_Host *host, struct scsi_cmnd **SCpntp,
 
 	acornscsi_dma_cleanup(host);
 
-	SCpnt->result = result << 16 | host->scsi.SCp.Message << 8 | host->scsi.SCp.Status;
+	set_scsi_result(SCpnt, 0, result, host->scsi.SCp.Message,
+                        host->scsi.SCp.Status);
 
 	/*
 	 * In theory, this should not happen.  In practice, it seems to.
diff --git a/drivers/scsi/arm/fas216.c b/drivers/scsi/arm/fas216.c
index 27bda2b05de6..dd1d8c903e31 100644
--- a/drivers/scsi/arm/fas216.c
+++ b/drivers/scsi/arm/fas216.c
@@ -2037,8 +2037,8 @@  fas216_std_done(FAS216_Info *info, struct scsi_cmnd *SCpnt, unsigned int result)
 {
 	info->stats.fins += 1;
 
-	SCpnt->result = result << 16 | info->scsi.SCp.Message << 8 |
-			info->scsi.SCp.Status;
+	set_scsi_result(SCpnt, 0, result, info->scsi.SCp.Message,
+			info->scsi.SCp.Status);
 
 	fas216_log_command(info, LOG_CONNECT, SCpnt,
 		"command complete, result=0x%08x", SCpnt->result);
diff --git a/drivers/scsi/be2iscsi/be_main.c b/drivers/scsi/be2iscsi/be_main.c
index b3cfdd5f4d1c..7afd4e426cb8 100644
--- a/drivers/scsi/be2iscsi/be_main.c
+++ b/drivers/scsi/be2iscsi/be_main.c
@@ -1131,7 +1131,7 @@  be_complete_io(struct beiscsi_conn *beiscsi_conn,
 
 		return;
 	}
-	task->sc->result = (DID_OK << 16) | status;
+	set_scsi_result(task->sc, 0, DID_OK, 0, status);
 	if (rsp != ISCSI_STATUS_CMD_COMPLETED) {
 		task->sc->result = DID_ERROR << 16;
 		goto unmap;
diff --git a/drivers/scsi/bfa/bfad_im.c b/drivers/scsi/bfa/bfad_im.c
index c05d6e91e4bd..fe07d93e06f9 100644
--- a/drivers/scsi/bfa/bfad_im.c
+++ b/drivers/scsi/bfa/bfad_im.c
@@ -70,21 +70,21 @@  bfa_cb_ioim_done(void *drv, struct bfad_ioim_s *dio,
 				host_status = DID_ERROR;
 			}
 		}
-		cmnd->result = ScsiResult(host_status, scsi_status);
+		set_scsi_result(cmnd, 0, host_status, 0, scsi_status);
 
 		break;
 
 	case BFI_IOIM_STS_TIMEDOUT:
 		host_status = DID_TIME_OUT;
-		cmnd->result = ScsiResult(host_status, 0);
+		set_scsi_result(cmnd, 0, host_status, 0, 0);
 		break;
 	case BFI_IOIM_STS_PATHTOV:
 		host_status = DID_TRANSPORT_DISRUPTED;
-		cmnd->result = ScsiResult(host_status, 0);
+		set_scsi_result(cmnd, 0, host_status, 0, 0);
 		break;
 	default:
 		host_status = DID_ERROR;
-		cmnd->result = ScsiResult(host_status, 0);
+		set_scsi_result(cmnd, 0, host_status, 0, 0);
 	}
 
 	/* Unmap DMA, if host is NULL, it means a scsi passthru cmd */
@@ -117,7 +117,7 @@  bfa_cb_ioim_good_comp(void *drv, struct bfad_ioim_s *dio)
 	struct bfad_itnim_data_s *itnim_data;
 	struct bfad_itnim_s *itnim;
 
-	cmnd->result = ScsiResult(DID_OK, SCSI_STATUS_GOOD);
+	set_scsi_result(cmnd, 0, DID_OK, 0, SCSI_STATUS_GOOD);
 
 	/* Unmap DMA, if host is NULL, it means a scsi passthru cmd */
 	if (cmnd->device->host != NULL)
@@ -144,7 +144,7 @@  bfa_cb_ioim_abort(void *drv, struct bfad_ioim_s *dio)
 	struct scsi_cmnd *cmnd = (struct scsi_cmnd *)dio;
 	struct bfad_s         *bfad = drv;
 
-	cmnd->result = ScsiResult(DID_ERROR, 0);
+	set_scsi_result(cmnd, 0, DID_ERROR, 0, 0);
 
 	/* Unmap DMA, if host is NULL, it means a scsi passthru cmd */
 	if (cmnd->device->host != NULL)
@@ -1253,14 +1253,14 @@  bfad_im_queuecommand_lck(struct scsi_cmnd *cmnd, void (*done) (struct scsi_cmnd
 		printk(KERN_WARNING
 			"bfad%d, queuecommand %p %x failed, BFA stopped\n",
 		       bfad->inst_no, cmnd, cmnd->cmnd[0]);
-		cmnd->result = ScsiResult(DID_NO_CONNECT, 0);
+		set_scsi_result(cmnd, 0, DID_NO_CONNECT, 0, 0);
 		goto out_fail_cmd;
 	}
 
 
 	itnim = itnim_data->itnim;
 	if (!itnim) {
-		cmnd->result = ScsiResult(DID_IMM_RETRY, 0);
+		set_scsi_result(cmnd, 0, DID_IMM_RETRY, 0, 0);
 		goto out_fail_cmd;
 	}
 
diff --git a/drivers/scsi/bfa/bfad_im.h b/drivers/scsi/bfa/bfad_im.h
index af66275570c3..e61ed8dad0b4 100644
--- a/drivers/scsi/bfa/bfad_im.h
+++ b/drivers/scsi/bfa/bfad_im.h
@@ -44,7 +44,6 @@  u32 bfad_im_supported_speeds(struct bfa_s *bfa);
 #define MAX_FCP_LUN 16384
 #define BFAD_TARGET_RESET_TMO 60
 #define BFAD_LUN_RESET_TMO 60
-#define ScsiResult(host_code, scsi_code) (((host_code) << 16) | scsi_code)
 #define BFA_QUEUE_FULL_RAMP_UP_TIME 120
 
 /*
diff --git a/drivers/scsi/bnx2fc/bnx2fc_io.c b/drivers/scsi/bnx2fc/bnx2fc_io.c
index 5a645b8b9af1..45f6900cc25d 100644
--- a/drivers/scsi/bnx2fc/bnx2fc_io.c
+++ b/drivers/scsi/bnx2fc/bnx2fc_io.c
@@ -1548,7 +1548,8 @@  void bnx2fc_process_tm_compl(struct bnx2fc_cmd *io_req,
 			sc_cmd->result = DID_OK << 16;
 		} else {
 			/* Transport status is good, SCSI status not good */
-			sc_cmd->result = (DID_OK << 16) | io_req->cdb_status;
+			set_scsi_result(sc_cmd, 0, DID_OK, 0,
+					io_req->cdb_status);
 		}
 		if (io_req->fcp_resid)
 			scsi_set_resid(sc_cmd, io_req->fcp_resid);
@@ -1946,7 +1947,8 @@  void bnx2fc_process_scsi_cmd_compl(struct bnx2fc_cmd *io_req,
 			BNX2FC_IO_DBG(io_req, "scsi_cmpl: cdb_status = %d"
 				 " fcp_resid = 0x%x\n",
 				io_req->cdb_status, io_req->fcp_resid);
-			sc_cmd->result = (DID_OK << 16) | io_req->cdb_status;
+			set_scsi_result(sc_cmd, 0, DID_OK, 0,
+					io_req->cdb_status);
 
 			if (io_req->cdb_status == SAM_STAT_TASK_SET_FULL ||
 			    io_req->cdb_status == SAM_STAT_BUSY) {
diff --git a/drivers/scsi/csiostor/csio_scsi.c b/drivers/scsi/csiostor/csio_scsi.c
index dab0d3f9bee1..ef5aff4f6efe 100644
--- a/drivers/scsi/csiostor/csio_scsi.c
+++ b/drivers/scsi/csiostor/csio_scsi.c
@@ -1716,7 +1716,7 @@  csio_scsi_err_handler(struct csio_hw *hw, struct csio_ioreq *req)
 	if (req->nsge > 0)
 		scsi_dma_unmap(cmnd);
 
-	cmnd->result = (((host_status) << 16) | scsi_status);
+	set_scsi_result(cmnd, 0, host_status, 0, scsi_status);
 	cmnd->scsi_done(cmnd);
 
 	/* Wake up waiting threads */
@@ -1744,7 +1744,7 @@  csio_scsi_cbfn(struct csio_hw *hw, struct csio_ioreq *req)
 				host_status = csio_scsi_copy_to_sgl(hw, req);
 		}
 
-		cmnd->result = (((host_status) << 16) | scsi_status);
+		set_scsi_result(cmnd, 0, host_status, 0, scsi_status);
 		cmnd->scsi_done(cmnd);
 		csio_scsi_cmnd(req) = NULL;
 		CSIO_INC_STATS(csio_hw_to_scsim(hw), n_tot_success);
diff --git a/drivers/scsi/cxlflash/main.c b/drivers/scsi/cxlflash/main.c
index d8fe7ab870b8..d87ba402fadb 100644
--- a/drivers/scsi/cxlflash/main.c
+++ b/drivers/scsi/cxlflash/main.c
@@ -85,7 +85,8 @@  static void process_cmd_err(struct afu_cmd *cmd, struct scsi_cmnd *scp)
 			       SISL_SENSE_DATA_LEN);
 			scp->result = ioasa->rc.scsi_rc;
 		} else
-			scp->result = ioasa->rc.scsi_rc | (DID_ERROR << 16);
+			set_scsi_result(scp, 0, DID_ERROR, 0,
+					ioasa->rc.scsi_rc);
 	}
 
 	/*
diff --git a/drivers/scsi/dc395x.c b/drivers/scsi/dc395x.c
index 379a1bc37576..25f35bbd7264 100644
--- a/drivers/scsi/dc395x.c
+++ b/drivers/scsi/dc395x.c
@@ -3382,14 +3382,12 @@  static void srb_done(struct AdapterCtlBlk *acb, struct DeviceCtlBlk *dcb,
 
 		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_scsi_result(cmd, 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);
+			set_scsi_result(cmd, DRIVER_SENSE, DID_OK,
+					srb->end_message, CHECK_CONDITION);
 
 		goto ckc_e;
 	}
@@ -3421,10 +3419,8 @@  static void srb_done(struct AdapterCtlBlk *acb, struct DeviceCtlBlk *dcb,
 			cmd->result = DID_NO_CONNECT << 16;
 		} else {
 			srb->adapter_status = 0;
-			SET_RES_DID(cmd->result, DID_ERROR);
-			SET_RES_MSG(cmd->result, srb->end_message);
-			SET_RES_TARGET(cmd->result, status);
-
+			set_scsi_result(cmd, 0, DID_ERROR, srb->end_message,
+					status);
 		}
 	} else {
 		/*
@@ -3433,11 +3429,10 @@  static void srb_done(struct AdapterCtlBlk *acb, struct DeviceCtlBlk *dcb,
 		status = srb->adapter_status;
 		if (status & H_OVER_UNDER_RUN) {
 			srb->target_status = 0;
-			SET_RES_DID(cmd->result, DID_OK);
-			SET_RES_MSG(cmd->result, srb->end_message);
+			set_scsi_result(cmd, 0, DID_OK, srb->end_message, 0);
 		} else if (srb->status & PARITY_ERROR) {
-			SET_RES_DID(cmd->result, DID_PARITY);
-			SET_RES_MSG(cmd->result, srb->end_message);
+			set_scsi_result(cmd, 0, DID_PARITY,
+					srb->end_message, 0);
 		} else {	/* No error */
 
 			srb->adapter_status = 0;
diff --git a/drivers/scsi/dpt_i2o.c b/drivers/scsi/dpt_i2o.c
index 5ceea8da7bb6..97ffc57b35ab 100644
--- a/drivers/scsi/dpt_i2o.c
+++ b/drivers/scsi/dpt_i2o.c
@@ -2261,7 +2261,7 @@  static s32 adpt_scsi_to_i2o(adpt_hba* pHba, struct scsi_cmnd* cmd, struct adpt_d
 		default:
 			printk(KERN_WARNING"%s: scsi opcode 0x%x not supported.\n",
 			     pHba->name, cmd->cmnd[0]);
-			cmd->result = (DID_OK <<16) | (INITIATOR_ERROR << 8);
+			set_scsi_result(cmd, 0, DID_OK, INITIATOR_ERROR, 0);
 			cmd->scsi_done(cmd);
 			return 	0;
 		}
@@ -2689,7 +2689,7 @@  static void adpt_fail_posted_scbs(adpt_hba* pHba)
 			if(cmd->serial_number == 0){
 				continue;
 			}
-			cmd->result = (DID_OK << 16) | (QUEUE_FULL <<1);
+			set_scsi_result(cmd, 0, DID_OK, 0, (QUEUE_FULL << 1));
 			cmd->scsi_done(cmd);
 		}
 		spin_unlock_irqrestore(&d->list_lock, flags);
diff --git a/drivers/scsi/esas2r/esas2r_main.c b/drivers/scsi/esas2r/esas2r_main.c
index e07eac5be087..20264098c4ba 100644
--- a/drivers/scsi/esas2r/esas2r_main.c
+++ b/drivers/scsi/esas2r/esas2r_main.c
@@ -1522,9 +1522,10 @@  void esas2r_complete_request_cb(struct esas2r_adapter *a,
 			     rq->func_rsp.scsi_rsp.scsi_stat,
 			     rq->cmd);
 
-		rq->cmd->result =
-			((esas2r_req_status_to_error(rq->req_stat) << 16)
-			 | (rq->func_rsp.scsi_rsp.scsi_stat & STATUS_MASK));
+		set_scsi_result(rq->cmd, 0,
+				esas2r_req_status_to_error(rq->req_stat) << 16,
+				0,
+				(rq->func_rsp.scsi_rsp.scsi_stat & STATUS_MASK));
 
 		if (rq->req_stat == RS_UNDERRUN)
 			scsi_set_resid(rq->cmd,
diff --git a/drivers/scsi/esp_scsi.c b/drivers/scsi/esp_scsi.c
index c3fc34b9964d..9d31e43bc99a 100644
--- a/drivers/scsi/esp_scsi.c
+++ b/drivers/scsi/esp_scsi.c
@@ -910,11 +910,8 @@  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) |
-			       (COMMAND_COMPLETE << 8) |
-			       (SAM_STAT_CHECK_CONDITION << 0));
-
+		set_scsi_result(cmd, DRIVER_SENSE, DID_OK,
+				COMMAND_COMPLETE, SAM_STAT_CHECK_CONDITION);
 		ent->flags &= ~ESP_CMD_FLAG_AUTOSENSE;
 		if (esp_debug & ESP_DEBUG_AUTOSENSE) {
 			int i;
diff --git a/drivers/scsi/fnic/fnic_scsi.c b/drivers/scsi/fnic/fnic_scsi.c
index 8cbd3c9f0b4c..e083c0f687f9 100644
--- a/drivers/scsi/fnic/fnic_scsi.c
+++ b/drivers/scsi/fnic/fnic_scsi.c
@@ -922,7 +922,7 @@  static void fnic_fcpio_icmnd_cmpl_handler(struct fnic *fnic,
 
 	switch (hdr_status) {
 	case FCPIO_SUCCESS:
-		sc->result = (DID_OK << 16) | icmnd_cmpl->scsi_status;
+		set_scsi_result(sc, 0, DID_OK, 0, icmnd_cmpl->scsi_status);
 		xfer_len = scsi_bufflen(sc);
 		scsi_set_resid(sc, icmnd_cmpl->residual);
 
@@ -938,50 +938,52 @@  static void fnic_fcpio_icmnd_cmpl_handler(struct fnic *fnic,
 
 	case FCPIO_TIMEOUT:          /* request was timed out */
 		atomic64_inc(&fnic_stats->misc_stats.fcpio_timeout);
-		sc->result = (DID_TIME_OUT << 16) | icmnd_cmpl->scsi_status;
+		set_scsi_result(sc, 0, DID_TIME_OUT, 0,
+				icmnd_cmpl->scsi_status);
 		break;
 
 	case FCPIO_ABORTED:          /* request was aborted */
 		atomic64_inc(&fnic_stats->misc_stats.fcpio_aborted);
-		sc->result = (DID_ERROR << 16) | icmnd_cmpl->scsi_status;
+		set_scsi_result(sc, 0, DID_ERROR, 0, icmnd_cmpl->scsi_status);
 		break;
 
 	case FCPIO_DATA_CNT_MISMATCH: /* recv/sent more/less data than exp. */
 		atomic64_inc(&fnic_stats->misc_stats.data_count_mismatch);
 		scsi_set_resid(sc, icmnd_cmpl->residual);
-		sc->result = (DID_ERROR << 16) | icmnd_cmpl->scsi_status;
+		set_scsi_result(sc, 0, DID_ERROR, 0, icmnd_cmpl->scsi_status);
 		break;
 
 	case FCPIO_OUT_OF_RESOURCE:  /* out of resources to complete request */
 		atomic64_inc(&fnic_stats->fw_stats.fw_out_of_resources);
-		sc->result = (DID_REQUEUE << 16) | icmnd_cmpl->scsi_status;
+		set_scsi_result(sc, 0, DID_REQUEUE, 0,
+				icmnd_cmpl->scsi_status);
 		break;
 
 	case FCPIO_IO_NOT_FOUND:     /* requested I/O was not found */
 		atomic64_inc(&fnic_stats->io_stats.io_not_found);
-		sc->result = (DID_ERROR << 16) | icmnd_cmpl->scsi_status;
+		set_scsi_result(sc, 0, DID_ERROR, 0, icmnd_cmpl->scsi_status);
 		break;
 
 	case FCPIO_SGL_INVALID:      /* request was aborted due to sgl error */
 		atomic64_inc(&fnic_stats->misc_stats.sgl_invalid);
-		sc->result = (DID_ERROR << 16) | icmnd_cmpl->scsi_status;
+		set_scsi_result(sc, 0, DID_ERROR, 0, icmnd_cmpl->scsi_status);
 		break;
 
 	case FCPIO_FW_ERR:           /* request was terminated due fw error */
 		atomic64_inc(&fnic_stats->fw_stats.io_fw_errs);
-		sc->result = (DID_ERROR << 16) | icmnd_cmpl->scsi_status;
+		set_scsi_result(sc, 0, DID_ERROR, 0, icmnd_cmpl->scsi_status);
 		break;
 
 	case FCPIO_MSS_INVALID:      /* request was aborted due to mss error */
 		atomic64_inc(&fnic_stats->misc_stats.mss_invalid);
-		sc->result = (DID_ERROR << 16) | icmnd_cmpl->scsi_status;
+		set_scsi_result(sc, 0, DID_ERROR, 0, icmnd_cmpl->scsi_status);
 		break;
 
 	case FCPIO_INVALID_HEADER:   /* header contains invalid data */
 	case FCPIO_INVALID_PARAM:    /* some parameter in request invalid */
 	case FCPIO_REQ_NOT_SUPPORTED:/* request type is not supported */
 	default:
-		sc->result = (DID_ERROR << 16) | icmnd_cmpl->scsi_status;
+		set_scsi_result(sc, 0, DID_ERROR, 0, icmnd_cmpl->scsi_status);
 		break;
 	}
 
diff --git a/drivers/scsi/gdth.c b/drivers/scsi/gdth.c
index 61d1576028f5..e34b567a9976 100644
--- a/drivers/scsi/gdth.c
+++ b/drivers/scsi/gdth.c
@@ -2127,7 +2127,7 @@  static void gdth_next(gdth_ha_str *ha)
                 memset((char*)nscp->sense_buffer,0,16);
                 nscp->sense_buffer[0] = 0x70;
                 nscp->sense_buffer[2] = NOT_READY;
-                nscp->result = (DID_OK << 16) | (CHECK_CONDITION << 1);
+                set_scsi_result(nscp, 0, DID_OK, 0, (CHECK_CONDITION << 1));
                 if (!nscp_cmndinfo->wait_for_completion)
                     nscp_cmndinfo->wait_for_completion++;
                 else
@@ -2172,7 +2172,8 @@  static void gdth_next(gdth_ha_str *ha)
                     memset((char*)nscp->sense_buffer,0,16);
                     nscp->sense_buffer[0] = 0x70;
                     nscp->sense_buffer[2] = UNIT_ATTENTION;
-                    nscp->result = (DID_OK << 16) | (CHECK_CONDITION << 1);
+                    set_scsi_result(nscp, 0, DID_OK, 0,
+                                    (CHECK_CONDITION << 1));
                     if (!nscp_cmndinfo->wait_for_completion)
                         nscp_cmndinfo->wait_for_completion++;
                     else
@@ -2224,7 +2225,8 @@  static void gdth_next(gdth_ha_str *ha)
                     memset((char*)nscp->sense_buffer,0,16);
                     nscp->sense_buffer[0] = 0x70;
                     nscp->sense_buffer[2] = UNIT_ATTENTION;
-                    nscp->result = (DID_OK << 16) | (CHECK_CONDITION << 1);
+                    set_scsi_result(nscp, 0, DID_OK, 0,
+                                    (CHECK_CONDITION << 1));
                     if (!nscp_cmndinfo->wait_for_completion)
                         nscp_cmndinfo->wait_for_completion++;
                     else
@@ -3381,7 +3383,7 @@  static int gdth_sync_event(gdth_ha_str *ha, int service, u8 index,
                 memset((char*)scp->sense_buffer,0,16);
                 scp->sense_buffer[0] = 0x70;
                 scp->sense_buffer[2] = NOT_READY;
-                scp->result = (DID_OK << 16) | (CHECK_CONDITION << 1);
+                set_scsi_result(scp, 0, DID_OK, 0, (CHECK_CONDITION << 1));
             } else if (service == CACHESERVICE) {
                 if (ha->status == S_CACHE_UNKNOWN &&
                     (ha->hdr[t].cluster_type & 
@@ -3391,11 +3393,12 @@  static int gdth_sync_event(gdth_ha_str *ha, int service, u8 index,
                 }
                 memset((char*)scp->sense_buffer,0,16);
                 if (ha->status == (u16)S_CACHE_RESERV) {
-                    scp->result = (DID_OK << 16) | (RESERVATION_CONFLICT << 1);
+                    set_scsi_result(scp, 0, DID_OK, 0,
+                                    (RESERVATION_CONFLICT << 1));
                 } else {
                     scp->sense_buffer[0] = 0x70;
                     scp->sense_buffer[2] = NOT_READY;
-                    scp->result = (DID_OK << 16) | (CHECK_CONDITION << 1);
+                    set_scsi_result(scp, 0, DID_OK, 0, (CHECK_CONDITION << 1));
                 }
                 if (!cmndinfo->internal_command) {
                     ha->dvr.size = sizeof(ha->dvr.eu.sync);
@@ -3414,7 +3417,7 @@  static int gdth_sync_event(gdth_ha_str *ha, int service, u8 index,
                 if (ha->status != S_RAW_SCSI || ha->info >= 0x100) {
                     scp->result = DID_BAD_TARGET << 16;
                 } else {
-                    scp->result = (DID_OK << 16) | ha->info;
+                    set_scsi_result(scp, 0, DID_OK, 0, ha->info);
                 }
             }
         }
diff --git a/drivers/scsi/hptiop.c b/drivers/scsi/hptiop.c
index 2fad7f03aa02..9951700712f1 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,
 		break;
 
 	default:
-		scp->result = DRIVER_INVALID << 24 | DID_ABORT << 16;
+		set_scsi_result(scp, DRIVER_INVALID, DID_ABORT, 0, 0);
 		break;
 	}
 
diff --git a/drivers/scsi/imm.c b/drivers/scsi/imm.c
index 690c0e25ea51..a64b52672adc 100644
--- a/drivers/scsi/imm.c
+++ b/drivers/scsi/imm.c
@@ -892,7 +892,7 @@  static int imm_engine(imm_struct *dev, struct scsi_cmnd *cmd)
 			/* Check for optional message byte */
 			if (imm_wait(dev) == (unsigned char) 0xb8)
 				imm_in(dev, &h, 1);
-			cmd->result = (DID_OK << 16) + (l & STATUS_MASK);
+			set_scsi_result(cmd, 0, DID_OK, 0, l & STATUS_MASK);
 		}
 		if ((dev->mode == IMM_NIBBLE) || (dev->mode == IMM_PS2)) {
 			w_ctr(ppb, 0x4);
diff --git a/drivers/scsi/initio.c b/drivers/scsi/initio.c
index 7a91cf3ff173..9f0525f375e3 100644
--- a/drivers/scsi/initio.c
+++ b/drivers/scsi/initio.c
@@ -2802,7 +2802,7 @@  static void i91uSCBPost(u8 * host_mem, u8 * cblk_mem)
 		break;
 	}
 
-	cmnd->result = cblk->tastat | (cblk->hastat << 16);
+	set_scsi_result(cmnd, 0, cblk->hastat, 0, cblk->tastat);
 	i91u_unmap_scb(host->pci_dev, cmnd);
 	cmnd->scsi_done(cmnd);	/* Notify system DONE           */
 	initio_release_scb(host, cblk);	/* Release SCB for current channel */
diff --git a/drivers/scsi/ips.c b/drivers/scsi/ips.c
index e3c8857741a1..c297abaab513 100644
--- a/drivers/scsi/ips.c
+++ b/drivers/scsi/ips.c
@@ -3370,7 +3370,7 @@  ips_map_status(ips_ha_t * ha, ips_scb_t * scb, ips_stat_t * sp)
 		}		/* end switch */
 	}			/* end switch */
 
-	scb->scsi_cmd->result = device_error | (errcode << 16);
+	set_scsi_result(scb->scsi_cmd, 0, errcode, 0, device_error);
 
 	return (1);
 }
@@ -3706,7 +3706,8 @@  ips_send_cmd(ips_ha_t * ha, ips_scb_t * scb)
 			sp[13] = 0x00;	/* ASCQ                     */
 
 			device_error = 2;	/* Indicate Check Condition */
-			scb->scsi_cmd->result = device_error | (DID_OK << 16);
+			set_scsi_result(scb->scsi_cmd, 0, DID_OK, 0,
+					device_error);
 			break;
 		}		/* end switch */
 	}
diff --git a/drivers/scsi/libfc/fc_fcp.c b/drivers/scsi/libfc/fc_fcp.c
index 4fae253d4f3d..c101d4e226c7 100644
--- a/drivers/scsi/libfc/fc_fcp.c
+++ b/drivers/scsi/libfc/fc_fcp.c
@@ -2010,7 +2010,7 @@  static void fc_io_compl(struct fc_fcp_pkt *fsp)
 			 * transport level I/O was ok but scsi
 			 * has non zero status
 			 */
-			sc_cmd->result = (DID_OK << 16) | fsp->cdb_status;
+			set_scsi_result(sc_cmd, 0, DID_OK, 0, fsp->cdb_status);
 		}
 		break;
 	case FC_ERROR:
@@ -2038,7 +2038,8 @@  static void fc_io_compl(struct fc_fcp_pkt *fsp)
 			FC_FCP_DBG(fsp, "Returning DID_ERROR to scsi-ml "
 				   "due to FC_DATA_UNDRUN (scsi)\n");
 			CMD_RESID_LEN(sc_cmd) = fsp->scsi_resid;
-			sc_cmd->result = (DID_ERROR << 16) | fsp->cdb_status;
+			set_scsi_result(sc_cmd, 0, DID_ERROR, 0,
+					fsp->cdb_status);
 		}
 		break;
 	case FC_DATA_OVRRUN:
@@ -2047,7 +2048,7 @@  static void fc_io_compl(struct fc_fcp_pkt *fsp)
 		 */
 		FC_FCP_DBG(fsp, "Returning DID_ERROR to scsi-ml "
 			   "due to FC_DATA_OVRRUN\n");
-		sc_cmd->result = (DID_ERROR << 16) | fsp->cdb_status;
+		set_scsi_result(sc_cmd, 0, DID_ERROR, 0, fsp->cdb_status);
 		break;
 	case FC_CMD_ABORTED:
 		if (host_byte(sc_cmd->result) == DID_TIME_OUT)
@@ -2083,7 +2084,7 @@  static void fc_io_compl(struct fc_fcp_pkt *fsp)
 	case FC_TIMED_OUT:
 		FC_FCP_DBG(fsp, "Returning DID_BUS_BUSY to scsi-ml "
 			   "due to FC_TIMED_OUT\n");
-		sc_cmd->result = (DID_BUS_BUSY << 16) | fsp->io_status;
+		set_scsi_result(sc_cmd, 0, DID_BUS_BUSY, 0, fsp->io_status);
 		break;
 	default:
 		FC_FCP_DBG(fsp, "Returning DID_ERROR to scsi-ml "
diff --git a/drivers/scsi/libiscsi.c b/drivers/scsi/libiscsi.c
index 15a2fef51e38..fa9082507049 100644
--- a/drivers/scsi/libiscsi.c
+++ b/drivers/scsi/libiscsi.c
@@ -841,7 +841,7 @@  static void iscsi_scsi_cmd_rsp(struct iscsi_conn *conn, struct iscsi_hdr *hdr,
 	iscsi_update_cmdsn(session, (struct iscsi_nopin*)rhdr);
 	conn->exp_statsn = be32_to_cpu(rhdr->statsn) + 1;
 
-	sc->result = (DID_OK << 16) | rhdr->cmd_status;
+	set_scsi_result(sc, 0, DID_OK, 0, rhdr->cmd_status);
 
 	if (task->protected) {
 		sector_t sector;
@@ -856,8 +856,9 @@  static void iscsi_scsi_cmd_rsp(struct iscsi_conn *conn, struct iscsi_hdr *hdr,
 
 		ascq = session->tt->check_protection(task, &sector);
 		if (ascq) {
-			sc->result = DRIVER_SENSE << 24 |
-				     SAM_STAT_CHECK_CONDITION;
+			sc->result = 0;
+			set_scsi_result(sc, DRIVER_SENSE, 0, 0,
+					SAM_STAT_CHECK_CONDITION);
 			scsi_build_sense_buffer(1, sc->sense_buffer,
 						ILLEGAL_REQUEST, 0x10, ascq);
 			scsi_set_sense_information(sc->sense_buffer,
@@ -904,7 +905,8 @@  static void iscsi_scsi_cmd_rsp(struct iscsi_conn *conn, struct iscsi_hdr *hdr,
 				 res_count <= scsi_in(sc)->length))
 			scsi_in(sc)->resid = res_count;
 		else
-			sc->result = (DID_BAD_TARGET << 16) | rhdr->cmd_status;
+			set_scsi_result(sc, 0, DID_BAD_TARGET, 0,
+					rhdr->cmd_status);
 	}
 
 	if (rhdr->flags & (ISCSI_FLAG_CMD_UNDERFLOW |
@@ -917,7 +919,8 @@  static void iscsi_scsi_cmd_rsp(struct iscsi_conn *conn, struct iscsi_hdr *hdr,
 			/* write side for bidi or uni-io set_resid */
 			scsi_set_resid(sc, res_count);
 		else
-			sc->result = (DID_BAD_TARGET << 16) | rhdr->cmd_status;
+			set_scsi_result(sc, 0, DID_BAD_TARGET, 0,
+					rhdr->cmd_status);
 	}
 out:
 	ISCSI_DBG_SESSION(session, "cmd rsp done [sc %p res %d itt 0x%x]\n",
@@ -943,7 +946,7 @@  iscsi_data_in_rsp(struct iscsi_conn *conn, struct iscsi_hdr *hdr,
 		return;
 
 	iscsi_update_cmdsn(conn->session, (struct iscsi_nopin *)hdr);
-	sc->result = (DID_OK << 16) | rhdr->cmd_status;
+	set_scsi_result(sc, 0, DID_OK, 0, rhdr->cmd_status);
 	conn->exp_statsn = be32_to_cpu(rhdr->statsn) + 1;
 	if (rhdr->flags & (ISCSI_FLAG_DATA_UNDERFLOW |
 	                   ISCSI_FLAG_DATA_OVERFLOW)) {
@@ -954,7 +957,8 @@  iscsi_data_in_rsp(struct iscsi_conn *conn, struct iscsi_hdr *hdr,
 		     res_count <= scsi_in(sc)->length))
 			scsi_in(sc)->resid = res_count;
 		else
-			sc->result = (DID_BAD_TARGET << 16) | rhdr->cmd_status;
+			set_scsi_result(sc, 0, DID_BAD_TARGET, 0,
+					rhdr->cmd_status);
 	}
 
 	ISCSI_DBG_SESSION(conn->session, "data in with status done "
diff --git a/drivers/scsi/libsas/sas_scsi_host.c b/drivers/scsi/libsas/sas_scsi_host.c
index ceab5e5c41c2..81f9ec462df5 100644
--- a/drivers/scsi/libsas/sas_scsi_host.c
+++ b/drivers/scsi/libsas/sas_scsi_host.c
@@ -111,7 +111,7 @@  static void sas_end_task(struct scsi_cmnd *sc, struct sas_task *task)
 		}
 	}
 
-	sc->result = (hs << 16) | stat;
+	set_scsi_result(sc, 0, hs, 0, stat);
 	ASSIGN_SAS_TASK(sc, NULL);
 	sas_free_task(task);
 }
diff --git a/drivers/scsi/lpfc/lpfc_crtn.h b/drivers/scsi/lpfc/lpfc_crtn.h
index 4ae9ba425e78..30f9e3ff6cb5 100644
--- a/drivers/scsi/lpfc/lpfc_crtn.h
+++ b/drivers/scsi/lpfc/lpfc_crtn.h
@@ -469,7 +469,6 @@  int lpfc_parse_vpd(struct lpfc_hba *, uint8_t *, int);
 void lpfc_start_fdiscs(struct lpfc_hba *phba);
 struct lpfc_vport *lpfc_find_vport_by_vpid(struct lpfc_hba *, uint16_t);
 struct lpfc_sglq *__lpfc_get_active_sglq(struct lpfc_hba *, uint16_t);
-#define ScsiResult(host_code, scsi_code) (((host_code) << 16) | scsi_code)
 #define HBA_EVENT_RSCN                   5
 #define HBA_EVENT_LINK_UP                2
 #define HBA_EVENT_LINK_DOWN              3
diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
index 050f04418f5f..ee23f9a4d4ab 100644
--- a/drivers/scsi/lpfc/lpfc_scsi.c
+++ b/drivers/scsi/lpfc/lpfc_scsi.c
@@ -3017,8 +3017,9 @@  lpfc_calc_bg_err(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd)
 	if (err_type == BGS_GUARD_ERR_MASK) {
 		scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST,
 					0x10, 0x1);
-		cmd->result = DRIVER_SENSE << 24
-			| ScsiResult(DID_ABORT, SAM_STAT_CHECK_CONDITION);
+		cmd->result = 0;
+		set_scsi_result(cmd, DRIVER_SENSE, DID_ABORT, 0,
+				SAM_STAT_CHECK_CONDITION);
 		phba->bg_guard_err_cnt++;
 		lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG,
 				"9069 BLKGRD: LBA %lx grd_tag error %x != %x\n",
@@ -3028,8 +3029,9 @@  lpfc_calc_bg_err(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd)
 	} else if (err_type == BGS_REFTAG_ERR_MASK) {
 		scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST,
 					0x10, 0x3);
-		cmd->result = DRIVER_SENSE << 24
-			| ScsiResult(DID_ABORT, SAM_STAT_CHECK_CONDITION);
+		cmd->result = 0;
+		set_scsi_result(cmd, DRIVER_SENSE, DID_ABORT, 0,
+				SAM_STAT_CHECK_CONDITION);
 
 		phba->bg_reftag_err_cnt++;
 		lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG,
@@ -3040,8 +3042,9 @@  lpfc_calc_bg_err(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd)
 	} else if (err_type == BGS_APPTAG_ERR_MASK) {
 		scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST,
 					0x10, 0x2);
-		cmd->result = DRIVER_SENSE << 24
-			| ScsiResult(DID_ABORT, SAM_STAT_CHECK_CONDITION);
+		cmd->result = 0;
+		set_scsi_result(cmd, DRIVER_SENSE, DID_ABORT, 0,
+				SAM_STAT_CHECK_CONDITION);
 
 		phba->bg_apptag_err_cnt++;
 		lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG,
@@ -3096,7 +3099,7 @@  lpfc_parse_bg_err(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd,
 	spin_unlock(&_dump_buf_lock);
 
 	if (lpfc_bgs_get_invalid_prof(bgstat)) {
-		cmd->result = ScsiResult(DID_ERROR, 0);
+		set_scsi_result(cmd, 0, DID_ERROR, 0, 0);
 		lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG,
 				"9072 BLKGRD: Invalid BG Profile in cmd"
 				" 0x%x lba 0x%llx blk cnt 0x%x "
@@ -3108,7 +3111,7 @@  lpfc_parse_bg_err(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd,
 	}
 
 	if (lpfc_bgs_get_uninit_dif_block(bgstat)) {
-		cmd->result = ScsiResult(DID_ERROR, 0);
+		set_scsi_result(cmd, 0, DID_ERROR, 0, 0);
 		lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG,
 				"9073 BLKGRD: Invalid BG PDIF Block in cmd"
 				" 0x%x lba 0x%llx blk cnt 0x%x "
@@ -3124,8 +3127,9 @@  lpfc_parse_bg_err(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd,
 
 		scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST,
 				0x10, 0x1);
-		cmd->result = DRIVER_SENSE << 24
-			| ScsiResult(DID_ABORT, SAM_STAT_CHECK_CONDITION);
+		cmd->result = 0;
+		set_scsi_result(cmd, DRIVER_SENSE, DID_ABORT, 0,
+				SAM_STAT_CHECK_CONDITION);
 		phba->bg_guard_err_cnt++;
 		lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG,
 				"9055 BLKGRD: Guard Tag error in cmd"
@@ -3140,9 +3144,9 @@  lpfc_parse_bg_err(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd,
 
 		scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST,
 				0x10, 0x3);
-		cmd->result = DRIVER_SENSE << 24
-			| ScsiResult(DID_ABORT, SAM_STAT_CHECK_CONDITION);
-
+		cmd->result = 0;
+		set_scsi_result(cmd, DRIVER_SENSE, DID_ABORT, 0,
+				SAM_STAT_CHECK_CONDITION);
 		phba->bg_reftag_err_cnt++;
 		lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG,
 				"9056 BLKGRD: Ref Tag error in cmd"
@@ -3157,8 +3161,9 @@  lpfc_parse_bg_err(struct lpfc_hba *phba, struct lpfc_scsi_buf *lpfc_cmd,
 
 		scsi_build_sense_buffer(1, cmd->sense_buffer, ILLEGAL_REQUEST,
 				0x10, 0x2);
-		cmd->result = DRIVER_SENSE << 24
-			| ScsiResult(DID_ABORT, SAM_STAT_CHECK_CONDITION);
+		cmd->result = 0;
+		set_scsi_result(cmd, DRIVER_SENSE, DID_ABORT, 0,
+				SAM_STAT_CHECK_CONDITION);
 
 		phba->bg_apptag_err_cnt++;
 		lpfc_printf_log(phba, KERN_WARNING, LOG_FCP | LOG_BG,
@@ -3866,7 +3871,7 @@  lpfc_handle_fcp_err(struct lpfc_vport *vport, struct lpfc_scsi_buf *lpfc_cmd,
 	}
 
  out:
-	cmnd->result = ScsiResult(host_status, scsi_status);
+	set_scsi_result(cmnd, 0, host_status, 0, scsi_status);
 	lpfc_send_scsi_error_event(vport->phba, vport, lpfc_cmd, rsp_iocb);
 }
 
@@ -4022,7 +4027,7 @@  lpfc_scsi_cmd_iocb_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *pIocbIn,
 			break;
 		case IOSTAT_NPORT_BSY:
 		case IOSTAT_FABRIC_BSY:
-			cmd->result = ScsiResult(DID_TRANSPORT_DISRUPTED, 0);
+			set_scsi_result(cmd, 0, DID_TRANSPORT_DISRUPTED, 0, 0);
 			fast_path_evt = lpfc_alloc_fast_evt(phba);
 			if (!fast_path_evt)
 				break;
@@ -4056,14 +4061,14 @@  lpfc_scsi_cmd_iocb_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *pIocbIn,
 			    lpfc_cmd->result == IOERR_ELXSEC_CRYPTO_ERROR ||
 			    lpfc_cmd->result ==
 					IOERR_ELXSEC_CRYPTO_COMPARE_ERROR) {
-				cmd->result = ScsiResult(DID_NO_CONNECT, 0);
+				set_scsi_result(cmd, 0, DID_NO_CONNECT, 0, 0);
 				break;
 			}
 			if (lpfc_cmd->result == IOERR_INVALID_RPI ||
 			    lpfc_cmd->result == IOERR_NO_RESOURCES ||
 			    lpfc_cmd->result == IOERR_ABORT_REQUESTED ||
 			    lpfc_cmd->result == IOERR_SLER_CMD_RCV_FAILURE) {
-				cmd->result = ScsiResult(DID_REQUEUE, 0);
+				set_scsi_result(cmd, 0, DID_REQUEUE, 0, 0);
 				break;
 			}
 			if ((lpfc_cmd->result == IOERR_RX_DMA_FAILED ||
@@ -4097,16 +4102,16 @@  lpfc_scsi_cmd_iocb_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *pIocbIn,
 			}
 		/* else: fall through */
 		default:
-			cmd->result = ScsiResult(DID_ERROR, 0);
+			set_scsi_result(cmd, 0, DID_ERROR, 0, 0);
 			break;
 		}
 
 		if (!pnode || !NLP_CHK_NODE_ACT(pnode)
 		    || (pnode->nlp_state != NLP_STE_MAPPED_NODE))
-			cmd->result = ScsiResult(DID_TRANSPORT_DISRUPTED,
-						 SAM_STAT_BUSY);
+			set_scsi_result(cmd, 0, DID_TRANSPORT_DISRUPTED, 0,
+					SAM_STAT_BUSY);
 	} else
-		cmd->result = ScsiResult(DID_OK, 0);
+		set_scsi_result(cmd, 0, DID_OK, 0, 0);
 
 	if (cmd->result || lpfc_cmd->fcp_rsp->rspSnsLen) {
 		uint32_t *lp = (uint32_t *)cmd->sense_buffer;
diff --git a/drivers/scsi/megaraid.c b/drivers/scsi/megaraid.c
index 284bc8c4c6d5..300fa4a93124 100644
--- a/drivers/scsi/megaraid.c
+++ b/drivers/scsi/megaraid.c
@@ -1586,9 +1586,8 @@  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);
+				set_scsi_result(cmd, DRIVER_SENSE, DID_OK, 0,
+						CHECK_CONDITION << 1);
 			}
 			else {
 				if (mbox->m_out.cmd == MEGA_MBOXCMD_EXTPTHRU) {
@@ -1596,9 +1595,8 @@  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);
+					set_scsi_result(cmd, DRIVER_SENSE, DID_OK, 0,
+							CHECK_CONDITION << 1);
 				} else {
 					cmd->sense_buffer[0] = 0x70;
 					cmd->sense_buffer[2] = ABORTED_COMMAND;
diff --git a/drivers/scsi/megaraid/megaraid_mbox.c b/drivers/scsi/megaraid/megaraid_mbox.c
index 530358cdcb39..0d7f261fff35 100644
--- a/drivers/scsi/megaraid/megaraid_mbox.c
+++ b/drivers/scsi/megaraid/megaraid_mbox.c
@@ -2347,8 +2347,8 @@  megaraid_mbox_dpc(unsigned long devp)
 				memcpy(scp->sense_buffer, pthru->reqsensearea,
 						14);
 
-				scp->result = DRIVER_SENSE << 24 |
-					DID_OK << 16 | CHECK_CONDITION << 1;
+				set_scsi_result(scp, DRIVER_SENSE, DID_OK, 0,
+						CHECK_CONDITION << 1);
 			}
 			else {
 				if (mbox->cmd == MBOXCMD_EXTPTHRU) {
@@ -2356,9 +2356,9 @@  megaraid_mbox_dpc(unsigned long devp)
 					memcpy(scp->sense_buffer,
 						epthru->reqsensearea, 14);
 
-					scp->result = DRIVER_SENSE << 24 |
-						DID_OK << 16 |
-						CHECK_CONDITION << 1;
+					set_scsi_result(scp, DRIVER_SENSE,
+							DID_OK, 0,
+							CHECK_CONDITION << 1);
 				} else {
 					scp->sense_buffer[0] = 0x70;
 					scp->sense_buffer[2] = ABORTED_COMMAND;
@@ -2369,7 +2369,7 @@  megaraid_mbox_dpc(unsigned long devp)
 
 		case 0x08:
 
-			scp->result = DID_BUS_BUSY << 16 | status;
+			set_scsi_result(scp, 0, DID_BUS_BUSY, 0, status);
 			break;
 
 		default:
@@ -2379,8 +2379,8 @@  megaraid_mbox_dpc(unsigned long devp)
 			 * failed
 			 */
 			if (scp->cmnd[0] == TEST_UNIT_READY) {
-				scp->result = DID_ERROR << 16 |
-					RESERVATION_CONFLICT << 1;
+				set_scsi_result(scp, 0, DID_ERROR, 0,
+						RESERVATION_CONFLICT << 1);
 			}
 			else
 			/*
@@ -2390,11 +2390,12 @@  megaraid_mbox_dpc(unsigned long devp)
 			if (status == 1 && (scp->cmnd[0] == RESERVE ||
 					 scp->cmnd[0] == RELEASE)) {
 
-				scp->result = DID_ERROR << 16 |
-					RESERVATION_CONFLICT << 1;
+				set_scsi_result(scp, 0, DID_ERROR, 0,
+						RESERVATION_CONFLICT << 1);
 			}
 			else {
-				scp->result = DID_BAD_TARGET << 16 | status;
+				set_scsi_result(scp, 0, DID_BAD_TARGET, 0,
+						status);
 			}
 		}
 
diff --git a/drivers/scsi/megaraid/megaraid_sas_base.c b/drivers/scsi/megaraid/megaraid_sas_base.c
index b89c6e6c0589..9c3dec24b6bf 100644
--- a/drivers/scsi/megaraid/megaraid_sas_base.c
+++ b/drivers/scsi/megaraid/megaraid_sas_base.c
@@ -3294,13 +3294,14 @@  megasas_complete_cmd(struct megasas_instance *instance, struct megasas_cmd *cmd,
 
 		case MFI_STAT_SCSI_IO_FAILED:
 		case MFI_STAT_LD_INIT_IN_PROGRESS:
-			cmd->scmd->result =
-			    (DID_ERROR << 16) | hdr->scsi_status;
+			set_scsi_result(cmd->scmd, 0, DID_ERROR, 0,
+					hdr->scsi_status);
 			break;
 
 		case MFI_STAT_SCSI_DONE_WITH_ERROR:
 
-			cmd->scmd->result = (DID_OK << 16) | hdr->scsi_status;
+			set_scsi_result(cmd->scmd, 0, DID_OK, 0,
+					hdr->scsi_status);
 
 			if (hdr->scsi_status == SAM_STAT_CHECK_CONDITION) {
 				memset(cmd->scmd->sense_buffer, 0,
diff --git a/drivers/scsi/megaraid/megaraid_sas_fusion.c b/drivers/scsi/megaraid/megaraid_sas_fusion.c
index ce97cde3b41c..8c5757d5770a 100644
--- a/drivers/scsi/megaraid/megaraid_sas_fusion.c
+++ b/drivers/scsi/megaraid/megaraid_sas_fusion.c
@@ -1784,12 +1784,12 @@  map_cmd_status(struct fusion_context *fusion,
 
 	case MFI_STAT_SCSI_IO_FAILED:
 	case MFI_STAT_LD_INIT_IN_PROGRESS:
-		scmd->result = (DID_ERROR << 16) | ext_status;
+		set_scsi_result(scmd, 0, DID_ERROR, 0, ext_status);
 		break;
 
 	case MFI_STAT_SCSI_DONE_WITH_ERROR:
 
-		scmd->result = (DID_OK << 16) | ext_status;
+		set_scsi_result(scmd, 0, DID_OK, 0, ext_status);
 		if (ext_status == SAM_STAT_CHECK_CONDITION) {
 			memset(scmd->sense_buffer, 0,
 			       SCSI_SENSE_BUFFERSIZE);
diff --git a/drivers/scsi/mesh.c b/drivers/scsi/mesh.c
index 1753e42826dd..15b75e696117 100644
--- a/drivers/scsi/mesh.c
+++ b/drivers/scsi/mesh.c
@@ -594,7 +594,7 @@  static void mesh_done(struct mesh_state *ms, int start_next)
 	ms->current_req = NULL;
 	tp->current_req = NULL;
 	if (cmd) {
-		cmd->result = (ms->stat << 16) + cmd->SCp.Status;
+		set_scsi_result(cmd, 0, ms->stat, 0, cmd->SCp.Status);
 		if (ms->stat == DID_OK)
 			cmd->result += (cmd->SCp.Message << 8);
 		if (DEBUG_TARGET(cmd)) {
diff --git a/drivers/scsi/mpt3sas/mpt3sas_scsih.c b/drivers/scsi/mpt3sas/mpt3sas_scsih.c
index 8cd3782fab49..7328bf9917f2 100644
--- a/drivers/scsi/mpt3sas/mpt3sas_scsih.c
+++ b/drivers/scsi/mpt3sas/mpt3sas_scsih.c
@@ -4557,8 +4557,8 @@  _scsih_eedp_error_handling(struct scsi_cmnd *scmd, u16 ioc_status)
 	}
 	scsi_build_sense_buffer(0, scmd->sense_buffer, ILLEGAL_REQUEST, 0x10,
 	    ascq);
-	scmd->result = DRIVER_SENSE << 24 | (DID_ABORT << 16) |
-	    SAM_STAT_CHECK_CONDITION;
+	set_scsi_result(scmd, DRIVER_SENSE, DID_ABORT, 0,
+			SAM_STAT_CHECK_CONDITION);
 }
 
 /**
@@ -5323,11 +5323,11 @@  _scsih_io_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
 		if ((xfer_cnt == 0) || (scmd->underflow > xfer_cnt))
 			scmd->result = DID_SOFT_ERROR << 16;
 		else
-			scmd->result = (DID_OK << 16) | scsi_status;
+			set_scsi_result(scmd, 0, DID_OK, 0, scsi_status);
 		break;
 
 	case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN:
-		scmd->result = (DID_OK << 16) | scsi_status;
+		set_scsi_result(scmd, 0, DID_OK, 0, scsi_status);
 
 		if ((scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID))
 			break;
@@ -5345,8 +5345,8 @@  _scsih_io_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
 		else if (!xfer_cnt && scmd->cmnd[0] == REPORT_LUNS) {
 			mpi_reply->SCSIState = MPI2_SCSI_STATE_AUTOSENSE_VALID;
 			mpi_reply->SCSIStatus = SAM_STAT_CHECK_CONDITION;
-			scmd->result = (DRIVER_SENSE << 24) |
-			    SAM_STAT_CHECK_CONDITION;
+			set_scsi_result(scmd, DRIVER_SENSE, 0, 0,
+					SAM_STAT_CHECK_CONDITION);
 			scmd->sense_buffer[0] = 0x70;
 			scmd->sense_buffer[2] = ILLEGAL_REQUEST;
 			scmd->sense_buffer[12] = 0x20;
@@ -5358,7 +5358,7 @@  _scsih_io_done(struct MPT3SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
 		scsi_set_resid(scmd, 0);
 	case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR:
 	case MPI2_IOCSTATUS_SUCCESS:
-		scmd->result = (DID_OK << 16) | scsi_status;
+		set_scsi_result(scmd, 0, DID_OK, 0, scsi_status);
 		if (response_code ==
 		    MPI2_SCSITASKMGMT_RSP_INVALID_FRAME ||
 		    (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED |
diff --git a/drivers/scsi/mvumi.c b/drivers/scsi/mvumi.c
index fe97401ad192..570e7ff481a3 100644
--- a/drivers/scsi/mvumi.c
+++ b/drivers/scsi/mvumi.c
@@ -2081,8 +2081,8 @@  static unsigned char mvumi_build_frame(struct mvumi_hba *mhba,
 	return 0;
 
 error:
-	scmd->result = (DID_OK << 16) | (DRIVER_SENSE << 24) |
-		SAM_STAT_CHECK_CONDITION;
+	set_scsi_result(scmd, DRIVER_SENSE, DID_OK, 0,
+			SAM_STAT_CHECK_CONDITION);
 	scsi_build_sense_buffer(0, scmd->sense_buffer, ILLEGAL_REQUEST, 0x24,
 									0);
 	return -1;
@@ -2145,7 +2145,7 @@  static enum blk_eh_timer_return mvumi_timed_out(struct scsi_cmnd *scmd)
 	else
 		atomic_dec(&mhba->fw_outstanding);
 
-	scmd->result = (DRIVER_INVALID << 24) | (DID_ABORT << 16);
+	set_scsi_result(scmd, DRIVER_INVALID, DID_ABORT, 0, 0);
 	scmd->SCp.ptr = NULL;
 	if (scsi_bufflen(scmd)) {
 		pci_unmap_sg(mhba->pdev, scsi_sglist(scmd),
diff --git a/drivers/scsi/ncr53c8xx.c b/drivers/scsi/ncr53c8xx.c
index dc4e801b2cef..db627bf80b7d 100644
--- a/drivers/scsi/ncr53c8xx.c
+++ b/drivers/scsi/ncr53c8xx.c
@@ -1010,8 +1010,6 @@  typedef u32 tagmap_t;
 **	Other definitions
 */
 
-#define ScsiResult(host_code, scsi_code) (((host_code) << 16) + ((scsi_code) & 0x7f))
-
 #define initverbose (driver_setup.verbose)
 #define bootverbose (np->verbose)
 
@@ -4611,7 +4609,7 @@  static int ncr_reset_bus (struct ncb *np, struct scsi_cmnd *cmd, int sync_reset)
  * in order to keep it alive.
  */
 	if (!found && sync_reset && !retrieve_from_waiting_list(0, np, cmd)) {
-		cmd->result = ScsiResult(DID_RESET, 0);
+		set_scsi_result(cmd, 0, DID_RESET, 0, 0);
 		ncr_queue_done_cmd(np, cmd);
 	}
 
@@ -4922,7 +4920,7 @@  void ncr_complete (struct ncb *np, struct ccb *cp)
 		 *	CONDITION MET status is returned on 
 		 *	`Pre-Fetch' or `Search data' success.
 		 */
-		cmd->result = ScsiResult(DID_OK, cp->scsi_status);
+		set_scsi_result(cmd, 0, DID_OK, 0, cp->scsi_status);
 
 		/*
 		**	@RESID@
@@ -4957,7 +4955,7 @@  void ncr_complete (struct ncb *np, struct ccb *cp)
 		/*
 		**   Check condition code
 		*/
-		cmd->result = ScsiResult(DID_OK, S_CHECK_COND);
+		set_scsi_result(cmd, 0, DID_OK, 0, S_CHECK_COND);
 
 		/*
 		**	Copy back sense data to caller's buffer.
@@ -4978,7 +4976,7 @@  void ncr_complete (struct ncb *np, struct ccb *cp)
 		/*
 		**   Reservation Conflict condition code
 		*/
-		cmd->result = ScsiResult(DID_OK, S_CONFLICT);
+		set_scsi_result(cmd, 0, DID_OK, 0, S_CONFLICT);
 	
 	} else if ((cp->host_status == HS_COMPLETE)
 		&& (cp->scsi_status == S_BUSY ||
@@ -4987,7 +4985,7 @@  void ncr_complete (struct ncb *np, struct ccb *cp)
 		/*
 		**   Target is busy.
 		*/
-		cmd->result = ScsiResult(DID_OK, cp->scsi_status);
+		set_scsi_result(cmd, 0, DID_OK, 0, cp->scsi_status);
 
 	} else if ((cp->host_status == HS_SEL_TIMEOUT)
 		|| (cp->host_status == HS_TIMEOUT)) {
@@ -4995,21 +4993,21 @@  void ncr_complete (struct ncb *np, struct ccb *cp)
 		/*
 		**   No response
 		*/
-		cmd->result = ScsiResult(DID_TIME_OUT, cp->scsi_status);
+		set_scsi_result(cmd, 0, DID_TIME_OUT, 0, cp->scsi_status);
 
 	} else if (cp->host_status == HS_RESET) {
 
 		/*
 		**   SCSI bus reset
 		*/
-		cmd->result = ScsiResult(DID_RESET, cp->scsi_status);
+		set_scsi_result(cmd, 0, DID_RESET, 0, cp->scsi_status);
 
 	} else if (cp->host_status == HS_ABORTED) {
 
 		/*
 		**   Transfer aborted
 		*/
-		cmd->result = ScsiResult(DID_ABORT, cp->scsi_status);
+		set_scsi_result(cmd, 0, DID_ABORT, 0, cp->scsi_status);
 
 	} else {
 
@@ -5019,7 +5017,7 @@  void ncr_complete (struct ncb *np, struct ccb *cp)
 		PRINT_ADDR(cmd, "COMMAND FAILED (%x %x) @%p.\n",
 			cp->host_status, cp->scsi_status, cp);
 
-		cmd->result = ScsiResult(DID_ERROR, cp->scsi_status);
+		set_scsi_result(cmd, 0, DID_ERROR, 0, cp->scsi_status);
 	}
 
 	/*
@@ -8043,7 +8041,7 @@  printk("ncr53c8xx_queue_command\n");
      spin_lock_irqsave(&np->smp_lock, flags);
 
      if ((sts = ncr_queue_command(np, cmd)) != DID_OK) {
-	  cmd->result = ScsiResult(sts, 0);
+	  set_scsi_result(cmd, 0, sts, 0, 0);
 #ifdef DEBUG_NCR53C8XX
 printk("ncr53c8xx : command not queued - result=%d\n", sts);
 #endif
@@ -8234,7 +8232,7 @@  static void process_waiting_list(struct ncb *np, int sts)
 #ifdef DEBUG_WAITING_LIST
 	printk("%s: cmd %lx done forced sts=%d\n", ncr_name(np), (u_long) wcmd, sts);
 #endif
-			wcmd->result = ScsiResult(sts, 0);
+			set_scsi_result(wcmd, 0, sts, 0, 0);
 			ncr_queue_done_cmd(np, wcmd);
 		}
 	}
diff --git a/drivers/scsi/nsp32.c b/drivers/scsi/nsp32.c
index 8620ac5d6e41..6576d03de365 100644
--- a/drivers/scsi/nsp32.c
+++ b/drivers/scsi/nsp32.c
@@ -1680,9 +1680,8 @@  static int nsp32_busfree_occur(struct scsi_cmnd *SCpnt, unsigned short execph)
 		nsp32_dbg(NSP32_DEBUG_BUSFREE, 
 			  "normal end stat=0x%x resid=0x%x\n",
 			  SCpnt->SCp.Status, scsi_get_resid(SCpnt));
-		SCpnt->result = (DID_OK             << 16) |
-			        (SCpnt->SCp.Message <<  8) |
-			        (SCpnt->SCp.Status  <<  0);
+		set_scsi_result(SCpnt, 0, DID_OK, SCpnt->SCp.Message,
+				SCpnt->SCp.Status);
 		nsp32_scsi_done(SCpnt);
 		/* All operation is done */
 		return TRUE;
diff --git a/drivers/scsi/pcmcia/nsp_cs.c b/drivers/scsi/pcmcia/nsp_cs.c
index 5fb6eefc6541..a4b6f16e33c7 100644
--- a/drivers/scsi/pcmcia/nsp_cs.c
+++ b/drivers/scsi/pcmcia/nsp_cs.c
@@ -1035,9 +1035,9 @@  static irqreturn_t nspintr(int irq, void *dev_id)
 
 		if(data->CurrentSC != NULL) {
 			tmpSC = data->CurrentSC;
-			tmpSC->result  = (DID_RESET                   << 16) |
-				         ((tmpSC->SCp.Message & 0xff) <<  8) |
-				         ((tmpSC->SCp.Status  & 0xff) <<  0);
+			set_scsi_result(tmpSC, 0, DID_RESET,
+					tmpSC->SCp.Message & 0xff,
+					tmpSC->SCp.Status  & 0xff);
 			nsp_scsi_done(tmpSC);
 		}
 		return IRQ_HANDLED;
@@ -1135,9 +1135,9 @@  static irqreturn_t nspintr(int irq, void *dev_id)
 		//*sync_neg       = SYNC_NOT_YET;
 
 		if ((tmpSC->SCp.Message == MSG_COMMAND_COMPLETE)) {     /* all command complete and return status */
-			tmpSC->result = (DID_OK		             << 16) |
-					((tmpSC->SCp.Message & 0xff) <<  8) |
-					((tmpSC->SCp.Status  & 0xff) <<  0);
+			set_scsi_result(tmpSC, 0, DID_OK,
+					tmpSC->SCp.Message & 0xff,
+					tmpSC->SCp.Status  & 0xff);
 			nsp_dbg(NSP_DEBUG_INTR, "command complete result=0x%x", tmpSC->result);
 			nsp_scsi_done(tmpSC);
 
diff --git a/drivers/scsi/pcmcia/sym53c500_cs.c b/drivers/scsi/pcmcia/sym53c500_cs.c
index 20011c8afbb5..28f5624eb6cd 100644
--- a/drivers/scsi/pcmcia/sym53c500_cs.c
+++ b/drivers/scsi/pcmcia/sym53c500_cs.c
@@ -409,8 +409,8 @@  SYM53C500_intr(int irq, void *dev_id)
 		if (curSC->SCp.phase != message_in) {	/* Unexpected disconnect */
 			curSC->result = DID_NO_CONNECT << 16;
 		} else {	/* Command complete, return status and message */
-			curSC->result = (curSC->SCp.Status & 0xff)
-			    | ((curSC->SCp.Message & 0xff) << 8) | (DID_OK << 16);
+			set_scsi_result(curSC, 0, DID_OK, 0,
+					(curSC->SCp.Status & 0xff) | ((curSC->SCp.Message & 0xff) << 8));
 		}
 		goto idle_out;
 	}
diff --git a/drivers/scsi/ppa.c b/drivers/scsi/ppa.c
index f22fe4939a74..ec35bdce8669 100644
--- a/drivers/scsi/ppa.c
+++ b/drivers/scsi/ppa.c
@@ -774,8 +774,7 @@  static int ppa_engine(ppa_struct *dev, struct scsi_cmnd *cmd)
 			/* Check for optional message byte */
 			if (ppa_wait(dev) == (unsigned char) 0xf0)
 				ppa_in(dev, &h, 1);
-			cmd->result =
-			    (DID_OK << 16) + (h << 8) + (l & STATUS_MASK);
+			set_scsi_result(cmd, 0, DID_OK, h, l & STATUS_MASK);
 		}
 		return 0;	/* Finished */
 		break;
diff --git a/drivers/scsi/ps3rom.c b/drivers/scsi/ps3rom.c
index 4924424d20fe..bf5407cdcbc3 100644
--- a/drivers/scsi/ps3rom.c
+++ b/drivers/scsi/ps3rom.c
@@ -322,7 +322,8 @@  static irqreturn_t ps3rom_interrupt(int irq, void *data)
 		/* SCSI spec says request sense should never get error */
 		dev_err(&dev->sbd.core, "%s:%u: end error without autosense\n",
 			__func__, __LINE__);
-		cmd->result = DID_ERROR << 16 | SAM_STAT_CHECK_CONDITION;
+		set_scsi_result(cmd, 0, DID_ERROR, 0,
+				SAM_STAT_CHECK_CONDITION);
 		goto done;
 	}
 
diff --git a/drivers/scsi/qedf/qedf_io.c b/drivers/scsi/qedf/qedf_io.c
index 50a50c4249d0..f1a81ee4a5c6 100644
--- a/drivers/scsi/qedf/qedf_io.c
+++ b/drivers/scsi/qedf/qedf_io.c
@@ -1138,16 +1138,19 @@  void qedf_scsi_completion(struct qedf_ctx *qedf, struct fcoe_cqe *cqe,
 		    cqe->cqe_info.rsp_info.fw_residual);
 
 		if (io_req->cdb_status == 0)
-			sc_cmd->result = (DID_ERROR << 16) | io_req->cdb_status;
+			set_scsi_result(sc_cmd, 0, DID_ERROR, 0,
+					io_req->cdb_status);
 		else
-			sc_cmd->result = (DID_OK << 16) | io_req->cdb_status;
+			set_scsi_result(sc_cmd, 0, DID_OK, 0,
+					io_req->cdb_status);
 
 		/* Abort the command since we did not get all the data */
 		init_completion(&io_req->abts_done);
 		rval = qedf_initiate_abts(io_req, true);
 		if (rval) {
 			QEDF_ERR(&(qedf->dbg_ctx), "Failed to queue ABTS.\n");
-			sc_cmd->result = (DID_ERROR << 16) | io_req->cdb_status;
+			set_scsi_result(sc_cmd, 0, DID_ERROR, 0,
+					io_req->cdb_status);
 		}
 
 		/*
@@ -1175,7 +1178,8 @@  void qedf_scsi_completion(struct qedf_ctx *qedf, struct fcoe_cqe *cqe,
 			    sc_cmd->cmnd[4], sc_cmd->cmnd[5],
 			    io_req->cdb_status, io_req->fcp_resid,
 			    refcount);
-			sc_cmd->result = (DID_OK << 16) | io_req->cdb_status;
+			set_scsi_result(sc_cmd, 0, DID_OK, 0,
+					io_req->cdb_status);
 
 			if (io_req->cdb_status == SAM_STAT_TASK_SET_FULL ||
 			    io_req->cdb_status == SAM_STAT_BUSY) {
diff --git a/drivers/scsi/qla4xxx/ql4_isr.c b/drivers/scsi/qla4xxx/ql4_isr.c
index d2cd33d8d67f..d0f61ddd230c 100644
--- a/drivers/scsi/qla4xxx/ql4_isr.c
+++ b/drivers/scsi/qla4xxx/ql4_isr.c
@@ -181,7 +181,7 @@  static void qla4xxx_status_entry(struct scsi_qla_host *ha,
 			}
 		}
 
-		cmd->result = DID_OK << 16 | scsi_status;
+		set_scsi_result(cmd, 0, DID_OK, 0, scsi_status);
 
 		if (scsi_status != SCSI_CHECK_CONDITION)
 			break;
@@ -299,11 +299,11 @@  static void qla4xxx_status_entry(struct scsi_qla_host *ha,
 					  residual,
 					  scsi_bufflen(cmd)));
 
-			cmd->result = DID_ERROR << 16 | scsi_status;
+			set_scsi_result(cmd, 0, DID_ERROR, 0, scsi_status);
 			goto check_scsi_status;
 		}
 
-		cmd->result = DID_OK << 16 | scsi_status;
+		set_scsi_result(cmd, 0, DID_OK, 0, scsi_status);
 
 check_scsi_status:
 		if (scsi_status == SAM_STAT_CHECK_CONDITION)
@@ -332,7 +332,7 @@  static void qla4xxx_status_entry(struct scsi_qla_host *ha,
 		/*
 		 * SCSI Mid-Layer handles device queue full
 		 */
-		cmd->result = DID_OK << 16 | sts_entry->scsiStatus;
+		set_scsi_result(cmd, 0, DID_OK, 0, sts_entry->scsiStatus);
 		DEBUG2(printk("scsi%ld:%d:%llu: %s: QUEUE FULL detected "
 			      "compl=%02x, scsi=%02x, state=%02x, iFlags=%02x,"
 			      " iResp=%02x\n", ha->host_no, cmd->device->id,
diff --git a/drivers/scsi/snic/snic_scsi.c b/drivers/scsi/snic/snic_scsi.c
index d8a376b7882d..2194ac6f9ccb 100644
--- a/drivers/scsi/snic/snic_scsi.c
+++ b/drivers/scsi/snic/snic_scsi.c
@@ -476,7 +476,7 @@  snic_process_io_failed_state(struct snic *snic,
 		      snic_io_status_to_str(cmpl_stat), CMD_FLAGS(sc));
 
 	/* Set sc->result */
-	sc->result = (res << 16) | icmnd_cmpl->scsi_status;
+	set_scsi_result(sc, 0, res, 0, icmnd_cmpl->scsi_status);
 } /* end of snic_process_io_failed_state */
 
 /*
@@ -509,7 +509,7 @@  snic_process_icmnd_cmpl_status(struct snic *snic,
 	CMD_STATE(sc) = SNIC_IOREQ_COMPLETE;
 
 	if (likely(cmpl_stat == SNIC_STAT_IO_SUCCESS)) {
-		sc->result = (DID_OK << 16) | scsi_stat;
+		set_scsi_result(sc, 0, DID_OK, 0, scsi_stat);
 
 		xfer_len = scsi_bufflen(sc);
 
diff --git a/drivers/scsi/stex.c b/drivers/scsi/stex.c
index 9b20643ab49d..a1d07b03bf0e 100644
--- a/drivers/scsi/stex.c
+++ b/drivers/scsi/stex.c
@@ -403,7 +403,7 @@  static struct status_msg *stex_get_status(struct st_hba *hba)
 static void stex_invalid_field(struct scsi_cmnd *cmd,
 			       void (*done)(struct scsi_cmnd *))
 {
-	cmd->result = (DRIVER_SENSE << 24) | SAM_STAT_CHECK_CONDITION;
+	set_scsi_result(cmd, DRIVER_SENSE, 0, 0, SAM_STAT_CHECK_CONDITION);
 
 	/* "Invalid field in cdb" */
 	scsi_build_sense_buffer(0, cmd->sense_buffer, ILLEGAL_REQUEST, 0x24,
@@ -630,7 +630,7 @@  stex_queuecommand_lck(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
 		if (page == 0x8 || page == 0x3f) {
 			scsi_sg_copy_from_buffer(cmd, ms10_caching_page,
 						 sizeof(ms10_caching_page));
-			cmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
+			set_scsi_result(cmd, 0, DID_OK, COMMAND_COMPLETE, 0);
 			done(cmd);
 		} else
 			stex_invalid_field(cmd, done);
@@ -649,7 +649,7 @@  stex_queuecommand_lck(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
 		break;
 	case TEST_UNIT_READY:
 		if (id == host->max_id - 1) {
-			cmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
+			set_scsi_result(cmd, 0, DID_OK, COMMAND_COMPLETE, 0);
 			done(cmd);
 			return 0;
 		}
@@ -666,7 +666,7 @@  stex_queuecommand_lck(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
 			(cmd->cmnd[1] & INQUIRY_EVPD) == 0) {
 			scsi_sg_copy_from_buffer(cmd, (void *)console_inq_page,
 						 sizeof(console_inq_page));
-			cmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8;
+			set_scsi_result(cmd, 0, DID_OK, COMMAND_COMPLETE, 0);
 			done(cmd);
 		} else
 			stex_invalid_field(cmd, done);
@@ -684,9 +684,12 @@  stex_queuecommand_lck(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
 			ver.console_id = host->max_id - 1;
 			ver.host_no = hba->host->host_no;
 			cp_len = scsi_sg_copy_from_buffer(cmd, &ver, cp_len);
-			cmd->result = sizeof(ver) == cp_len ?
-				DID_OK << 16 | COMMAND_COMPLETE << 8 :
-				DID_ERROR << 16 | COMMAND_COMPLETE << 8;
+			if (cp_len == sizeof(ver))
+				set_scsi_result(cmd, 0, DID_OK,
+						COMMAND_COMPLETE, 0);
+			else
+				set_scsi_result(cmd, 0, DID_ERROR,
+						COMMAND_COMPLETE, 0);
 			done(cmd);
 			return 0;
 		}
diff --git a/drivers/scsi/sym53c8xx_2/sym_glue.c b/drivers/scsi/sym53c8xx_2/sym_glue.c
index 7320d5fe4cbc..519fcc92440f 100644
--- a/drivers/scsi/sym53c8xx_2/sym_glue.c
+++ b/drivers/scsi/sym53c8xx_2/sym_glue.c
@@ -252,7 +252,7 @@  void sym_set_cam_result_error(struct sym_hcb *np, struct sym_ccb *cp, int resid)
 		cam_status = sym_xerr_cam_status(DID_ERROR, cp->xerr_status);
 	}
 	scsi_set_resid(cmd, resid);
-	cmd->result = (drv_status << 24) + (cam_status << 16) + scsi_status;
+	set_scsi_result(cmd, drv_status, cam_status, 0, scsi_status);
 }
 
 static int sym_scatter(struct sym_hcb *np, struct sym_ccb *cp, struct scsi_cmnd *cmd)
diff --git a/drivers/scsi/sym53c8xx_2/sym_glue.h b/drivers/scsi/sym53c8xx_2/sym_glue.h
index 805369521df8..de1250c8754d 100644
--- a/drivers/scsi/sym53c8xx_2/sym_glue.h
+++ b/drivers/scsi/sym53c8xx_2/sym_glue.h
@@ -256,7 +256,7 @@  sym_get_cam_status(struct scsi_cmnd *cmd)
 static inline void sym_set_cam_result_ok(struct sym_ccb *cp, struct scsi_cmnd *cmd, int resid)
 {
 	scsi_set_resid(cmd, resid);
-	cmd->result = (((DID_OK) << 16) + ((cp->ssss_status) & 0x7f));
+	set_scsi_result(cmd, 0, DID_OK, 0, cp->ssss_status & 0x7f);
 }
 void sym_set_cam_result_error(struct sym_hcb *np, struct sym_ccb *cp, int resid);
 
diff --git a/drivers/scsi/vmw_pvscsi.c b/drivers/scsi/vmw_pvscsi.c
index c374e3b5c678..fb049d8dcd34 100644
--- a/drivers/scsi/vmw_pvscsi.c
+++ b/drivers/scsi/vmw_pvscsi.c
@@ -561,7 +561,7 @@  static void pvscsi_complete_request(struct pvscsi_adapter *adapter,
 	    (btstat == BTSTAT_SUCCESS ||
 	     btstat == BTSTAT_LINKED_COMMAND_COMPLETED ||
 	     btstat == BTSTAT_LINKED_COMMAND_COMPLETED_WITH_FLAG)) {
-		cmd->result = (DID_OK << 16) | sdstat;
+		set_scsi_result(cmd, 0, DID_OK, 0, sdstat);
 		if (sdstat == SAM_STAT_CHECK_CONDITION && cmd->sense_buffer)
 			cmd->result |= (DRIVER_SENSE << 24);
 	} else
diff --git a/drivers/scsi/wd33c93.c b/drivers/scsi/wd33c93.c
index 74be04f2357c..e65f8b0d6339 100644
--- a/drivers/scsi/wd33c93.c
+++ b/drivers/scsi/wd33c93.c
@@ -1186,9 +1186,8 @@  wd33c93_intr(struct Scsi_Host *instance)
 				cmd->SCp.Status = lun;
 			if (cmd->cmnd[0] == REQUEST_SENSE
 			    && cmd->SCp.Status != GOOD)
-				cmd->result =
-				    (cmd->
-				     result & 0x00ffff) | (DID_ERROR << 16);
+				set_scsi_result(cmd, 0, DID_ERROR, 0,
+						(cmd->result & 0x00ffff));
 			else
 				cmd->result =
 				    cmd->SCp.Status | (cmd->SCp.Message << 8);
@@ -1272,10 +1271,11 @@  wd33c93_intr(struct Scsi_Host *instance)
 		hostdata->busy[cmd->device->id] &= ~(1 << (cmd->device->lun & 0xff));
 		hostdata->state = S_UNCONNECTED;
 		if (cmd->cmnd[0] == REQUEST_SENSE && cmd->SCp.Status != GOOD)
-			cmd->result =
-			    (cmd->result & 0x00ffff) | (DID_ERROR << 16);
+			set_scsi_result(cmd, 0, DID_ERROR, 0,
+					(cmd->result & 0x00ffff));
 		else
-			cmd->result = cmd->SCp.Status | (cmd->SCp.Message << 8);
+			set_scsi_result(cmd,0, 0, cmd->SCp.Message,
+					cmd->SCp.Status);
 		cmd->scsi_done(cmd);
 
 /* We are no longer connected to a target - check to see if
@@ -1306,9 +1306,8 @@  wd33c93_intr(struct Scsi_Host *instance)
 			DB(DB_INTR, printk(":%d", cmd->SCp.Status))
 			    if (cmd->cmnd[0] == REQUEST_SENSE
 				&& cmd->SCp.Status != GOOD)
-				cmd->result =
-				    (cmd->
-				     result & 0x00ffff) | (DID_ERROR << 16);
+				set_scsi_result(cmd, 0, DID_ERROR, 0,
+						(cmd->result & 0x00ffff));
 			else
 				cmd->result =
 				    cmd->SCp.Status | (cmd->SCp.Message << 8);
diff --git a/drivers/usb/storage/cypress_atacb.c b/drivers/usb/storage/cypress_atacb.c
index 4825902377eb..4dfaa0e0d3eb 100644
--- a/drivers/usb/storage/cypress_atacb.c
+++ b/drivers/usb/storage/cypress_atacb.c
@@ -220,11 +220,12 @@  static void cypress_atacb_passthrough(struct scsi_cmnd *srb, struct us_data *us)
 		desc[12] = regs[6];  /* device */
 		desc[13] = regs[7];  /* command */
 
-		srb->result = (DRIVER_SENSE << 24) | SAM_STAT_CHECK_CONDITION;
+		set_scsi_result(srb, DRIVER_SENSE, 0, 0,
+				SAM_STAT_CHECK_CONDITION);
 	}
 	goto end;
 invalid_fld:
-	srb->result = (DRIVER_SENSE << 24) | SAM_STAT_CHECK_CONDITION;
+	set_scsi_result(srb, DRIVER_SENSE, 0, 0, SAM_STAT_CHECK_CONDITION);
 
 	memcpy(srb->sense_buffer,
 			usb_stor_sense_invalidCDB,
diff --git a/include/scsi/scsi_cmnd.h b/include/scsi/scsi_cmnd.h
index 45d20d4a8f72..64342100ba4a 100644
--- a/include/scsi/scsi_cmnd.h
+++ b/include/scsi/scsi_cmnd.h
@@ -355,6 +355,14 @@  static inline void set_driver_byte(struct scsi_cmnd *cmd,
 	cmd->result = (cmd->result & 0x00ffffff) | (status << 24);
 }
 
+static inline void set_scsi_result(struct scsi_cmnd *cmd,
+				   enum scsi_driver_byte db,
+				   enum scsi_host_byte hb,
+				   enum scsi_msg_byte mb, char status)
+{
+	cmd->result = db << 24 | hb << 16 | mb << 8 | status;
+}
+
 static inline unsigned scsi_transfer_length(struct scsi_cmnd *scmd)
 {
 	unsigned int xfer_len = scsi_out(scmd)->length;