Skip to content

Commit 8e4bfbe

Browse files
Yang Yingliangjonmason
authored andcommitted
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: ff32fac ("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>
1 parent 556a2c7 commit 8e4bfbe

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

drivers/pci/endpoint/functions/pci-epf-vntb.c

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,8 @@ static int epf_ntb_db_bar_init(struct epf_ntb *ntb)
561561
return -1;
562562
}
563563

564+
static void epf_ntb_mw_bar_clear(struct epf_ntb *ntb, int num_mws);
565+
564566
/**
565567
* epf_ntb_db_bar_clear() - Clear doorbell BAR and free memory
566568
* allocated in peer's outbound address space
@@ -617,26 +619,34 @@ static int epf_ntb_mw_bar_init(struct epf_ntb *ntb)
617619
&ntb->vpci_mw_phy[i],
618620
size);
619621
if (!ntb->vpci_mw_addr[i]) {
622+
ret = -ENOMEM;
620623
dev_err(dev, "Failed to allocate source address\n");
621-
goto err_alloc_mem;
624+
goto err_set_bar;
622625
}
623626
}
624627

625628
return ret;
629+
630+
err_set_bar:
631+
pci_epc_clear_bar(ntb->epf->epc,
632+
ntb->epf->func_no,
633+
ntb->epf->vfunc_no,
634+
&ntb->epf->bar[barno]);
626635
err_alloc_mem:
636+
epf_ntb_mw_bar_clear(ntb, i);
627637
return ret;
628638
}
629639

630640
/**
631641
* epf_ntb_mw_bar_clear() - Clear Memory window BARs
632642
* @ntb: NTB device that facilitates communication between HOST and vHOST
633643
*/
634-
static void epf_ntb_mw_bar_clear(struct epf_ntb *ntb)
644+
static void epf_ntb_mw_bar_clear(struct epf_ntb *ntb, int num_mws)
635645
{
636646
enum pci_barno barno;
637647
int i;
638648

639-
for (i = 0; i < ntb->num_mws; i++) {
649+
for (i = 0; i < num_mws; i++) {
640650
barno = ntb->epf_ntb_bar[BAR_MW0 + i];
641651
pci_epc_clear_bar(ntb->epf->epc,
642652
ntb->epf->func_no,
@@ -764,7 +774,7 @@ static int epf_ntb_epc_init(struct epf_ntb *ntb)
764774
return 0;
765775

766776
err_write_header:
767-
epf_ntb_mw_bar_clear(ntb);
777+
epf_ntb_mw_bar_clear(ntb, ntb->num_mws);
768778
err_mw_bar_init:
769779
epf_ntb_db_bar_clear(ntb);
770780
err_db_bar_init:
@@ -784,7 +794,7 @@ static int epf_ntb_epc_init(struct epf_ntb *ntb)
784794
static void epf_ntb_epc_cleanup(struct epf_ntb *ntb)
785795
{
786796
epf_ntb_db_bar_clear(ntb);
787-
epf_ntb_mw_bar_clear(ntb);
797+
epf_ntb_mw_bar_clear(ntb, ntb->num_mws);
788798
}
789799

790800
#define EPF_NTB_R(_name) \

0 commit comments

Comments
 (0)