• Andrew Murray's avatar
    asm-generic: io: Fix ioport_map() for !CONFIG_GENERIC_IOMAP && CONFIG_INDIRECT_PIO · 500dd232
    Andrew Murray authored
    The !CONFIG_GENERIC_IOMAP version of ioport_map uses MMIO_UPPER_LIMIT to
    prevent users from making I/O accesses outside the expected I/O range -
    however it erroneously treats MMIO_UPPER_LIMIT as a mask which is
    contradictory to its other users.
    
    The introduction of CONFIG_INDIRECT_PIO, which subtracts an arbitrary
    amount from IO_SPACE_LIMIT to form MMIO_UPPER_LIMIT, results in ioport_map
    mangling the given port rather than capping it.
    
    We address this by aligning more closely with the CONFIG_GENERIC_IOMAP
    implementation of ioport_map by using the comparison operator and
    returning NULL where the port exceeds MMIO_UPPER_LIMIT. Though note that
    we preserve the existing behavior of masking with IO_SPACE_LIMIT such that
    we don't break existing buggy drivers that somehow rely on this masking.
    
    Fixes: 5745392e ("PCI: Apply the new generic I/O management on PCI IO hosts")
    Reported-by: default avatarWill Deacon <will.deacon@arm.com>
    Reviewed-by: default avatarArnd Bergmann <arnd@arndb.de>
    Signed-off-by: default avatarAndrew Murray <andrew.murray@arm.com>
    Signed-off-by: default avatarWill Deacon <will.deacon@arm.com>
    500dd232
io.h 22.7 KB