Skip to content

Commit b50b631

Browse files
zijun-hugregkh
authored andcommitted
PCI: endpoint: Clear secondary (not primary) EPC in pci_epc_remove_epf()
commit 688d2eb upstream. In addition to a primary endpoint controller, an endpoint function may be associated with a secondary endpoint controller, epf->sec_epc, to provide NTB (non-transparent bridge) functionality. Previously, pci_epc_remove_epf() incorrectly cleared epf->epc instead of epf->sec_epc when removing from the secondary endpoint controller. Extend the epc->list_lock coverage and clear either epf->epc or epf->sec_epc as indicated. Link: https://lore.kernel.org/r/20241107-epc_rfc-v2-2-da5b6a99a66f@quicinc.com Fixes: 63840ff ("PCI: endpoint: Add support to associate secondary EPC with EPF") Signed-off-by: Zijun Hu <quic_zijuhu@quicinc.com> Reviewed-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org> [mani: reworded subject and description] Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org> [bhelgaas: commit log] Signed-off-by: Bjorn Helgaas <bhelgaas@google.com> Signed-off-by: Krzysztof Wilczyński <kwilczynski@kernel.org> Cc: stable@vger.kernel.org Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 2bf49d7 commit b50b631

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -663,18 +663,18 @@ void pci_epc_remove_epf(struct pci_epc *epc, struct pci_epf *epf,
663663
if (!epc || IS_ERR(epc) || !epf)
664664
return;
665665

666+
mutex_lock(&epc->list_lock);
666667
if (type == PRIMARY_INTERFACE) {
667668
func_no = epf->func_no;
668669
list = &epf->list;
670+
epf->epc = NULL;
669671
} else {
670672
func_no = epf->sec_epc_func_no;
671673
list = &epf->sec_epc_list;
674+
epf->sec_epc = NULL;
672675
}
673-
674-
mutex_lock(&epc->list_lock);
675676
clear_bit(func_no, &epc->function_num_map);
676677
list_del(list);
677-
epf->epc = NULL;
678678
mutex_unlock(&epc->list_lock);
679679
}
680680
EXPORT_SYMBOL_GPL(pci_epc_remove_epf);

0 commit comments

Comments
 (0)