All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH -next v2] PCI: endpoint: pci-epf-vntb: fix error handle in epf_ntb_mw_bar_init()
@ 2022-06-25  2:15 Yang Yingliang
  2022-06-27 20:27 ` Bjorn Helgaas
  2022-12-13 18:27 ` Bjorn Helgaas
  0 siblings, 2 replies; 4+ messages in thread
From: Yang Yingliang @ 2022-06-25  2:15 UTC (permalink / raw)
  To: linux-kernel, linux-pci
  Cc: Frank.Li, jdmason, kishon, lpieralisi, kw, bhelgaas

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>
---
v2:
  add error label err_set_bar and move pci_epc_clear_bar() to it
---
 drivers/pci/endpoint/functions/pci-epf-vntb.c | 20 ++++++++++++++-----
 1 file 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 ebf7e243eefa..ee9fee167d48 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,13 +627,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;
 }
 
@@ -640,12 +650,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 +784,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 +804,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


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH -next v2] PCI: endpoint: pci-epf-vntb: fix error handle in epf_ntb_mw_bar_init()
  2022-06-25  2:15 [PATCH -next v2] PCI: endpoint: pci-epf-vntb: fix error handle in epf_ntb_mw_bar_init() Yang Yingliang
@ 2022-06-27 20:27 ` Bjorn Helgaas
  2022-08-12 14:06   ` Jon Mason
  2022-12-13 18:27 ` Bjorn Helgaas
  1 sibling, 1 reply; 4+ messages in thread
From: Bjorn Helgaas @ 2022-06-27 20:27 UTC (permalink / raw)
  To: Yang Yingliang, Jon Mason
  Cc: linux-kernel, linux-pci, Frank.Li, kishon, lpieralisi, kw, bhelgaas

On Sat, Jun 25, 2022 at 10:15:16AM +0800, Yang Yingliang wrote:
> 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.

Another one for Jon, since ff32fac00d97 appeared in -next via his
tree

https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/commit/?id=ff32fac00d97

> 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>
> ---
> v2:
>   add error label err_set_bar and move pci_epc_clear_bar() to it
> ---
>  drivers/pci/endpoint/functions/pci-epf-vntb.c | 20 ++++++++++++++-----
>  1 file 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 ebf7e243eefa..ee9fee167d48 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,13 +627,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;
>  }
>  
> @@ -640,12 +650,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 +784,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 +804,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
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH -next v2] PCI: endpoint: pci-epf-vntb: fix error handle in epf_ntb_mw_bar_init()
  2022-06-27 20:27 ` Bjorn Helgaas
@ 2022-08-12 14:06   ` Jon Mason
  0 siblings, 0 replies; 4+ messages in thread
From: Jon Mason @ 2022-08-12 14:06 UTC (permalink / raw)
  To: Bjorn Helgaas
  Cc: Yang Yingliang, linux-kernel, linux-pci, Frank.Li, kishon,
	lpieralisi, kw, bhelgaas

On Mon, Jun 27, 2022 at 03:27:04PM -0500, Bjorn Helgaas wrote:
> On Sat, Jun 25, 2022 at 10:15:16AM +0800, Yang Yingliang wrote:
> > 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.
> 
> Another one for Jon, since ff32fac00d97 appeared in -next via his
> tree
> 
> https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/commit/?id=ff32fac00d97

Sorry for the extremely long delay in response.  This series is in my
ntb branch and will be in my pull request for v5.20 which should be
going out later today.

Thanks,
Jon

> 
> > 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>
> > ---
> > v2:
> >   add error label err_set_bar and move pci_epc_clear_bar() to it
> > ---
> >  drivers/pci/endpoint/functions/pci-epf-vntb.c | 20 ++++++++++++++-----
> >  1 file 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 ebf7e243eefa..ee9fee167d48 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,13 +627,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;
> >  }
> >  
> > @@ -640,12 +650,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 +784,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 +804,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
> > 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH -next v2] PCI: endpoint: pci-epf-vntb: fix error handle in epf_ntb_mw_bar_init()
  2022-06-25  2:15 [PATCH -next v2] PCI: endpoint: pci-epf-vntb: fix error handle in epf_ntb_mw_bar_init() Yang Yingliang
  2022-06-27 20:27 ` Bjorn Helgaas
@ 2022-12-13 18:27 ` Bjorn Helgaas
  1 sibling, 0 replies; 4+ messages in thread
From: Bjorn Helgaas @ 2022-12-13 18:27 UTC (permalink / raw)
  To: Yang Yingliang
  Cc: linux-kernel, linux-pci, Frank.Li, jdmason, kishon, lpieralisi,
	kw, bhelgaas

On Sat, Jun 25, 2022 at 10:15:16AM +0800, Yang Yingliang wrote:
> 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.
> ...

> @@ -640,12 +650,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)

This change added a kernel-doc warning:

  drivers/pci/endpoint/functions/pci-epf-vntb.c:658: warning: Function parameter or member 'num_mws' not described in 'epf_ntb_mw_bar_clear'

Can you fix this, please?

I use this to check for kernel-doc warnings:

  $ find drivers/pci -type f -name \*.[ch] | xargs scripts/kernel-doc -none 

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-12-13 18:27 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-25  2:15 [PATCH -next v2] PCI: endpoint: pci-epf-vntb: fix error handle in epf_ntb_mw_bar_init() Yang Yingliang
2022-06-27 20:27 ` Bjorn Helgaas
2022-08-12 14:06   ` Jon Mason
2022-12-13 18:27 ` Bjorn Helgaas

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.