idpf_vport_intr_req_irq() allocates a name for each vector IRQ before
calling request_irq(). On success, the name is released later through
kfree(free_irq()), but when request_irq() fails, the error path only
unwinds the previous vectors and the name for the failed one is leaked.

Free the allocated name on the request_irq() failure path, as done for
the mailbox IRQ in commit 9bff30482c10 ("idpf: Fix mailbox IRQ name leak
on request failure"). While at it, fail with -ENOMEM when the name
cannot be allocated instead of requesting the IRQ without a name.

Fixes: d4d558718266 ("idpf: initialize interrupts and enable vport")
Signed-off-by: Yuho Choi <[email protected]>
---
Changes in v2:
- Correct the Fixes: tag (Simon Horman)
- Handle kasprintf() failure (Simon Horman)

v1: https://lore.kernel.org/all/[email protected]/

Compile-tested only (x86_64 defconfig + CONFIG_IDPF=m, W=1).

 drivers/net/ethernet/intel/idpf/idpf_txrx.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/net/ethernet/intel/idpf/idpf_txrx.c 
b/drivers/net/ethernet/intel/idpf/idpf_txrx.c
index 4311ffa30bb1..af3213eae393 100644
--- a/drivers/net/ethernet/intel/idpf/idpf_txrx.c
+++ b/drivers/net/ethernet/intel/idpf/idpf_txrx.c
@@ -4067,12 +4067,17 @@ static int idpf_vport_intr_req_irq(struct idpf_vport 
*vport,
 
                name = kasprintf(GFP_KERNEL, "%s-%s-%s-%d", drv_name, if_name,
                                 vec_name, vector);
+               if (!name) {
+                       err = -ENOMEM;
+                       goto free_q_irqs;
+               }
 
                err = request_irq(irq_num, idpf_vport_intr_clean_queues, 0,
                                  name, q_vector);
                if (err) {
                        netdev_err(vport->netdev,
                                   "Request_irq failed, error: %d\n", err);
+                       kfree(name);
                        goto free_q_irqs;
                }
 

base-commit: 551c722f40809618230001baccf219193e22fc5a
-- 
2.43.0

Reply via email to