All of lore.kernel.org
 help / color / mirror / Atom feed
From: Christoph Hellwig <hch@infradead.org>
To: Douglas Gilbert <dougg@torque.net>
Cc: linux-scsi@vger.kernel.org
Subject: Re: [PATCH] normalize fixed and descriptor sense data
Date: Fri, 27 Aug 2004 16:18:00 +0100	[thread overview]
Message-ID: <20040827161800.A32040@infradead.org> (raw)
In-Reply-To: <412EF74A.1070106@torque.net>; from dougg@torque.net on Fri, Aug 27, 2004 at 06:56:42PM +1000


+struct scsi_sense_hd {     /* See SPC-3 section 4.5 */

maybe scsi_sense_desc insted?

+    uint8_t response_code; /* permit: 0x0, 0x70, 0x71, 0x72, 0x73 */
+    uint8_t sense_key;
+    uint8_t asc;
+    uint8_t ascq;
+    uint8_t byte4;
+    uint8_t byte5;
+    uint8_t byte6;
+    uint8_t additional_length; /* always 0 for fixed sense format */

We use u8 elsewhere in the scsi code, please stay consistant.

+static inline int scsi_sense_is_deferred(struct scsi_sense_hd * sshd)
+{
+	return (sshd && (sshd->response_code >= 0x70) && 
+		(sshd->response_code & 1)) ? 1 : 0;
+}

I don't think we need the NULL check for sshd here, do we?

+/**
+ *	scsi_normalize_sense - normalize main elements from either fixed
+ *		or descriptor sense data format into a common format.
+ *	@sense_buffer:	byte array containing sense data returned by
+ *			device
+ *	@sb_len:	number of valid bytes in sense_buffer
+ *	@sshd:		pointer to instance of structure that common
+ *			elements are written to. Ignored if NULL.
+ *
+ *	The "main elements" from sense data are: response_code, sense_key,
+ *	asc, ascq and additional_length (only for descriptor format).
+ *	Typically this function can be called after a device has
+ *	responded to a SCSI command with the CHECK_CONDITION status.
+ *
+ *	Returns 1 if valid sense data information found, else 0;
+ **/
+int scsi_normalize_sense(const uint8_t * sense_buffer, int sb_len,
+                         struct scsi_sense_hd * sshd)
+{
+	if (sshd)
+		memset(sshd, 0, sizeof(struct scsi_sense_hd));

Again, checking for a NULL sshd here doesn't make much sense.

Also I think this function should get a __ prefix and we should
add two small helpers that take a scsi_cmnd/scsi_request and use
the sense_buffer and len from it.

+	if ((NULL == sense_buffer) || (0 == sb_len) ||
+	    (0x70 != (0x70 & sense_buffer[0])))
+		return 0;
+	if (NULL == sshd)
+		return 1;

Wrong way around vs normal scsi style.  Should be more like:

	if (!sense_buffer || !sb_len || (0x70 & sense_buffer[0]) != 0x70)
		return 0;

(and the sshd check gone again)
(same issues come up below again a few times)


  reply	other threads:[~2004-08-27 15:18 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-08-27  8:56 [PATCH] normalize fixed and descriptor sense data Douglas Gilbert
2004-08-27 15:18 ` Christoph Hellwig [this message]
2004-08-27 15:45   ` Luben Tuikov
2004-08-27 15:52     ` Christoph Hellwig
2004-08-27 15:46 ` Randy.Dunlap
2004-08-28  5:05 ` Douglas Gilbert
2004-08-28 20:23   ` Christoph Hellwig
2004-08-29  0:36     ` Douglas Gilbert
2004-08-29  8:59       ` Christoph Hellwig
  -- strict thread matches above, loose matches on Subject: below --
2004-08-27 14:56 Pat LaVarre
2004-08-28  4:07 ` Douglas Gilbert
2004-08-28  6:31   ` Kai Makisara
     [not found]     ` <3CC78E D C-FAAA-11D8-85F1-00039398BB5E@ieee.org>
2004-08-30 17:30     ` Pat LaVarre
2004-08-30 19:51       ` Kai Makisara
2004-08-30 20:03         ` Pat LaVarre

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=20040827161800.A32040@infradead.org \
    --to=hch@infradead.org \
    --cc=dougg@torque.net \
    --cc=linux-scsi@vger.kernel.org \
    /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.