From: Joe Perches <joe@perches.com>
To: Colin King <colin.king@canonical.com>,
Hannes Reinecke <hare@suse.com>,
"James E . J . Bottomley" <jejb@linux.vnet.ibm.com>,
"Martin K . Petersen" <martin.petersen@oracle.com>,
linux-scsi@vger.kernel.org
Cc: kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] scsi: aic7xxx: Fix unintended sign extension issue
Date: Thu, 25 Oct 2018 08:32:16 -0700 [thread overview]
Message-ID: <ce7de2909b7c9958ac63c4386e889509926b651b.camel@perches.com> (raw)
In-Reply-To: <20181025151334.15622-1-colin.king@canonical.com>
On Thu, 2018-10-25 at 16:13 +0100, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> In the expression "ahc_inb(ahc, port+3) << 24", the initial value is a
> u8, but is promoted to a signed int, then sign-extended to uint64_t. If
> the value read from the port has the upper bit set then the sign
> extension will set all the upper bits of the expression which is probably
> not what was intended. Cast to uint64_t to avoid the sign extension.
[]
> diff --git a/drivers/scsi/aic7xxx/aic79xx_core.c b/drivers/scsi/aic7xxx/aic79xx_core.c
[]
> @@ -622,7 +622,7 @@ ahd_inq(struct ahd_softc *ahd, u_int port)
> return ((ahd_inb(ahd, port))
> | (ahd_inb(ahd, port+1) << 8)
> | (ahd_inb(ahd, port+2) << 16)
> - | (ahd_inb(ahd, port+3) << 24)
> + | (((uint64_t)ahd_inb(ahd, port+3)) << 24)
> | (((uint64_t)ahd_inb(ahd, port+4)) << 32)
> | (((uint64_t)ahd_inb(ahd, port+5)) << 40)
> | (((uint64_t)ahd_inb(ahd, port+6)) << 48)
Perhaps a different method using two calls to ahd_inl
is clearer and possibly faster like:
uint64_t
ahd_inq(struct ahd_softc *ahd, u_int port)
{
return ahd_inl(port) | ((uint64_t)ahd_inl(port + 4) << 32);
}
> diff --git a/drivers/scsi/aic7xxx/aic7xxx_core.c b/drivers/scsi/aic7xxx/aic7xxx_core.c
[]
> @@ -493,7 +493,7 @@ ahc_inq(struct ahc_softc *ahc, u_int port)
> return ((ahc_inb(ahc, port))
> | (ahc_inb(ahc, port+1) << 8)
> | (ahc_inb(ahc, port+2) << 16)
> - | (ahc_inb(ahc, port+3) << 24)
> + | (((uint64_t)ahc_inb(ahc, port+3)) << 24)
> | (((uint64_t)ahc_inb(ahc, port+4)) << 32)
> | (((uint64_t)ahc_inb(ahc, port+5)) << 40)
> | (((uint64_t)ahc_inb(ahc, port+6)) << 48)
here too
next prev parent reply other threads:[~2018-10-25 15:32 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-10-25 15:13 Colin King
2018-10-25 15:32 ` Joe Perches [this message]
2018-10-25 15:32 ` James Bottomley
2018-10-25 15:54 ` David Laight
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=ce7de2909b7c9958ac63c4386e889509926b651b.camel@perches.com \
--to=joe@perches.com \
--cc=colin.king@canonical.com \
--cc=hare@suse.com \
--cc=jejb@linux.vnet.ibm.com \
--cc=kernel-janitors@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®