Skip to content

Commit 0e7faea

Browse files
floatiouskwilczynski
authored andcommitted
PCI: endpoint: Verify that requested BAR size is a power of two
When allocating a BAR using pci_epf_alloc_space(), there are checks that round up the size to a power of two. However, there is no check in pci_epc_set_bar() which verifies that the requested BAR size is a power of two. Add a power of two check in pci_epc_set_bar(), so that we don't need to add such a check in each and every PCI endpoint controller driver. Link: https://lore.kernel.org/r/20241213143301.4158431-14-cassel@kernel.org Signed-off-by: Niklas Cassel <cassel@kernel.org> Signed-off-by: Krzysztof Wilczyński <kwilczynski@kernel.org> Reviewed-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
1 parent f015b53 commit 0e7faea

1 file changed

Lines changed: 3 additions & 0 deletions

File tree

drivers/pci/endpoint/pci-epc-core.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,9 @@ int pci_epc_set_bar(struct pci_epc *epc, u8 func_no, u8 vfunc_no,
613613
(epc_features->bar[bar].fixed_size != epf_bar->size))
614614
return -EINVAL;
615615

616+
if (!is_power_of_2(epf_bar->size))
617+
return -EINVAL;
618+
616619
if ((epf_bar->barno == BAR_5 && flags & PCI_BASE_ADDRESS_MEM_TYPE_64) ||
617620
(flags & PCI_BASE_ADDRESS_SPACE_IO &&
618621
flags & PCI_BASE_ADDRESS_IO_MASK) ||

0 commit comments

Comments
 (0)