From: Stefan Richter <stefanr@s5r6.in-berlin.de>
To: Ankit Jain <jankit@suse.de>
Cc: Andy Grover <agrover@redhat.com>,
linux-scsi@vger.kernel.org, Eddie Wai <eddie.wai@broadcom.com>
Subject: Re: [PATCH] iscsi: Use struct scsi_lun in iscsi structs instead of u8[8]
Date: Fri, 17 Jun 2011 14:38:07 +0200 [thread overview]
Message-ID: <20110617143807.485b7e35@stein> (raw)
In-Reply-To: <4DFAECB2.2010107@suse.de>
On Jun 17 Ankit Jain wrote:
> On 06/17/2011 04:27 AM, Andy Grover wrote:
> > --- a/drivers/scsi/bnx2i/bnx2i_hwi.c
> > +++ b/drivers/scsi/bnx2i/bnx2i_hwi.c
> > @@ -430,7 +430,7 @@ int bnx2i_send_iscsi_tmf(struct bnx2i_conn *bnx2i_conn,
> > default:
> > tmfabort_wqe->ref_itt = RESERVED_ITT;
> > }
> > - memcpy(scsi_lun, tmfabort_hdr->lun, sizeof(struct scsi_lun));
> > + memcpy(scsi_lun, &tmfabort_hdr->lun, sizeof(struct scsi_lun));
> > tmfabort_wqe->lun[0] = be32_to_cpu(scsi_lun[0]);
> > tmfabort_wqe->lun[1] = be32_to_cpu(scsi_lun[1]);
> >
> > @@ -547,7 +547,7 @@ int bnx2i_send_iscsi_nopout(struct bnx2i_conn *bnx2i_conn,
> >
> > nopout_wqe->op_code = nopout_hdr->opcode;
> > nopout_wqe->op_attr = ISCSI_FLAG_CMD_FINAL;
> > - memcpy(nopout_wqe->lun, nopout_hdr->lun, 8);
> > + memcpy(nopout_wqe->lun, &nopout_hdr->lun, 8);
>
> Should you be using "sizeof (..)" here (and similar instances), rather
> than 8? It is being done that way in other instances and it would be
> better practice, IMHO.
sizeof or not sizeof is the least of the coding style issues in drivers/scsi/bnx2i/.
Exhibit one from 57xx_iscsi_hsi.h:
struct bnx2i_nop_out_request {
#if defined(__BIG_ENDIAN)
[...]
#elif defined(__LITTLE_ENDIAN)
[...]
#endif
This kind of coding leads to obfuscated CPU accessors to DMA data/ on the wire data.
If a structure for on-the-wire contains a bitfield (e.g. a 32 bits wide bitfield),
just use __be... or __le... data types (e.g. __be32 or __le32) as required by the
device or protocol. When the CPU needs to read and write certain bits and bytes in
the word, use the usual cpu_to_... and ..._to_cpu accessors on the entire bitfield,
plus CPU-side shifts and masks.
The end result should be obvious to the reader of the code, and intrinsically clean
in a CF="-D__CHECK_ENDIAN__" run of make.
Did nobody ask about that when this code was staged for merge into 2.6.31?
Hard to tell at a first glance whether the introduction of struct scsi_lun into the
mix makes this code better or worse.
--
Stefan Richter
-=====-==-== -==- =---=
http://arcgraph.de/sr/
next prev parent reply other threads:[~2011-06-17 12:38 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-06-16 22:57 [PATCH] iscsi: Use struct scsi_lun in iscsi structs instead of u8[8] Andy Grover
2011-06-17 5:57 ` Ankit Jain
2011-06-17 12:38 ` Stefan Richter [this message]
2011-06-17 16:31 ` Andy Grover
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=20110617143807.485b7e35@stein \
--to=stefanr@s5r6.in-berlin.de \
--cc=agrover@redhat.com \
--cc=eddie.wai@broadcom.com \
--cc=jankit@suse.de \
--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