Skip to content
Permalink
Browse files
Introduce more members in the scsi_status union
Add the status, message, host and driver members. Later patches will
convert assignments to the 'combined' member into assignments of one of
the new members. That will allow the compiler to verify the type of
constants assigned to the status, message, host and driver bytes.

Cc: Christoph Hellwig <hch@lst.de>
Cc: Ming Lei <ming.lei@redhat.com>
Cc: Hannes Reinecke <hare@suse.com>
Cc: John Garry <john.garry@huawei.com>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
  • Loading branch information
bvanassche committed Apr 14, 2021
1 parent fd78f07 commit f135308b20ad66b766bd6850a6fc591790a4df09
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
@@ -763,11 +763,19 @@ MODULE_LICENSE("GPL");
module_param(scsi_logging_level, int, S_IRUGO|S_IWUSR);
MODULE_PARM_DESC(scsi_logging_level, "a bit mask of logging levels");

#define TEST_STATUS ((union scsi_status) \
{.b = {.driver = 1, .host = 2, .msg = 3, .status = 8}})

static int __init init_scsi(void)
{
int error;

BUILD_BUG_ON(sizeof(union scsi_status) != 4);
BUILD_BUG_ON(TEST_STATUS.combined != 0x01020308);
BUILD_BUG_ON(driver_byte(TEST_STATUS) != 1);
BUILD_BUG_ON(host_byte(TEST_STATUS) != 2);
BUILD_BUG_ON(msg_byte(TEST_STATUS) != 3);
BUILD_BUG_ON(status_byte(TEST_STATUS) != 4);

error = scsi_init_procfs();
if (error)
@@ -316,22 +316,22 @@ static inline struct scsi_data_buffer *scsi_prot(struct scsi_cmnd *cmd)

static inline void set_status_byte(struct scsi_cmnd *cmd, char status)
{
cmd->result.combined = (cmd->result.combined & 0xffffff00) | status;
cmd->result.b.status = status;
}

static inline void set_msg_byte(struct scsi_cmnd *cmd, char status)
{
cmd->result.combined = (cmd->result.combined & 0xffff00ff) | (status << 8);
cmd->result.b.msg = status;
}

static inline void set_host_byte(struct scsi_cmnd *cmd, char status)
{
cmd->result.combined = (cmd->result.combined & 0xff00ffff) | (status << 16);
cmd->result.b.host = status;
}

static inline void set_driver_byte(struct scsi_cmnd *cmd, char status)
{
cmd->result.combined = (cmd->result.combined & 0x00ffffff) | (status << 24);
cmd->result.b.driver = status;
}

static inline unsigned scsi_transfer_length(struct scsi_cmnd *scmd)
@@ -94,9 +94,23 @@ enum driver_status {
* - A negative Unix error code.
* - In the IDE code, a positive value that represents an error code, an
* error counter or a bitfield.
* @b: SCSI status code.
*/
union scsi_status {
int32_t combined;
struct {
#if defined(__s390__)
enum driver_status driver : 8;
enum host_status host : 8;
enum msg_byte msg : 8;
enum sam_status status : 8;
#else
enum sam_status status : 8;
enum msg_byte msg : 8;
enum host_status host : 8;
enum driver_status driver : 8;
#endif
} b;
};

#endif /* _SCSI_SCSI_STATUS_H */

0 comments on commit f135308

Please sign in to comment.