Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

scsi: core: Introduce scsi_status_is_check_condition()

Add a helper function scsi_status_is_check_condition() to encapsulate the
frequent checks for SAM_STAT_CHECK_CONDITION.

Link: https://lore.kernel.org/r/20210427083046.31620-9-hare@suse.de
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Hannes Reinecke <hare@suse.de>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>

authored by

Hannes Reinecke and committed by
Martin K. Petersen
d0672a03 f2b1e9c6

+20 -5
+1 -1
drivers/scsi/ibmvscsi/ibmvscsi.c
··· 1005 1005 1006 1006 if (cmnd) { 1007 1007 cmnd->result |= rsp->status; 1008 - if (((cmnd->result >> 1) & 0x1f) == CHECK_CONDITION) 1008 + if (scsi_status_is_check_condition(cmnd->result)) 1009 1009 memcpy(cmnd->sense_buffer, 1010 1010 rsp->data, 1011 1011 be32_to_cpu(rsp->sense_data_len));
+1 -1
drivers/scsi/scsi.c
··· 144 144 (level > 1)) { 145 145 scsi_print_result(cmd, "Done", disposition); 146 146 scsi_print_command(cmd); 147 - if (status_byte(cmd->result) == CHECK_CONDITION) 147 + if (scsi_status_is_check_condition(cmd->result)) 148 148 scsi_print_sense(cmd); 149 149 if (level > 3) 150 150 scmd_printk(KERN_INFO, cmd,
+2 -2
drivers/scsi/scsi_error.c
··· 1258 1258 current->comm)); 1259 1259 break; 1260 1260 } 1261 - if (status_byte(scmd->result) != CHECK_CONDITION) 1261 + if (!scsi_status_is_check_condition(scmd->result)) 1262 1262 /* 1263 1263 * don't request sense if there's no check condition 1264 1264 * status because the error we're processing isn't one ··· 1774 1774 return (scmd->request->cmd_flags & REQ_FAILFAST_DRIVER); 1775 1775 } 1776 1776 1777 - if (status_byte(scmd->result) != CHECK_CONDITION) 1777 + if (!scsi_status_is_check_condition(scmd->result)) 1778 1778 return 0; 1779 1779 1780 1780 check_type:
+1 -1
drivers/scsi/scsi_lib.c
··· 2164 2164 goto retry; 2165 2165 } 2166 2166 } 2167 - if ((status_byte(result) == CHECK_CONDITION) && 2167 + if (scsi_status_is_check_condition(result) && 2168 2168 sshdr->sense_key == UNIT_ATTENTION && 2169 2169 retry_count) { 2170 2170 retry_count--;
+15
include/scsi/scsi.h
··· 62 62 return (lun & 0xff00) == SCSI_W_LUN_BASE; 63 63 } 64 64 65 + /** 66 + * scsi_status_is_check_condition - check the status return. 67 + * 68 + * @status: the status passed up from the driver (including host and 69 + * driver components) 70 + * 71 + * This returns true if the status code is SAM_STAT_CHECK_CONDITION. 72 + */ 73 + static inline int scsi_status_is_check_condition(int status) 74 + { 75 + if (status < 0) 76 + return false; 77 + status &= 0xfe; 78 + return status == SAM_STAT_CHECK_CONDITION; 79 + } 65 80 66 81 /* 67 82 * MESSAGE CODES