Skip to content

Commit 57bdb43

Browse files
Zenghui YuMarc Zyngier
authored andcommitted
KVM: arm64: vgic-its: Fix memory leak on the error path of vgic_add_lpi()
If we're going to fail out the vgic_add_lpi(), let's make sure the allocated vgic_irq memory is also freed. Though it seems that both cases are unlikely to fail. Signed-off-by: Zenghui Yu <[email protected]> Signed-off-by: Marc Zyngier <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 969ce8b commit 57bdb43

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

virt/kvm/arm/vgic/vgic-its.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,21 @@ static struct vgic_irq *vgic_add_lpi(struct kvm *kvm, u32 intid,
9696
* We "cache" the configuration table entries in our struct vgic_irq's.
9797
* However we only have those structs for mapped IRQs, so we read in
9898
* the respective config data from memory here upon mapping the LPI.
99+
*
100+
* Should any of these fail, behave as if we couldn't create the LPI
101+
* by dropping the refcount and returning the error.
99102
*/
100103
ret = update_lpi_config(kvm, irq, NULL, false);
101-
if (ret)
104+
if (ret) {
105+
vgic_put_irq(kvm, irq);
102106
return ERR_PTR(ret);
107+
}
103108

104109
ret = vgic_v3_lpi_sync_pending_status(kvm, irq);
105-
if (ret)
110+
if (ret) {
111+
vgic_put_irq(kvm, irq);
106112
return ERR_PTR(ret);
113+
}
107114

108115
return irq;
109116
}

0 commit comments

Comments
 (0)