diff options
author | Damien Le Moal <damien.lemoal@wdc.com> | 2017-04-24 16:51:12 +0900 |
---|---|---|
committer | Martin K. Petersen <martin.petersen@oracle.com> | 2017-04-25 13:00:56 -0400 |
commit | 2908769c35fbd3de7b874b60b95ba81546e3c920 (patch) | |
tree | 9bde4e27970ce851070a4b2b3daf6bb7eaed388f | |
parent | d227ec267ff4fa91ac2db9965d5392cf825be511 (diff) |
scsi: Improve scsi_get_sense_info_fld
Use get_unaligned_be32 and get_unaligned_be64 to obtain values from the
sense buffer instead of open coding the operations. Also change the
function return value to a bool and fix the function signature
declaration to remove spaces triggering checkpatch warnings.
No functional change is introduced by this patch.
Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com>
Reviewed-by: Bart Van Assche <Bart.VanAssche@sandisk.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
-rw-r--r-- | drivers/scsi/scsi_error.c | 38 | ||||
-rw-r--r-- | include/scsi/scsi_eh.h | 4 |
2 files changed, 17 insertions, 25 deletions
diff --git a/drivers/scsi/scsi_error.c b/drivers/scsi/scsi_error.c index 53e334356f31..d70c67cf46ef 100644 --- a/drivers/scsi/scsi_error.c +++ b/drivers/scsi/scsi_error.c @@ -46,6 +46,8 @@ #include <trace/events/scsi.h> +#include <asm/unaligned.h> + static void scsi_eh_done(struct scsi_cmnd *scmd); /* @@ -2361,44 +2363,34 @@ EXPORT_SYMBOL(scsi_command_normalize_sense); * field will be placed if found. * * Return value: - * 1 if information field found, 0 if not found. + * true if information field found, false if not found. */ -int scsi_get_sense_info_fld(const u8 * sense_buffer, int sb_len, - u64 * info_out) +bool scsi_get_sense_info_fld(const u8 *sense_buffer, int sb_len, + u64 *info_out) { - int j; const u8 * ucp; - u64 ull; if (sb_len < 7) - return 0; + return false; switch (sense_buffer[0] & 0x7f) { case 0x70: case 0x71: if (sense_buffer[0] & 0x80) { - *info_out = (sense_buffer[3] << 24) + - (sense_buffer[4] << 16) + - (sense_buffer[5] << 8) + sense_buffer[6]; - return 1; - } else - return 0; + *info_out = get_unaligned_be32(&sense_buffer[3]); + return true; + } + return false; case 0x72: case 0x73: ucp = scsi_sense_desc_find(sense_buffer, sb_len, 0 /* info desc */); if (ucp && (0xa == ucp[1])) { - ull = 0; - for (j = 0; j < 8; ++j) { - if (j > 0) - ull <<= 8; - ull |= ucp[4 + j]; - } - *info_out = ull; - return 1; - } else - return 0; + *info_out = get_unaligned_be64(&ucp[4]); + return true; + } + return false; default: - return 0; + return false; } } EXPORT_SYMBOL(scsi_get_sense_info_fld); diff --git a/include/scsi/scsi_eh.h b/include/scsi/scsi_eh.h index a25b3285dd6f..64d30d80dadb 100644 --- a/include/scsi/scsi_eh.h +++ b/include/scsi/scsi_eh.h @@ -23,8 +23,8 @@ static inline bool scsi_sense_is_deferred(const struct scsi_sense_hdr *sshdr) return ((sshdr->response_code >= 0x70) && (sshdr->response_code & 1)); } -extern int scsi_get_sense_info_fld(const u8 * sense_buffer, int sb_len, - u64 * info_out); +extern bool scsi_get_sense_info_fld(const u8 *sense_buffer, int sb_len, + u64 *info_out); extern int scsi_ioctl_reset(struct scsi_device *, int __user *); |