Skip to content

Commit 21e87da

Browse files
Dan Carpenteroupton
authored andcommitted
KVM: arm64: timers: Fix resource leaks in kvm_timer_hyp_init()
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: 9e01dc7 ("KVM: arm/arm64: arch_timer: Assign the phys timer on VHE systems") Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org> Link: https://lore.kernel.org/r/72fffc35-7669-40b1-9d14-113c43269cf3@kili.mountain Signed-off-by: Oliver Upton <oliver.upton@linux.dev>
1 parent b53d4a2 commit 21e87da

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

arch/arm64/kvm/arch_timer.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1406,7 +1406,7 @@ int __init kvm_timer_hyp_init(bool has_gic)
14061406
kvm_get_running_vcpus());
14071407
if (err) {
14081408
kvm_err("kvm_arch_timer: error setting vcpu affinity\n");
1409-
goto out_free_irq;
1409+
goto out_free_vtimer_irq;
14101410
}
14111411

14121412
static_branch_enable(&has_gic_active_state);
@@ -1422,15 +1422,15 @@ int __init kvm_timer_hyp_init(bool has_gic)
14221422
if (err) {
14231423
kvm_err("kvm_arch_timer: can't request ptimer interrupt %d (%d)\n",
14241424
host_ptimer_irq, err);
1425-
return err;
1425+
goto out_free_vtimer_irq;
14261426
}
14271427

14281428
if (has_gic) {
14291429
err = irq_set_vcpu_affinity(host_ptimer_irq,
14301430
kvm_get_running_vcpus());
14311431
if (err) {
14321432
kvm_err("kvm_arch_timer: error setting vcpu affinity\n");
1433-
goto out_free_irq;
1433+
goto out_free_ptimer_irq;
14341434
}
14351435
}
14361436

@@ -1439,11 +1439,15 @@ int __init kvm_timer_hyp_init(bool has_gic)
14391439
kvm_err("kvm_arch_timer: invalid physical timer IRQ: %d\n",
14401440
info->physical_irq);
14411441
err = -ENODEV;
1442-
goto out_free_irq;
1442+
goto out_free_vtimer_irq;
14431443
}
14441444

14451445
return 0;
1446-
out_free_irq:
1446+
1447+
out_free_ptimer_irq:
1448+
if (info->physical_irq > 0)
1449+
free_percpu_irq(host_ptimer_irq, kvm_get_running_vcpus());
1450+
out_free_vtimer_irq:
14471451
free_percpu_irq(host_vtimer_irq, kvm_get_running_vcpus());
14481452
return err;
14491453
}

0 commit comments

Comments
 (0)