Skip to contentSkip to conversation

PCI: endpoint: Fix missing unlock on error in pci_epf_add_vepf()

PATCH In review Wei Yongjun 2 participants 2 messages Aug 19, 2021

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 PCI: endpoint: Fix missing unlock on error in pci_epf_add_vepf()

Add the missing unlock before return from function pci_epf_add_vepf() in the error handling case.

Fixes b64215ff2b5e ("PCI: endpoint: Add support to add virtual function in endpoint core")
---
 drivers/pci/endpoint/pci-epf-core.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/pci/endpoint/pci-epf-core.c +3 -1
index ec286ee5d04c..8aea16380870 100644
@@ -200,8 +200,10 @@ int pci_epf_add_vepf(struct pci_epf *epf_pf, struct pci_epf *epf_vf)
 	mutex_lock(&epf_pf->lock);
 	vfunc_no = find_first_zero_bit(&epf_pf->vfunction_num_map,
 				       BITS_PER_LONG);
-	if (vfunc_no >= BITS_PER_LONG)
+	if (vfunc_no >= BITS_PER_LONG) {
+		mutex_unlock(&epf_pf->lock);
 		return -EINVAL;
+	}
 
 	set_bit(vfunc_no, &epf_pf->vfunction_num_map);
 	epf_vf->vfunc_no = vfunc_no;
#1 lore raw

Hi Wei,

Quoted 6 lines · Wei Yongjun

Add the missing unlock before return from function pci_epf_add_vepf() in the error handling case.

Fixes b64215ff2b5e ("PCI: endpoint: Add support to add virtual function in endpoint core")

Thanks for the patch. Since I had to resend the series, I squashed this patch into the original series

https://lore.kernel.org/r/[email protected]

Thanks
Kishon

Quoted 21 lines
---
 drivers/pci/endpoint/pci-epf-core.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/pci/endpoint/pci-epf-core.c +3 -1
index ec286ee5d04c..8aea16380870 100644
@@ -200,8 +200,10 @@ int pci_epf_add_vepf(struct pci_epf *epf_pf, struct pci_epf *epf_vf)
 	mutex_lock(&epf_pf->lock);
 	vfunc_no = find_first_zero_bit(&epf_pf->vfunction_num_map,
 				       BITS_PER_LONG);
-	if (vfunc_no >= BITS_PER_LONG)
+	if (vfunc_no >= BITS_PER_LONG) {
+		mutex_unlock(&epf_pf->lock);
 		return -EINVAL;
+	}
 
 	set_bit(vfunc_no, &epf_pf->vfunction_num_map);
 	epf_vf->vfunc_no = vfunc_no;