Skip to content

Commit f015b53

Browse files
floatiouskwilczynski
authored andcommitted
PCI: endpoint: Add size check for fixed size BARs in pci_epc_set_bar()
A BAR of type BAR_FIXED has a fixed BAR size (the size cannot be changed). When using pci_epf_alloc_space() to allocate backing memory for a BAR, pci_epf_alloc_space() will always set the size to the fixed BAR size if the BAR type is BAR_FIXED (and will give an error if you the requested size is larger than the fixed BAR size). However, some drivers might not call pci_epf_alloc_space() before calling pci_epc_set_bar(), so add a check in pci_epc_set_bar() to ensure that an EPF driver cannot set a size different from the fixed BAR size, if the BAR type is BAR_FIXED. The pci_epc_function_is_valid() check is removed because this check is now done by pci_epc_get_features(). Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Niklas Cassel <[email protected]> Signed-off-by: Krzysztof Wilczyński <[email protected]> Reviewed-by: Frank Li <[email protected]> Reviewed-by: Manivannan Sadhasivam <[email protected]>
1 parent b61fef0 commit f015b53

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -600,10 +600,17 @@ EXPORT_SYMBOL_GPL(pci_epc_clear_bar);
600600
int pci_epc_set_bar(struct pci_epc *epc, u8 func_no, u8 vfunc_no,
601601
struct pci_epf_bar *epf_bar)
602602
{
603-
int ret;
603+
const struct pci_epc_features *epc_features;
604+
enum pci_barno bar = epf_bar->barno;
604605
int flags = epf_bar->flags;
606+
int ret;
605607

606-
if (!pci_epc_function_is_valid(epc, func_no, vfunc_no))
608+
epc_features = pci_epc_get_features(epc, func_no, vfunc_no);
609+
if (!epc_features)
610+
return -EINVAL;
611+
612+
if (epc_features->bar[bar].type == BAR_FIXED &&
613+
(epc_features->bar[bar].fixed_size != epf_bar->size))
607614
return -EINVAL;
608615

609616
if ((epf_bar->barno == BAR_5 && flags & PCI_BASE_ADDRESS_MEM_TYPE_64) ||

0 commit comments

Comments
 (0)