public inbox for linux-scsi@vger.kernel.org
 help / color / mirror / Atom feed
From: Douglas Gilbert <dgilbert@interlog.com>
To: SCSI development list <linux-scsi@vger.kernel.org>
Subject: Re: scsi.h: please rename the status_byte() macro
Date: Thu, 16 Sep 2010 16:46:21 -0400	[thread overview]
Message-ID: <4C92821D.1000903@interlog.com> (raw)
In-Reply-To: <4C912F14.8000706@interlog.com>

On 10-09-15 04:39 PM, Douglas Gilbert wrote:
> ... to something like:
> scsi_status_byte_div2()
> or:
> scsi_broken_status_byte()

The bug in the bsg driver with its SCSI status byte
brought this to my attention. If memory serves about
10 years ago some of us tried to kill the status_byte()
macro.

But it is still there in the kernel's scsi/scsi.h
ready to trip up another generation of programmers:
#define status_byte(result) (((result) >> 1) & 0x7f)

with no explanation that it does NOT yield the SCSI
status byte but the right shifted (once) equivalent.

The correct macro (or inline function) for obtaining the
SCSI status byte from the 32 bit "result" from a LLD would
be:
#define scsi_status_byte(result) ((result) & 0xff)

[Long ago (20 years) something silly was put in bit 0
  so masking with 0xfe would work as well.]

Another thought, these macros are associated with the
mid-level or a ULD deciding whether a SCSI command has
succeeded; so scsi_cmnd.h would be a more appropriate
header.

Happily the version of scsi.h shown to the user space
(typically /usr/include/scsi/scsi.h) does not include
these defective macros. So any API breakage is limited
to the kernel.

Doug Gilbert



  reply	other threads:[~2010-09-16 20:46 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-09-15 20:39 scsi.h: please rename the status_byte() macro Douglas Gilbert
2010-09-16 20:46 ` Douglas Gilbert [this message]
2010-09-25  1:17   ` [RFC/PATCH] " Randy Dunlap

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=4C92821D.1000903@interlog.com \
    --to=dgilbert@interlog.com \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox