[2/2] x86/xen: Fix memory leak in xen_init_lock_cpu()

Message ID 20221119085923.114889-3-xiujianfeng@huawei.com
State New
Headers
Series x86/xen: Fix memory leak issue |

Commit Message

Xiu Jianfeng Nov. 19, 2022, 8:59 a.m. UTC
  In xen_init_lock_cpu(), the @name has allocated new string by kasprintf(),
if bind_ipi_to_irqhandler() fails, it should be freed, otherwise may lead
to a memory leak issue, fix it.

Fixes: 2d9e1e2f58b5 ("xen: implement Xen-specific spinlocks")
Signed-off-by: Xiu Jianfeng <xiujianfeng@huawei.com>
---
 arch/x86/xen/spinlock.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
  

Patch

diff --git a/arch/x86/xen/spinlock.c b/arch/x86/xen/spinlock.c
index 043c73dfd2c9..156d3e04c9ef 100644
--- a/arch/x86/xen/spinlock.c
+++ b/arch/x86/xen/spinlock.c
@@ -86,7 +86,8 @@  void xen_init_lock_cpu(int cpu)
 		disable_irq(irq); /* make sure it's never delivered */
 		per_cpu(lock_kicker_irq, cpu) = irq;
 		per_cpu(irq_name, cpu) = name;
-	}
+	} else
+		kfree(name);
 
 	printk("cpu %d spinlock event irq %d\n", cpu, irq);
 }