* [PATCH v2] KVM: arm64: timers: Fix resource leaks in kvm_timer_hyp_init()
@ 2023-06-13 6:43 Dan Carpenter
2023-06-13 12:16 ` Oliver Upton
0 siblings, 1 reply; 2+ messages in thread
From: Dan Carpenter @ 2023-06-13 6:43 UTC (permalink / raw)
To: Christoffer Dall
Cc: Marc Zyngier, Oliver Upton, James Morse, Suzuki K Poulose,
Zenghui Yu, Catalin Marinas, Will Deacon, linux-arm-kernel,
kvmarm, kernel-janitors
Smatch detected this bug:
arch/arm64/kvm/arch_timer.c:1425 kvm_timer_hyp_init()
warn: missing unwind goto?
There are two resources to be freed the vtimer and ptimer. The
line that Smatch complains about should free the vtimer first
before returning and then after that cleanup code should free
the ptimer.
I've added a out_free_ptimer_irq to free the ptimer and renamed
the existing label to out_free_vtimer_irq.
Fixes: 9e01dc76be6a ("KVM: arm/arm64: arch_timer: Assign the phys timer on VHE systems")
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
---
v2: renamed the label as Oliver Upton requested.
arch/arm64/kvm/arch_timer.c | 14 +++++++++-----
1 file changed, 9 insertions(+), 5 deletions(-)
diff --git a/arch/arm64/kvm/arch_timer.c b/arch/arm64/kvm/arch_timer.c
index 05b022be885b..0696732fa38c 100644
--- a/arch/arm64/kvm/arch_timer.c
+++ b/arch/arm64/kvm/arch_timer.c
@@ -1406,7 +1406,7 @@ int __init kvm_timer_hyp_init(bool has_gic)
kvm_get_running_vcpus());
if (err) {
kvm_err("kvm_arch_timer: error setting vcpu affinity\n");
- goto out_free_irq;
+ goto out_free_vtimer_irq;
}
static_branch_enable(&has_gic_active_state);
@@ -1422,7 +1422,7 @@ int __init kvm_timer_hyp_init(bool has_gic)
if (err) {
kvm_err("kvm_arch_timer: can't request ptimer interrupt %d (%d)\n",
host_ptimer_irq, err);
- return err;
+ goto out_free_vtimer_irq;
}
if (has_gic) {
@@ -1430,7 +1430,7 @@ int __init kvm_timer_hyp_init(bool has_gic)
kvm_get_running_vcpus());
if (err) {
kvm_err("kvm_arch_timer: error setting vcpu affinity\n");
- goto out_free_irq;
+ goto out_free_ptimer_irq;
}
}
@@ -1439,11 +1439,15 @@ int __init kvm_timer_hyp_init(bool has_gic)
kvm_err("kvm_arch_timer: invalid physical timer IRQ: %d\n",
info->physical_irq);
err = -ENODEV;
- goto out_free_irq;
+ goto out_free_vtimer_irq;
}
return 0;
-out_free_irq:
+
+out_free_ptimer_irq:
+ if (info->physical_irq > 0)
+ free_percpu_irq(host_ptimer_irq, kvm_get_running_vcpus());
+out_free_vtimer_irq:
free_percpu_irq(host_vtimer_irq, kvm_get_running_vcpus());
return err;
}
--
2.39.2
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v2] KVM: arm64: timers: Fix resource leaks in kvm_timer_hyp_init()
2023-06-13 6:43 [PATCH v2] KVM: arm64: timers: Fix resource leaks in kvm_timer_hyp_init() Dan Carpenter
@ 2023-06-13 12:16 ` Oliver Upton
0 siblings, 0 replies; 2+ messages in thread
From: Oliver Upton @ 2023-06-13 12:16 UTC (permalink / raw)
To: Dan Carpenter, Christoffer Dall
Cc: Oliver Upton, Will Deacon, Marc Zyngier, kernel-janitors, kvmarm,
Catalin Marinas, Zenghui Yu, James Morse, Suzuki K Poulose,
linux-arm-kernel
On Tue, 13 Jun 2023 09:43:39 +0300, Dan Carpenter wrote:
> Smatch detected this bug:
> arch/arm64/kvm/arch_timer.c:1425 kvm_timer_hyp_init()
> warn: missing unwind goto?
>
> There are two resources to be freed the vtimer and ptimer. The
> line that Smatch complains about should free the vtimer first
> before returning and then after that cleanup code should free
> the ptimer.
>
> [...]
Applied to kvmarm/next, thanks!
[1/1] KVM: arm64: timers: Fix resource leaks in kvm_timer_hyp_init()
https://git.kernel.org/kvmarm/kvmarm/c/21e87daece5a
--
Best,
Oliver
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-06-13 12:16 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-06-13 6:43 [PATCH v2] KVM: arm64: timers: Fix resource leaks in kvm_timer_hyp_init() Dan Carpenter
2023-06-13 12:16 ` Oliver Upton
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox