Skip to content

Commit 56fab6e

Browse files
tpetazzonibjorn-helgaas
authored andcommitted
PCI: mvebu: Fix uninitialized variable in mvebu_get_tgt_attr()
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. Reported-by: Geert Uytterhoeven <geert+renesas@glider.be> Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com> Signed-off-by: Bjorn Helgaas <bhelgaas@google.com> CC: stable@vger.kernel.org # v3.12+
1 parent 52addcf commit 56fab6e

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

‎drivers/pci/host/pci-mvebu.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -873,7 +873,7 @@ static int mvebu_get_tgt_attr(struct device_node *np, int devfn,
873873
rangesz = pna + na + ns;
874874
nranges = rlen / sizeof(__be32) / rangesz;
875875

876-
for (i = 0; i < nranges; i++) {
876+
for (i = 0; i < nranges; i++, range += rangesz) {
877877
u32 flags = of_read_number(range, 1);
878878
u32 slot = of_read_number(range + 1, 1);
879879
u64 cpuaddr = of_read_number(range + na, pna);
@@ -883,14 +883,14 @@ static int mvebu_get_tgt_attr(struct device_node *np, int devfn,
883883
rtype = IORESOURCE_IO;
884884
else if (DT_FLAGS_TO_TYPE(flags) == DT_TYPE_MEM32)
885885
rtype = IORESOURCE_MEM;
886+
else
887+
continue;
886888

887889
if (slot == PCI_SLOT(devfn) && type == rtype) {
888890
*tgt = DT_CPUADDR_TO_TARGET(cpuaddr);
889891
*attr = DT_CPUADDR_TO_ATTR(cpuaddr);
890892
return 0;
891893
}
892-
893-
range += rangesz;
894894
}
895895

896896
return -ENOENT;

0 commit comments

Comments
 (0)