From: James Bottomley <jejb@linux.ibm.com>
To: Dan Carpenter <dan.carpenter@oracle.com>, Walter Harms <wharms@bfs.de>
Cc: Colin King <colin.king@canonical.com>,
Jianyun Li <jyli@marvell.com>,
"Martin K . Petersen" <martin.petersen@oracle.com>,
linux-scsi@vger.kernel.org, kernel-janitors@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] scsi: mvumi: fix 32 bit shift of a 32 bit unsigned int
Date: Mon, 18 Feb 2019 15:32:05 +0000 [thread overview]
Message-ID: <1550503925.2834.3.camel@linux.ibm.com> (raw)
In-Reply-To: <20190218093710.GB17104@kadam>
On Mon, 2019-02-18 at 12:37 +0300, Dan Carpenter wrote:
> On Sat, Feb 16, 2019 at 05:27:16PM +0100, Walter Harms wrote:
> > Am 16.02.2019 15:44, schrieb Colin King:
> > > From: Colin Ian King <colin.king@canonical.com>
> > >
> > > Currently m_sg->baseaddr_h (a 32 bit unsigned int) is being
> > > shifted by a
> > > total of 32 bits; this always produces a 0 result. Fix this by
> > > casting
> > > it to a dma_addr_t (a 64 bit unsigned int) before performing the
> > > shift.
> > >
> > > Detected by CoverityScan, CID#147270 ("Operands don't affect
> > > result")
> > >
> > > Fixes: f0c568a478f0 ("[SCSI] mvumi: Add Marvell UMI driver")
> > > Signed-off-by: Colin Ian King <colin.king@canonical.com>
> > > ---
> > > drivers/scsi/mvumi.c | 2 +-
> > > 1 file changed, 1 insertion(+), 1 deletion(-)
> > >
> > > diff --git a/drivers/scsi/mvumi.c b/drivers/scsi/mvumi.c
> > > index 36f64205ecfa..d3582accfd09 100644
> > > --- a/drivers/scsi/mvumi.c
> > > +++ b/drivers/scsi/mvumi.c
> > > @@ -313,7 +313,7 @@ static void mvumi_delete_internal_cmd(struct
> > > mvumi_hba
> > > *mhba,
> > > sgd_getsz(mhba, m_sg, size);
> > >
> > > phy_addr = (dma_addr_t) m_sg->baseaddr_l
> > > |
> > > - (dma_addr_t) ((m_sg->baseaddr_h
> > > << 16) << 16);
> > > + (((dma_addr_t) m_sg->baseaddr_h
> > > << 16) << 16);
> > >
> > > dma_free_coherent(&mhba->pdev->dev,
> > > size, cmd->data_buf,
> > >
> > > phy_addr);
> >
> > i would suggest to try a version with less casts to make it more
> > readable
> > like this untested suggestion:
> >
> > phy_addr =(m_sg->baseaddr_h << 16)| m_sg->baseaddr_l;
> > phy_addr <<= 16;
> >
>
> That would be a behavior change but it also might be a bugfix? Why
> doesn't the code just do:
>
> phy_addr = ((dma_addr_t)m_sg->baseaddr_h << 32) | m_sg-
> >baseaddr_l;
>
> (Probably they broke it up into two shifts to silence a GCC warning
> that the shift was wrong because of the missing cast?)
No because dma_addr_t can be 32 bits and the warning would then always
appear on some builds. The << 16 << 16 makes sure it doesn't.
James
WARNING: multiple messages have this Message-ID (diff)
From: James Bottomley <jejb@linux.ibm.com>
To: Dan Carpenter <dan.carpenter@oracle.com>, Walter Harms <wharms@bfs.de>
Cc: Colin King <colin.king@canonical.com>,
Jianyun Li <jyli@marvell.com>,
"Martin K . Petersen" <martin.petersen@oracle.com>,
linux-scsi@vger.kernel.org, kernel-janitors@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] scsi: mvumi: fix 32 bit shift of a 32 bit unsigned int
Date: Mon, 18 Feb 2019 07:32:05 -0800 [thread overview]
Message-ID: <1550503925.2834.3.camel@linux.ibm.com> (raw)
In-Reply-To: <20190218093710.GB17104@kadam>
On Mon, 2019-02-18 at 12:37 +0300, Dan Carpenter wrote:
> On Sat, Feb 16, 2019 at 05:27:16PM +0100, Walter Harms wrote:
> > Am 16.02.2019 15:44, schrieb Colin King:
> > > From: Colin Ian King <colin.king@canonical.com>
> > >
> > > Currently m_sg->baseaddr_h (a 32 bit unsigned int) is being
> > > shifted by a
> > > total of 32 bits; this always produces a 0 result. Fix this by
> > > casting
> > > it to a dma_addr_t (a 64 bit unsigned int) before performing the
> > > shift.
> > >
> > > Detected by CoverityScan, CID#147270 ("Operands don't affect
> > > result")
> > >
> > > Fixes: f0c568a478f0 ("[SCSI] mvumi: Add Marvell UMI driver")
> > > Signed-off-by: Colin Ian King <colin.king@canonical.com>
> > > ---
> > > drivers/scsi/mvumi.c | 2 +-
> > > 1 file changed, 1 insertion(+), 1 deletion(-)
> > >
> > > diff --git a/drivers/scsi/mvumi.c b/drivers/scsi/mvumi.c
> > > index 36f64205ecfa..d3582accfd09 100644
> > > --- a/drivers/scsi/mvumi.c
> > > +++ b/drivers/scsi/mvumi.c
> > > @@ -313,7 +313,7 @@ static void mvumi_delete_internal_cmd(struct
> > > mvumi_hba
> > > *mhba,
> > > sgd_getsz(mhba, m_sg, size);
> > >
> > > phy_addr = (dma_addr_t) m_sg->baseaddr_l
> > > |
> > > - (dma_addr_t) ((m_sg->baseaddr_h
> > > << 16) << 16);
> > > + (((dma_addr_t) m_sg->baseaddr_h
> > > << 16) << 16);
> > >
> > > dma_free_coherent(&mhba->pdev->dev,
> > > size, cmd->data_buf,
> > >
> > > phy_addr);
> >
> > i would suggest to try a version with less casts to make it more
> > readable
> > like this untested suggestion:
> >
> > phy_addr =(m_sg->baseaddr_h << 16)| m_sg->baseaddr_l;
> > phy_addr <<= 16;
> >
>
> That would be a behavior change but it also might be a bugfix? Why
> doesn't the code just do:
>
> phy_addr = ((dma_addr_t)m_sg->baseaddr_h << 32) | m_sg-
> >baseaddr_l;
>
> (Probably they broke it up into two shifts to silence a GCC warning
> that the shift was wrong because of the missing cast?)
No because dma_addr_t can be 32 bits and the warning would then always
appear on some builds. The << 16 << 16 makes sure it doesn't.
James
next prev parent reply other threads:[~2019-02-18 15:32 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-02-16 14:44 [PATCH] scsi: mvumi: fix 32 bit shift of a 32 bit unsigned int Colin King
2019-02-16 16:27 ` Walter Harms
2019-02-16 16:27 ` Walter Harms
2019-02-18 9:37 ` Dan Carpenter
2019-02-18 9:37 ` Dan Carpenter
2019-02-18 15:32 ` James Bottomley [this message]
2019-02-18 15:32 ` James Bottomley
2019-02-18 15:47 ` Dan Carpenter
2019-02-18 15:47 ` Dan Carpenter
2019-02-18 12:42 ` Walter Harms
2019-02-18 14:24 ` Dan Carpenter
2019-02-18 16:52 ` Walter Harms
2019-08-13 18:01 ` [PATCH] scsi: mvumi: fix 32 bit shift of a u32 value Colin King
2019-08-13 18:01 ` Colin King
2019-08-14 7:17 ` walter harms
2019-08-14 7:17 ` walter harms
2019-08-14 8:07 ` Dan Carpenter
2019-08-14 8:07 ` Dan Carpenter
2019-08-14 15:07 ` kbuild test robot
2019-08-14 15:07 ` kbuild test robot
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=1550503925.2834.3.camel@linux.ibm.com \
--to=jejb@linux.ibm.com \
--cc=colin.king@canonical.com \
--cc=dan.carpenter@oracle.com \
--cc=jyli@marvell.com \
--cc=kernel-janitors@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=martin.petersen@oracle.com \
--cc=wharms@bfs.de \
/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.