From: Frank Li <frank.li@nxp.com>
To: Yang Yingliang <yangyingliang@huawei.com>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"linux-pci@vger.kernel.org" <linux-pci@vger.kernel.org>
Cc: "jdmason@kudzu.us" <jdmason@kudzu.us>,
"kishon@ti.com" <kishon@ti.com>,
"lpieralisi@kernel.org" <lpieralisi@kernel.org>,
"kw@linux.com" <kw@linux.com>,
"bhelgaas@google.com" <bhelgaas@google.com>
Subject: RE: [PATCH -next] PCI: endpoint: pci-epf-vntb: fix error handle in epf_ntb_mw_bar_init()
Date: Fri, 24 Jun 2022 14:46:09 +0000 [thread overview]
Message-ID: <PAXPR04MB9186907C398EC709B7ADF95888B49@PAXPR04MB9186.eurprd04.prod.outlook.com> (raw)
In-Reply-To: <20220624094604.2159713-1-yangyingliang@huawei.com>
> -----Original Message-----
> From: Yang Yingliang <yangyingliang@huawei.com>
> Sent: Friday, June 24, 2022 4:46 AM
> To: linux-kernel@vger.kernel.org; linux-pci@vger.kernel.org
> Cc: Frank Li <frank.li@nxp.com>; jdmason@kudzu.us; kishon@ti.com;
> lpieralisi@kernel.org; kw@linux.com; bhelgaas@google.com
> Subject: [PATCH -next] 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>
> ---
> drivers/pci/endpoint/functions/pci-epf-vntb.c | 16 ++++++++++++----
> 1 file changed, 12 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/pci/endpoint/functions/pci-epf-vntb.c
> b/drivers/pci/endpoint/functions/pci-epf-vntb.c
> index ebf7e243eefa..d8ed640c16c4 100644
> --- a/drivers/pci/endpoint/functions/pci-epf-vntb.c
> +++ b/drivers/pci/endpoint/functions/pci-epf-vntb.c
> @@ -567,6 +567,8 @@ static int epf_ntb_db_bar_init(struct epf_ntb *ntb)
> 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 peers outbound address space
> @@ -625,6 +627,11 @@ static int epf_ntb_mw_bar_init(struct epf_ntb *ntb)
> &ntb-
> >vpci_mw_phy[i],
> size);
> if (!ntb->vpci_mw_addr[i]) {
> + pci_epc_clear_bar(ntb->epf->epc,
> + ntb->epf->func_no,
> + ntb->epf->vfunc_no,
> + &ntb->epf->bar[barno]);
> + ret = -ENOMEM;
This function move to goto and keep consistent of error handle.
Suggest:
Goto err_set_bar
....
Error_set_bar:
Pci_epc_clear_bar();
> dev_err(dev, "Failed to allocate source address\n");
> goto err_alloc_mem;
> }
> @@ -632,6 +639,7 @@ static int epf_ntb_mw_bar_init(struct epf_ntb *ntb)
>
> return ret;
> err_alloc_mem:
> + epf_ntb_mw_bar_clear(ntb, i);
> return ret;
> }
>
> @@ -640,12 +648,12 @@ static int epf_ntb_mw_bar_init(struct epf_ntb *ntb)
> * @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,
> @@ -774,7 +782,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:
> @@ -794,7 +802,7 @@ static int epf_ntb_epc_init(struct epf_ntb *ntb)
> 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) \
> --
> 2.25.1
prev parent reply other threads:[~2022-06-24 14:52 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-24 9:46 [PATCH -next] PCI: endpoint: pci-epf-vntb: fix error handle in epf_ntb_mw_bar_init() Yang Yingliang
2022-06-24 14:46 ` Frank Li [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=PAXPR04MB9186907C398EC709B7ADF95888B49@PAXPR04MB9186.eurprd04.prod.outlook.com \
--to=frank.li@nxp.com \
--cc=bhelgaas@google.com \
--cc=jdmason@kudzu.us \
--cc=kishon@ti.com \
--cc=kw@linux.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=lpieralisi@kernel.org \
--cc=yangyingliang@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).