]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
x86/PCI: Fix Broadcom CNB20LE unintended sign extension
authorBjorn Helgaas <bhelgaas@google.com>
Fri, 25 Apr 2014 17:01:08 +0000 (11:01 -0600)
committerBjorn Helgaas <bhelgaas@google.com>
Fri, 25 Apr 2014 17:01:08 +0000 (11:01 -0600)
In the expression "word1 << 16", word1 starts as u16, but is promoted to
a signed int, then sign-extended to resource_size_t, which is probably
not what was intended.  Cast to resource_size_t to avoid the sign
extension.

Found by Coverity (CID 138749, 138750).

Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
arch/x86/pci/broadcom_bus.c

index 614392ced7d6b620a2db74cbe2e113a5e9f24643..bb461cfd01abc78cdc45c6e69f013128e04ccdb4 100644 (file)
@@ -60,8 +60,8 @@ static void __init cnb20le_res(u8 bus, u8 slot, u8 func)
        word1 = read_pci_config_16(bus, slot, func, 0xc4);
        word2 = read_pci_config_16(bus, slot, func, 0xc6);
        if (word1 != word2) {
-               res.start = (word1 << 16) | 0x0000;
-               res.end   = (word2 << 16) | 0xffff;
+               res.start = ((resource_size_t) word1 << 16) | 0x0000;
+               res.end   = ((resource_size_t) word2 << 16) | 0xffff;
                res.flags = IORESOURCE_MEM | IORESOURCE_PREFETCH;
                update_res(info, res.start, res.end, res.flags, 0);
        }