[PATCH 1/2] PCI: endpoint: strictly apply bar fixed size to allocate space

From: Jerome Brunet
Date: Fri Mar 28 2025 - 10:54:33 EST


When trying to allocate space for an endpoint function on a BAR with a
fixed size, that size should be used regardless of the alignment.

Some controller may have specified an alignment, but do have a BAR with a
fixed size smaller that alignment. In such case, pci_epf_alloc_space()
tries to allocate a space that matches the alignment and it won't work.

When the BAR size is fixed, pci_epf_alloc_space() should not deviate
from this fixed size.

Fixes: 2a9a801620ef ("PCI: endpoint: Add support to specify alignment for buffers allocated to BARs")
Signed-off-by: Jerome Brunet <jbrunet@xxxxxxxxxxxx>
---
drivers/pci/endpoint/pci-epf-core.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/drivers/pci/endpoint/pci-epf-core.c b/drivers/pci/endpoint/pci-epf-core.c
index 394395c7f8decfa2010469655a4bd58a002993fd..cb985b172ed041c6f319c083f412e51e25b0a157 100644
--- a/drivers/pci/endpoint/pci-epf-core.c
+++ b/drivers/pci/endpoint/pci-epf-core.c
@@ -285,12 +285,11 @@ void *pci_epf_alloc_space(struct pci_epf *epf, size_t size, enum pci_barno bar,
return NULL;
}
size = bar_fixed_size;
- }
-
- if (align)
+ } else if (align) {
size = ALIGN(size, align);
- else
+ } else {
size = roundup_pow_of_two(size);
+ }

if (type == PRIMARY_INTERFACE) {
epc = epf->epc;

--
2.47.2