[PATCH] PCI: don't allocate resource above 4G for 32-bit BAR

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Saw pci_bus_alloc_resource() allocated resource above 4G for a
non-Prefetchable Memory Space BAR on 64-bit machine. This is not correct
since the non-Prefetchable Memory Space and I/O Space are 32-bit width.
Only Prefetchable Memory Space support 64-bit address.

Signed-off-by: Yu Zhao <yu.zhao@xxxxxxxxx>
---
 drivers/pci/bus.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)

diff --git a/drivers/pci/bus.c b/drivers/pci/bus.c
index 52b54f0..b6512c0 100644
--- a/drivers/pci/bus.c
+++ b/drivers/pci/bus.c
@@ -40,9 +40,12 @@ pci_bus_alloc_resource(struct pci_bus *bus, struct resource *res,
 				resource_size_t),
 		void *alignf_data)
 {
+	resource_size_t max;
 	int i, ret = -ENOMEM;
 
 	type_mask |= IORESOURCE_IO | IORESOURCE_MEM;
+	/* only Prefetchable Memory Space supports 64-bit */
+	max = res->flags & IORESOURCE_PREFETCH ? (u64)-1 : (u32)-1;
 
 	for (i = 0; i < PCI_BUS_NUM_RESOURCES; i++) {
 		struct resource *r = bus->resource[i];
@@ -62,7 +65,7 @@ pci_bus_alloc_resource(struct pci_bus *bus, struct resource *res,
 		/* Ok, try it out.. */
 		ret = allocate_resource(r, res, size,
 					r->start ? : min,
-					-1, align,
+					max, align,
 					alignf, alignf_data);
 		if (ret == 0)
 			break;
-- 
1.5.6.4

--
To unsubscribe from this list: send the line "unsubscribe linux-pci" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [DMA Engine]     [Linux Coverity]     [Linux USB]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Greybus]

  Powered by Linux