[PATCH] qlcnic: fix a memory leak in __qlcnic_pci_sriov_enable()

Haoxiang Li posted 1 patch 11 months, 1 week ago
drivers/net/ethernet/qlogic/qlcnic/qlcnic_sriov_pf.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
[PATCH] qlcnic: fix a memory leak in __qlcnic_pci_sriov_enable()
Posted by Haoxiang Li 11 months, 1 week ago
Add qlcnic_sriov_free_vlans() to free the memory allocated by
qlcnic_sriov_alloc_vlans() if qlcnic_sriov_alloc_vlans() fails.

Fixes: 60ec7fcfe768 ("qlcnic: potential dereference null pointer of rx_queue->page_ring")
Cc: stable@vger.kernel.org
Signed-off-by: Haoxiang Li <haoxiang_li2024@163.com>
---
 drivers/net/ethernet/qlogic/qlcnic/qlcnic_sriov_pf.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_sriov_pf.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_sriov_pf.c
index 8dd7aa08ecfb..b8a9e0e2907e 100644
--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_sriov_pf.c
+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_sriov_pf.c
@@ -598,8 +598,10 @@ static int __qlcnic_pci_sriov_enable(struct qlcnic_adapter *adapter,
 		goto del_flr_queue;
 
 	err = qlcnic_sriov_alloc_vlans(adapter);
-	if (err)
+	if (err) {
+		qlcnic_sriov_free_vlans(adapter);
 		goto del_flr_queue;
+	}
 
 	return err;
 
-- 
2.25.1
Re: [PATCH] qlcnic: fix a memory leak in __qlcnic_pci_sriov_enable()
Posted by Paolo Abeni 11 months, 1 week ago
On 3/5/25 11:18 AM, Haoxiang Li wrote:
> Add qlcnic_sriov_free_vlans() to free the memory allocated by
> qlcnic_sriov_alloc_vlans() if qlcnic_sriov_alloc_vlans() fails.
> 
> Fixes: 60ec7fcfe768 ("qlcnic: potential dereference null pointer of rx_queue->page_ring")
> Cc: stable@vger.kernel.org
> Signed-off-by: Haoxiang Li <haoxiang_li2024@163.com>

I think we are better off addressing the problem in
qlcnic_sriov_alloc_vlans(), so that eventual future callers of such
fuction will not need special handling.

Thanks,

Paolo