On Tue, 2017-10-10 at 17:29 +0200, Johannes Thumshirn wrote:
> Call set_host_byte() instead of open-coding it.
> 
> Converted using this simple Coccinelle spatch
> 
> <SmPL>
> @@
> local idexpression struct scsi_cmnd *c;
> expression E1;
> @@
> 
> - c->result = E1 << 16;
> + set_host_byte(c, E1);
> </SmPL>

This is useful but I think we should take this a step further. How
about the following approach:
- Introduce four enumeration types - one for the msg byte codes, one
  for the host byte codes, one for the driver byte codes and one for
  SCSI sense codes.
- Update the signatures of functions that store or extract these four
  bytes.
- Change the data type of scsi_cmnd.result into something that makes
  regular assignments trigger a compiler error.

I'm proposing this because there are several drivers that do not assign the
SCSI host byte correctly:
$ git grep -nH '>result = DID_' | grep -v '<< *16' | grep -v ': \*'
drivers/scsi/ips.c:953:                 scsi_cmd->result = DID_ERROR;
drivers/scsi/ips.c:2657:                SC->result = DID_OK;
drivers/scsi/libiscsi.c:1731:           sc->result = DID_REQUEUE;
drivers/scsi/qla2xxx/qla_bsg.c:152:                     bsg_reply->result = 
DID_OK;
drivers/scsi/qla2xxx/qla_bsg.c:167:                             
bsg_reply->result = DID_OK;
drivers/scsi/qla2xxx/qla_bsg.c:184:             bsg_reply->result = DID_OK;
drivers/scsi/qla2xxx/qla_bsg.c:236:             bsg_reply->result = DID_OK;
drivers/scsi/qla2xxx/qla_bsg.c:976:             bsg_reply->result = DID_OK;
drivers/scsi/qla2xxx/qla_bsg.c:1078:            bsg_reply->result = DID_OK;
drivers/scsi/qla2xxx/qla_bsg.c:1261:            bsg_reply->result = DID_OK;
drivers/scsi/qla2xxx/qla_bsg.c:1375:            bsg_reply->result = DID_OK;
drivers/scsi/qla2xxx/qla_bsg.c:1480:    bsg_reply->result = DID_OK;
drivers/scsi/qla2xxx/qla_bsg.c:1516:    bsg_reply->result = DID_OK;
drivers/scsi/qlogicpti.c:1049:  Cmnd->result = DID_BUS_BUSY;
drivers/scsi/stex.c:615:                cmd->result = DID_NO_CONNECT;

Bart.

Reply via email to