All of lore.kernel.org
 help / color / mirror / Atom feed
From: damien.lemoal@wdc.com
To: linux-scsi@vger.kernel.org,
	"Martin K . Petersen" <martin.petersen@oracle.com>
Cc: Bart Van Assche <Bart.VanAssche@sandisk.com>,
	Hannes Reinecke <hare@suse.de>, Christoph Hellwig <hch@lst.de>,
	Damien Le Moal <damien.lemoal@wdc.com>
Subject: [PATCH v2 4/7] scsi: Improve scsi_get_sense_info_fld
Date: Mon, 24 Apr 2017 16:51:12 +0900	[thread overview]
Message-ID: <20170424075115.30337-5-damien.lemoal@wdc.com> (raw)
In-Reply-To: <20170424075115.30337-1-damien.lemoal@wdc.com>

From: Damien Le Moal <damien.lemoal@wdc.com>

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>
---
 drivers/scsi/scsi_error.c | 38 +++++++++++++++-----------------------
 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 53e3343..d70c67c 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 a25b328..64d30d8 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 *);
 
-- 
2.9.3

  parent reply	other threads:[~2017-04-24  7:51 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-24  7:51 [PATCH v2 0/7] scsi: sd/sd_zbc cleanup and improvements damien.lemoal
2017-04-24  7:51 ` [PATCH v2 1/7] sd: Fix functions description damien.lemoal
2017-04-24 15:30   ` Christoph Hellwig
2017-04-24  7:51 ` [PATCH v2 2/7] sd: Improve sd_completed_bytes damien.lemoal
2017-04-24 15:31   ` Christoph Hellwig
2017-04-24  7:51 ` [PATCH v2 3/7] sd: Cleanup sd_done sense data handling damien.lemoal
2017-04-24 15:35   ` Christoph Hellwig
2017-04-24 23:11     ` Martin K. Petersen
2017-04-25  1:54       ` Damien Le Moal
2017-04-25 17:03         ` Martin K. Petersen
2017-04-24  7:51 ` damien.lemoal [this message]
2017-04-24 15:36   ` [PATCH v2 4/7] scsi: Improve scsi_get_sense_info_fld Christoph Hellwig
2017-04-24  7:51 ` [PATCH v2 5/7] sd_zbc: Rename sd_zbc_setup_write_cmnd damien.lemoal
2017-04-24 15:36   ` Christoph Hellwig
2017-04-24  7:51 ` [PATCH v2 6/7] sd_zbc: Remove superfluous assignments damien.lemoal
2017-04-24 15:37   ` Christoph Hellwig
2017-04-24  7:51 ` [PATCH v2 7/7] sd_zbc: Do not write lock zones for reset damien.lemoal
2017-04-24 15:38   ` Christoph Hellwig

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170424075115.30337-5-damien.lemoal@wdc.com \
    --to=damien.lemoal@wdc.com \
    --cc=Bart.VanAssche@sandisk.com \
    --cc=hare@suse.de \
    --cc=hch@lst.de \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.