Skip to contentSkip to conversation

lib/pci_iomap.c: fix cleanup bugs in pci_iounmap()

PATCH Superseded Philipp Stanner 1 participant 1 message Jan 4, 2024 1 message not in the archive

Subsystems (2)

v5 of 6 Superseded Latest is v6 →

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

PATCH v5 1/5 lib/pci_iomap.c: fix cleanup bugs in pci_iounmap()

pci_iounmap() in lib/pci_iomap.c is supposed to check whether an address is within ioport-range IF the config specifies that ioports exist. If so, the port should be unmapped with ioport_unmap(). If not, it's a generic MMIO address that has to be passed to iounmap().

The bugs are:
1. ioport_unmap() is missing entirely, so this function will never actually unmap a port.
2. the #ifdef for the ioport-ranges accidentally also guards iounmap(), potentially compiling an empty function. This would cause the mapping to be leaked.

Implement the missing call to ioport_unmap().

Move the guard so that iounmap() will always be part of the function.

CC <[email protected]> # v5.15+
Fixes 316e8d79a095 ("pci_iounmap'2: Electric Boogaloo: try to make sense of it all")
---
 lib/pci_iomap.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
lib/pci_iomap.c +4 -2
index ce39ce9f3526..6e144b017c48 100644
@@ -168,10 +168,12 @@ void pci_iounmap(struct pci_dev *dev, void __iomem *p)
 	uintptr_t start = (uintptr_t) PCI_IOBASE;
 	uintptr_t addr = (uintptr_t) p;
 
-	if (addr >= start && addr < start + IO_SPACE_LIMIT)
+	if (addr >= start && addr < start + IO_SPACE_LIMIT) {
+		ioport_unmap(p);
 		return;
-	iounmap(p);
+	}
 #endif
+	iounmap(p);
 }
 EXPORT_SYMBOL(pci_iounmap);
 
Signature · 1 line
2.43.0