From: Bjorn Helgaas <helgaas@kernel.org>
To: Jon Hunter <jonathanh@nvidia.com>
Cc: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>,
Bjorn Helgaas <bhelgaas@google.com>,
Thierry Reding <thierry.reding@gmail.com>,
Vidya Sagar <vidyas@nvidia.com>,
linux-pci@vger.kernel.org, linux-tegra@vger.kernel.org
Subject: Re: [PATCH] PCI: tegra: Fix shiftTooManyBitsSigned warning for Tegra194
Date: Thu, 24 Jun 2021 18:01:50 -0500 [thread overview]
Message-ID: <20210624230150.GA3574555@bjorn-Precision-5520> (raw)
In-Reply-To: <20210618230428.GA3231877@bjorn-Precision-5520>
On Fri, Jun 18, 2021 at 06:04:28PM -0500, Bjorn Helgaas wrote:
> On Fri, Jun 18, 2021 at 05:02:19PM +0100, Jon Hunter wrote:
> > The cppcheck tool issues the following warning for the Tegra194 PCIe
> > driver ...
> >
> > $ cppcheck --enable=all drivers/pci/controller/dwc/pcie-tegra194.c
> > Checking drivers/pci/controller/dwc/pcie-tegra194.c ...
> >
> > drivers/pci/controller/dwc/pcie-tegra194.c:1829:23: portability:
> > Shifting signed 32-bit value by 31 bits is
> > implementation-defined behaviour. See condition at line 1826.
> > [shiftTooManyBitsSigned]
> >
> > appl_writel(pcie, (1 << irq), APPL_MSI_CTRL_1);
> > ^
> > The above warning occurs because the '1' is treated as a signed type
> > and so fix this by using the 'BIT' macro to ensure that this is defined
> > as a unsigned type.
>
> The subject and commit log should describe the problem we're fixing.
> The *warning* is not the problem; the problem is the undefined
> behavior.
>
> I'll fix this up, no need to repost for this.
I merged this from Lorenzo's branch, but I updated the commit log like
this because the undefined behavior is the real problem:
PCI: tegra194: Fix tegra_pcie_ep_raise_msi_irq() ill-defined shift
tegra_pcie_ep_raise_msi_irq() shifted a signed 32-bit value left by 31
bits. The behavior of this is implementation-defined.
Replace the shift by BIT(), which is well-defined.
Found by cppcheck:
$ cppcheck --enable=all drivers/pci/controller/dwc/pcie-tegra194.c
Checking drivers/pci/controller/dwc/pcie-tegra194.c ...
drivers/pci/controller/dwc/pcie-tegra194.c:1829:23: portability: Shifting signed 32-bit value by 31 bits is implementation-defined behaviour. See condition at line 1826. [shiftTooManyBitsSigned]
appl_writel(pcie, (1 << irq), APPL_MSI_CTRL_1);
^
[bhelgaas: commit log]
Link: https://lore.kernel.org/r/20210618160219.303092-1-jonathanh@nvidia.com
Fixes: c57247f940e8 ("PCI: tegra: Add support for PCIe endpoint mode in Tegra194")
Signed-off-by: Jon Hunter <jonathanh@nvidia.com>
Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
> > Fixes: c57247f940e8 PCI: tegra: Add support for PCIe endpoint mode in Tegra194
> > Signed-off-by: Jon Hunter <jonathanh@nvidia.com>
> > ---
> > drivers/pci/controller/dwc/pcie-tegra194.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/drivers/pci/controller/dwc/pcie-tegra194.c b/drivers/pci/controller/dwc/pcie-tegra194.c
> > index 8fc08336f76e..3c1feeab104f 100644
> > --- a/drivers/pci/controller/dwc/pcie-tegra194.c
> > +++ b/drivers/pci/controller/dwc/pcie-tegra194.c
> > @@ -1826,7 +1826,7 @@ static int tegra_pcie_ep_raise_msi_irq(struct tegra_pcie_dw *pcie, u16 irq)
> > if (unlikely(irq > 31))
> > return -EINVAL;
> >
> > - appl_writel(pcie, (1 << irq), APPL_MSI_CTRL_1);
> > + appl_writel(pcie, BIT(irq), APPL_MSI_CTRL_1);
> >
> > return 0;
> > }
> > --
> > 2.25.1
> >
next prev parent reply other threads:[~2021-06-24 23:01 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-06-18 16:02 [PATCH] PCI: tegra: Fix shiftTooManyBitsSigned warning for Tegra194 Jon Hunter
2021-06-18 16:05 ` Jon Hunter
2021-06-18 23:04 ` Bjorn Helgaas
2021-06-23 8:52 ` Lorenzo Pieralisi
2021-06-23 12:04 ` Bjorn Helgaas
2021-06-24 23:01 ` Bjorn Helgaas [this message]
2021-06-25 9:08 ` Lorenzo Pieralisi
2021-06-23 15:23 ` Lorenzo Pieralisi
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=20210624230150.GA3574555@bjorn-Precision-5520 \
--to=helgaas@kernel.org \
--cc=bhelgaas@google.com \
--cc=jonathanh@nvidia.com \
--cc=linux-pci@vger.kernel.org \
--cc=linux-tegra@vger.kernel.org \
--cc=lorenzo.pieralisi@arm.com \
--cc=thierry.reding@gmail.com \
--cc=vidyas@nvidia.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