PCI: mvebu: Fix uninitialized variable in mvebu_get_tgt_attr()
PATCH 1/1 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.
---
This patch is a different solution than the one proposed by Geert. It (hopefully) matches the discussion we had with Bjorn and Arnd.
--- drivers/pci/host/pci-mvebu.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/pci/host/pci-mvebu.c +3 -3
@@ -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 ;
Signature · 1 line
2.0.0
PATCH 1/1 PCI: mvebu: Fix uninitialized variable in mvebu_get_tgt_attr()
Quoted 14 lines · Thomas Petazzoni
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.
Quoted 7 lines
Signed-off-by Thomas Petazzoni <[email protected]>Reported-by Geert Uytterhoeven <[email protected]>---
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 <[email protected]>
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.
Quoted 41 lines
--- drivers/pci/host/pci-mvebu.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)drivers/pci/host/pci-mvebu.c +3
-3@@ -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 ;Signature · 6 lines
2.0.0 -- To unsubscribe from this list: send the line "unsubscribe linux-pci" in the body of a message to majordomo at vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html