linux-pci.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Bjorn Helgaas <bhelgaas@google.com>
To: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
Cc: linux-pci@vger.kernel.org, Jason Cooper <jason@lakedaemon.net>,
	Andrew Lunn <andrew@lunn.ch>,
	Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>,
	Gregory Clement <gregory.clement@free-electrons.com>,
	linux-arm-kernel@lists.infradead.org,
	Geert Uytterhoeven <geert+renesas@glider.be>
Subject: Re: [PATCH] PCI: mvebu: Fix uninitialized variable in mvebu_get_tgt_attr()
Date: Mon, 22 Sep 2014 14:43:22 -0600	[thread overview]
Message-ID: <20140922204322.GG1880@google.com> (raw)
In-Reply-To: <1410969507-13692-1-git-send-email-thomas.petazzoni@free-electrons.com>

On Wed, Sep 17, 2014 at 05:58:27PM +0200, Thomas Petazzoni wrote:
> Geert Uytterhoeven reported a warning when building pci-mvebu:
> 
> drivers/pci/host/pci-mvebu.c: In function 'mvebu_get_tgt_attr':
> drivers/pci/host/pci-mvebu.c:887:39: warning: 'rtype' may be used uninitialized in this function [-Wmaybe-uninitialized]
>    if (slot == PCI_SLOT(devfn) && type == rtype) {
>                                        ^
> 
> And indeed, the code of mvebu_get_tgt_attr() may lead to the usage of
> rtype when being uninitialized, even though it would only happen if we
> had entries other than I/O space and 32 bits memory space.
> 
> This commit fixes that by simply skipping the current DT range being
> considered, if it doesn't match the resource type we're looking for.
> 
> Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
> Reported-by: Geert Uytterhoeven <geert+renesas@glider.be>
> ---
> This patch is a different solution than the one proposed by Geert. It
> (hopefully) matches the discussion we had with Bjorn and Arnd.
> 
> Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>

Applied to pci/host-mvebu for v3.18, thanks!  Oh, and I added a stable tag
for v3.12+, since mvebu_get_tgt_attr() appeared in v3.12.

> ---
>  drivers/pci/host/pci-mvebu.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/pci/host/pci-mvebu.c b/drivers/pci/host/pci-mvebu.c
> index a8c6f1a..b1315e1 100644
> --- a/drivers/pci/host/pci-mvebu.c
> +++ b/drivers/pci/host/pci-mvebu.c
> @@ -873,7 +873,7 @@ static int mvebu_get_tgt_attr(struct device_node *np, int devfn,
>  	rangesz = pna + na + ns;
>  	nranges = rlen / sizeof(__be32) / rangesz;
>  
> -	for (i = 0; i < nranges; i++) {
> +	for (i = 0; i < nranges; i++, range += rangesz) {
>  		u32 flags = of_read_number(range, 1);
>  		u32 slot = of_read_number(range + 1, 1);
>  		u64 cpuaddr = of_read_number(range + na, pna);
> @@ -883,14 +883,14 @@ static int mvebu_get_tgt_attr(struct device_node *np, int devfn,
>  			rtype = IORESOURCE_IO;
>  		else if (DT_FLAGS_TO_TYPE(flags) == DT_TYPE_MEM32)
>  			rtype = IORESOURCE_MEM;
> +		else
> +			continue;
>  
>  		if (slot == PCI_SLOT(devfn) && type == rtype) {
>  			*tgt = DT_CPUADDR_TO_TARGET(cpuaddr);
>  			*attr = DT_CPUADDR_TO_ATTR(cpuaddr);
>  			return 0;
>  		}
> -
> -		range += rangesz;
>  	}
>  
>  	return -ENOENT;
> -- 
> 2.0.0
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-pci" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

  reply	other threads:[~2014-09-22 20:43 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-09-17 15:58 Thomas Petazzoni
2014-09-22 20:43 ` Bjorn Helgaas [this message]
  -- strict thread matches above, loose matches on Subject: below --
2014-08-08 15:34 Geert Uytterhoeven
2014-09-05 17:41 ` Bjorn Helgaas
2014-09-05 17:51   ` Arnd Bergmann
2014-09-05 18:20   ` Thomas Petazzoni
2014-09-05 18:34     ` Arnd Bergmann
2014-09-05 19:00       ` Bjorn Helgaas
2014-09-16 23:17         ` Bjorn Helgaas

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=20140922204322.GG1880@google.com \
    --to=bhelgaas@google.com \
    --cc=andrew@lunn.ch \
    --cc=geert+renesas@glider.be \
    --cc=gregory.clement@free-electrons.com \
    --cc=jason@lakedaemon.net \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=sebastian.hesselbarth@gmail.com \
    --cc=thomas.petazzoni@free-electrons.com \
    --subject='Re: [PATCH] PCI: mvebu: Fix uninitialized variable in mvebu_get_tgt_attr()' \
    /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

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).