linux-scsi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Arnd Bergmann <arnd@arndb.de>
To: Samuel Holland <samuel@sholland.org>
Cc: Adam Radford <aradford@gmail.com>,
	"James E.J. Bottomley" <jejb@linux.ibm.com>,
	"Martin K. Petersen" <martin.petersen@oracle.com>,
	linux-scsi <linux-scsi@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] scsi: 3w-9xxx: Fix endianness issues found by sparse
Date: Mon, 27 Jul 2020 21:18:17 +0200	[thread overview]
Message-ID: <CAK8P3a3yj=ySNCn7YtEXxWiRK0FtG+5ftkV+vb3s82yRi7cdLw@mail.gmail.com> (raw)
In-Reply-To: <20200726191428.26767-1-samuel@sholland.org>

On Sun, Jul 26, 2020 at 9:15 PM Samuel Holland <samuel@sholland.org> wrote:
>
> The main issue observed was at the call to scsi_set_resid, where the
> byteswapped parameter would eventually trigger the alignment check at
> drivers/scsi/sd.c:2009. At that point, the kernel would continuously
> complain about an "Unaligned partial completion", and no further I/O
> could occur.
>
> This gets the controller working on big endian powerpc64.
>
> Signed-off-by: Samuel Holland <samuel@sholland.org>
> ---
>  drivers/scsi/3w-9xxx.c | 35 +++++++++++++++++------------------
>  drivers/scsi/3w-9xxx.h |  6 +++++-
>  2 files changed, 22 insertions(+), 19 deletions(-)
>
> diff --git a/drivers/scsi/3w-9xxx.c b/drivers/scsi/3w-9xxx.c
> index 3337b1e80412..95e25fda1f90 100644
> --- a/drivers/scsi/3w-9xxx.c
> +++ b/drivers/scsi/3w-9xxx.c
> @@ -303,10 +303,10 @@ static int twa_aen_drain_queue(TW_Device_Extension *tw_dev, int no_check_reset)
>
>         /* Initialize sglist */
>         memset(&sglist, 0, sizeof(TW_SG_Entry));
> -       sglist[0].length = TW_SECTOR_SIZE;
> -       sglist[0].address = tw_dev->generic_buffer_phys[request_id];
> +       sglist[0].length = cpu_to_le32(TW_SECTOR_SIZE);
> +       sglist[0].address = TW_CPU_TO_SGL(tw_dev->generic_buffer_phys[request_id]);

This looks like it would add a sparse warning, not fix one, unless you also
change the types of the target structure.

> @@ -501,7 +501,7 @@ static void twa_aen_sync_time(TW_Device_Extension *tw_dev, int request_id)
>             Sunday 12:00AM */
>         local_time = (ktime_get_real_seconds() - (sys_tz.tz_minuteswest * 60));
>         div_u64_rem(local_time - (3 * 86400), 604800, &schedulertime);
> -       schedulertime = cpu_to_le32(schedulertime % 604800);
> +       cpu_to_le32p(&schedulertime);
>
>         memcpy(param->data, &schedulertime, sizeof(u32));

You dropped the '%' operation, and the result of the byteswap?

> @@ -1004,7 +1004,7 @@ static int twa_fill_sense(TW_Device_Extension *tw_dev, int request_id, int copy_
>                                full_command_packet->header.status_block.error,
>                                error_str[0] == '\0' ?
>                                twa_string_lookup(twa_error_table,
> -                                                full_command_packet->header.status_block.error) : error_str,
> +                                                le16_to_cpu(full_command_packet->header.status_block.error)) : error_str,
>                                full_command_packet->header.err_specific_desc);
>                 else

This looks correct, but the error value has already been copied into the local
'error' variable, which you could use for simplification. As 'status_block' is
defined as a native_endian structure, this also introduced a sparse warning.

> @@ -1012,7 +1012,7 @@ static int twa_fill_sense(TW_Device_Extension *tw_dev, int request_id, int copy_
>                                full_command_packet->header.status_block.error,
>                                error_str[0] == '\0' ?
>                                twa_string_lookup(twa_error_table,
> -                                                full_command_packet->header.status_block.error) : error_str,
> +                                                le16_to_cpu(full_command_packet->header.status_block.error)) : error_str,

Same here

       Arnd

  reply	other threads:[~2020-07-27 19:18 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-26 19:14 [PATCH] scsi: 3w-9xxx: Fix endianness issues found by sparse Samuel Holland
2020-07-27 19:18 ` Arnd Bergmann [this message]
2020-07-29  4:50   ` Samuel Holland

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='CAK8P3a3yj=ySNCn7YtEXxWiRK0FtG+5ftkV+vb3s82yRi7cdLw@mail.gmail.com' \
    --to=arnd@arndb.de \
    --cc=aradford@gmail.com \
    --cc=jejb@linux.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    --cc=samuel@sholland.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;
as well as URLs for NNTP newsgroup(s).