diff mbox series

[v3,3/3] PCI: endpoint: Fix API pci_epf_add_vepf() returning -EBUSY error

Message ID 20241210-pci-epc-core_fix-v3-3-4d86dd573e4b@quicinc.com (mailing list archive)
State Accepted
Commit 3b9f942eb21c92041905e3943a8d5177c9a9d89d
Delegated to: Bjorn Helgaas
Headers show
Series PCI: endpoint: fix bug for 2 APIs and simplify 1 API | expand

Commit Message

Zijun Hu Dec. 10, 2024, 2 p.m. UTC
From: Zijun Hu <quic_zijuhu@quicinc.com>

pci_epf_add_vepf() will suffer -EBUSY error by steps below:

pci_epf_add_vepf(@epf_pf, @epf_vf)       // add
pci_epf_remove_vepf(@epf_pf, @epf_vf)   // remove
pci_epf_add_vepf(@epf_pf, @epf_vf)     // add again, -EBUSY error.

Fix by clearing @epf_vf->epf_pf in pci_epf_remove_vepf().

Fixes: 1cf362e907f3 ("PCI: endpoint: Add support to add virtual function in endpoint core")
Cc: stable@vger.kernel.org
Signed-off-by: Zijun Hu <quic_zijuhu@quicinc.com>
---
 drivers/pci/endpoint/pci-epf-core.c | 1 +
 1 file changed, 1 insertion(+)

Comments

Frank Li Dec. 12, 2024, 6:03 p.m. UTC | #1
On Tue, Dec 10, 2024 at 10:00:20PM +0800, Zijun Hu wrote:
> From: Zijun Hu <quic_zijuhu@quicinc.com>
>
> pci_epf_add_vepf() will suffer -EBUSY error by steps below:
>
> pci_epf_add_vepf(@epf_pf, @epf_vf)       // add
> pci_epf_remove_vepf(@epf_pf, @epf_vf)   // remove
> pci_epf_add_vepf(@epf_pf, @epf_vf)     // add again, -EBUSY error.

nit: can you align comments to the same column?

Reviewed-by: Frank Li <Frank.Li@nxp.com>

>
> Fix by clearing @epf_vf->epf_pf in pci_epf_remove_vepf().
>
> Fixes: 1cf362e907f3 ("PCI: endpoint: Add support to add virtual function in endpoint core")
> Cc: stable@vger.kernel.org
> Signed-off-by: Zijun Hu <quic_zijuhu@quicinc.com>
> ---
>  drivers/pci/endpoint/pci-epf-core.c | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/drivers/pci/endpoint/pci-epf-core.c b/drivers/pci/endpoint/pci-epf-core.c
> index 8fa2797d4169a9f21136bbf73daa818da6c4ac49..50bc2892a36c54aa82c819ac5a9c99e9155d92c1 100644
> --- a/drivers/pci/endpoint/pci-epf-core.c
> +++ b/drivers/pci/endpoint/pci-epf-core.c
> @@ -202,6 +202,7 @@ void pci_epf_remove_vepf(struct pci_epf *epf_pf, struct pci_epf *epf_vf)
>
>  	mutex_lock(&epf_pf->lock);
>  	clear_bit(epf_vf->vfunc_no, &epf_pf->vfunction_num_map);
> +	epf_vf->epf_pf = NULL;
>  	list_del(&epf_vf->list);
>  	mutex_unlock(&epf_pf->lock);
>  }
>
> --
> 2.34.1
>
diff mbox series

Patch

diff --git a/drivers/pci/endpoint/pci-epf-core.c b/drivers/pci/endpoint/pci-epf-core.c
index 8fa2797d4169a9f21136bbf73daa818da6c4ac49..50bc2892a36c54aa82c819ac5a9c99e9155d92c1 100644
--- a/drivers/pci/endpoint/pci-epf-core.c
+++ b/drivers/pci/endpoint/pci-epf-core.c
@@ -202,6 +202,7 @@  void pci_epf_remove_vepf(struct pci_epf *epf_pf, struct pci_epf *epf_vf)
 
 	mutex_lock(&epf_pf->lock);
 	clear_bit(epf_vf->vfunc_no, &epf_pf->vfunction_num_map);
+	epf_vf->epf_pf = NULL;
 	list_del(&epf_vf->list);
 	mutex_unlock(&epf_pf->lock);
 }