summaryrefslogtreecommitdiff
path: root/drivers/pci
diff options
context:
space:
mode:
authorYang Yingliang <yangyingliang@huawei.com>2022-06-25 05:15:16 +0300
committerJon Mason <jdmason@kudzu.us>2022-08-10 00:54:40 +0300
commit8e4bfbe644a6b804a72fd4575d89507a6e1d9476 (patch)
tree067a10f62c62baefe3105b18c12b623666286a01 /drivers/pci
parent556a2c7dca337954040ffdf0c544aa8bbb75583b (diff)
downloadlinux-8e4bfbe644a6b804a72fd4575d89507a6e1d9476.tar.xz
PCI: endpoint: pci-epf-vntb: fix error handle in epf_ntb_mw_bar_init()
In error case of epf_ntb_mw_bar_init(), memory window BARs should be cleared, so add 'num_mws' parameter in epf_ntb_mw_bar_clear() and calling it in error path to clear the BARs. Also add missing error code when pci_epc_mem_alloc_addr() fails. Fixes: ff32fac00d97 ("NTB: EPF: support NTB transfer between PCI RC and EP connection") Reported-by: Hulk Robot <hulkci@huawei.com> Signed-off-by: Yang Yingliang <yangyingliang@huawei.com> Signed-off-by: Jon Mason <jdmason@kudzu.us>
Diffstat (limited to 'drivers/pci')
-rw-r--r--drivers/pci/endpoint/functions/pci-epf-vntb.c20
1 files changed, 15 insertions, 5 deletions
diff --git a/drivers/pci/endpoint/functions/pci-epf-vntb.c b/drivers/pci/endpoint/functions/pci-epf-vntb.c
index 599538cd554c..b069c84ec172 100644
--- a/drivers/pci/endpoint/functions/pci-epf-vntb.c
+++ b/drivers/pci/endpoint/functions/pci-epf-vntb.c
@@ -561,6 +561,8 @@ err_alloc_peer_mem:
return -1;
}
+static void epf_ntb_mw_bar_clear(struct epf_ntb *ntb, int num_mws);
+
/**
* epf_ntb_db_bar_clear() - Clear doorbell BAR and free memory
* allocated in peer's outbound address space
@@ -617,13 +619,21 @@ static int epf_ntb_mw_bar_init(struct epf_ntb *ntb)
&ntb->vpci_mw_phy[i],
size);
if (!ntb->vpci_mw_addr[i]) {
+ ret = -ENOMEM;
dev_err(dev, "Failed to allocate source address\n");
- goto err_alloc_mem;
+ goto err_set_bar;
}
}
return ret;
+
+err_set_bar:
+ pci_epc_clear_bar(ntb->epf->epc,
+ ntb->epf->func_no,
+ ntb->epf->vfunc_no,
+ &ntb->epf->bar[barno]);
err_alloc_mem:
+ epf_ntb_mw_bar_clear(ntb, i);
return ret;
}
@@ -631,12 +641,12 @@ err_alloc_mem:
* epf_ntb_mw_bar_clear() - Clear Memory window BARs
* @ntb: NTB device that facilitates communication between HOST and vHOST
*/
-static void epf_ntb_mw_bar_clear(struct epf_ntb *ntb)
+static void epf_ntb_mw_bar_clear(struct epf_ntb *ntb, int num_mws)
{
enum pci_barno barno;
int i;
- for (i = 0; i < ntb->num_mws; i++) {
+ for (i = 0; i < num_mws; i++) {
barno = ntb->epf_ntb_bar[BAR_MW0 + i];
pci_epc_clear_bar(ntb->epf->epc,
ntb->epf->func_no,
@@ -764,7 +774,7 @@ static int epf_ntb_epc_init(struct epf_ntb *ntb)
return 0;
err_write_header:
- epf_ntb_mw_bar_clear(ntb);
+ epf_ntb_mw_bar_clear(ntb, ntb->num_mws);
err_mw_bar_init:
epf_ntb_db_bar_clear(ntb);
err_db_bar_init:
@@ -784,7 +794,7 @@ err_config_interrupt:
static void epf_ntb_epc_cleanup(struct epf_ntb *ntb)
{
epf_ntb_db_bar_clear(ntb);
- epf_ntb_mw_bar_clear(ntb);
+ epf_ntb_mw_bar_clear(ntb, ntb->num_mws);
}
#define EPF_NTB_R(_name) \