Unverified Commit 4f4da884 authored by openeuler-ci-bot's avatar openeuler-ci-bot Committed by Gitee
Browse files

!15472 PCI: dwc: ep: Prevent changing BAR size/flags in pci_epc_set_bar()

parents f6374604 75a74bd3
Loading
Loading
Loading
Loading
+21 −1
Original line number Diff line number Diff line
@@ -256,8 +256,28 @@ static int dw_pcie_ep_set_bar(struct pci_epc *epc, u8 func_no, u8 vfunc_no,
	if (ret)
		return ret;

	if (ep->epf_bar[bar])
	/*
	 * Certain EPF drivers dynamically change the physical address of a BAR
	 * (i.e. they call set_bar() twice, without ever calling clear_bar(), as
	 * calling clear_bar() would clear the BAR's PCI address assigned by the
	 * host).
	 */
	if (ep->epf_bar[bar]) {
		/*
		 * We can only dynamically change a BAR if the new BAR size and
		 * BAR flags do not differ from the existing configuration.
		 */
		if (ep->epf_bar[bar]->barno != bar ||
		    ep->epf_bar[bar]->size != size ||
		    ep->epf_bar[bar]->flags != flags)
			return -EINVAL;

		/*
		 * When dynamically changing a BAR, skip writing the BAR reg, as
		 * that would clear the BAR's PCI address assigned by the host.
		 */
		return 0;
	}

	dw_pcie_dbi_ro_wr_en(pci);