[PATCH v2 2/2] PCI: endpoint: Fix API pci_epc_remove_epf() cleaning up wrong EPC of EPF

Zijun Hu posted 2 patches 2 weeks, 3 days ago
[PATCH v2 2/2] PCI: endpoint: Fix API pci_epc_remove_epf() cleaning up wrong EPC of EPF
Posted by Zijun Hu 2 weeks, 3 days ago
From: Zijun Hu <quic_zijuhu@quicinc.com>

It is wrong for pci_epc_remove_epf(..., epf, SECONDARY_INTERFACE) to
clean up @epf->epc obviously.

Fix by cleaning up @epf->sec_epc instead of @epf->epc for
SECONDARY_INTERFACE.

Fixes: 63840ff53223 ("PCI: endpoint: Add support to associate secondary EPC with EPF")
Cc: stable@vger.kernel.org
Signed-off-by: Zijun Hu <quic_zijuhu@quicinc.com>
---
 drivers/pci/endpoint/pci-epc-core.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/pci/endpoint/pci-epc-core.c b/drivers/pci/endpoint/pci-epc-core.c
index bcc9bc3d6df5..62f7dff43730 100644
--- a/drivers/pci/endpoint/pci-epc-core.c
+++ b/drivers/pci/endpoint/pci-epc-core.c
@@ -660,18 +660,18 @@ void pci_epc_remove_epf(struct pci_epc *epc, struct pci_epf *epf,
 	if (IS_ERR_OR_NULL(epc) || !epf)
 		return;
 
+	mutex_lock(&epc->list_lock);
 	if (type == PRIMARY_INTERFACE) {
 		func_no = epf->func_no;
 		list = &epf->list;
+		epf->epc = NULL;
 	} else {
 		func_no = epf->sec_epc_func_no;
 		list = &epf->sec_epc_list;
+		epf->sec_epc = NULL;
 	}
-
-	mutex_lock(&epc->list_lock);
 	clear_bit(func_no, &epc->function_num_map);
 	list_del(list);
-	epf->epc = NULL;
 	mutex_unlock(&epc->list_lock);
 }
 EXPORT_SYMBOL_GPL(pci_epc_remove_epf);

-- 
2.34.1
Re: [PATCH v2 2/2] PCI: endpoint: Fix API pci_epc_remove_epf() cleaning up wrong EPC of EPF
Posted by Manivannan Sadhasivam 1 week, 4 days ago
On Thu, Nov 07, 2024 at 08:53:09AM +0800, Zijun Hu wrote:
> From: Zijun Hu <quic_zijuhu@quicinc.com>
> 
> It is wrong for pci_epc_remove_epf(..., epf, SECONDARY_INTERFACE) to
> clean up @epf->epc obviously.
> 
> Fix by cleaning up @epf->sec_epc instead of @epf->epc for
> SECONDARY_INTERFACE.
> 
> Fixes: 63840ff53223 ("PCI: endpoint: Add support to associate secondary EPC with EPF")
> Cc: stable@vger.kernel.org
> Signed-off-by: Zijun Hu <quic_zijuhu@quicinc.com>

Reviewed-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>

- Mani

> ---
>  drivers/pci/endpoint/pci-epc-core.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/pci/endpoint/pci-epc-core.c b/drivers/pci/endpoint/pci-epc-core.c
> index bcc9bc3d6df5..62f7dff43730 100644
> --- a/drivers/pci/endpoint/pci-epc-core.c
> +++ b/drivers/pci/endpoint/pci-epc-core.c
> @@ -660,18 +660,18 @@ void pci_epc_remove_epf(struct pci_epc *epc, struct pci_epf *epf,
>  	if (IS_ERR_OR_NULL(epc) || !epf)
>  		return;
>  
> +	mutex_lock(&epc->list_lock);
>  	if (type == PRIMARY_INTERFACE) {
>  		func_no = epf->func_no;
>  		list = &epf->list;
> +		epf->epc = NULL;
>  	} else {
>  		func_no = epf->sec_epc_func_no;
>  		list = &epf->sec_epc_list;
> +		epf->sec_epc = NULL;
>  	}
> -
> -	mutex_lock(&epc->list_lock);
>  	clear_bit(func_no, &epc->function_num_map);
>  	list_del(list);
> -	epf->epc = NULL;
>  	mutex_unlock(&epc->list_lock);
>  }
>  EXPORT_SYMBOL_GPL(pci_epc_remove_epf);
> 
> -- 
> 2.34.1
> 

-- 
மணிவண்ணன் சதாசிவம்