From patchwork Tue Jun 13 06:43:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Carpenter X-Patchwork-Id: 13278048 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id EAB7DC7EE29 for ; Tue, 13 Jun 2023 06:44:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-ID:Subject:Cc:To: From:Date:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=qOkEE7MPvNUunX8VrbakNsyJ1aggnFNvGk3yakw+yWk=; b=o/TvFtGIBVqdPF 1S+vTzb5q2tkU6W1BW7TyAdpU9IMlXlgsxJkMcoRVUrs9WM0/g6FafDGjvxpUYuedSebIMT5rZ7Zv pvff7epNi6yA/ybDR38FrvzaB6aGCgcrXQVK7fFIEs1Y2dBNfNOy4/t8czPXdQ69ehCKuDrqqlIgB tuHIX4Det3Ds6Rm146KYhNoSdt6cwVoX4aDSvRFYeXBfOPk9qjGo10K5EGEXWkQ/DqYB0plMQA1S5 VRKo/iV+oq+dr+0Lhd4Uwz0IR3oCwATaJfsqk494XNBiat6NXPJky4oLJInH9EfnJZx7UqI9zsdyR R8aaeInHehL7gg7GXyvQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1q8xkt-0076uI-2V; Tue, 13 Jun 2023 06:43:51 +0000 Received: from mail-lf1-x12d.google.com ([2a00:1450:4864:20::12d]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1q8xkr-0076tM-0f for linux-arm-kernel@lists.infradead.org; Tue, 13 Jun 2023 06:43:50 +0000 Received: by mail-lf1-x12d.google.com with SMTP id 2adb3069b0e04-4f63ea7bfb6so5877890e87.3 for ; Mon, 12 Jun 2023 23:43:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1686638626; x=1689230626; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :from:to:cc:subject:date:message-id:reply-to; bh=WwJ84lVw08wCsE95kQ0UTXAZqJk3Huei6Deabf+TMMI=; b=a8WCsz0oVX69Jbpov+VLq0SWUe+h1mt1pwDO9ey85cvKAGtRk/EdWbadNdyUHMjP37 8roQjrqIOm6+VaSM0cJLF8rgdUFH/Kuk2xKq9noEXAZzETpj1mdARqp/n2JhCrtz6cPg ZI9RwF9Fzk/XZ0shuaPvLK7DlCtU/21OQvGG0+iOKAvEx13PmpSV2T5LRrDohBWLtH+w u4PkaBL75sDY/AEZnRk2F5P2EYdNCu5Fyb2IJ8CNCGb6kv7taTieMNIllOAtqqAa4AUm ZihiA3ojcHPC0oz5zCKqdi2dK8vhA1+O7rjUVUUiMOETGXniNA4f1xiAf8VZsAQL/6qD gt3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686638626; x=1689230626; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=WwJ84lVw08wCsE95kQ0UTXAZqJk3Huei6Deabf+TMMI=; b=OljVtRWvbAcg6TIPE8o+9oendOpkED0Ra3kkRplOuht5ax806rdCBEWphG7mKi6d8n I/0PojDolnmQz7p/RAyyL4H+F+7JgF55lO9f9hmO3ka8APZcanosjrDjORzwXPgZvBBE OUdlTQPFyvy5eBPtHiGcWGGkg7NSdlrWJhqjxP1d+b0APFjM6JQKhFiHW0wwgWOTpTJf djUrKE08NxzCKkORzQRdS/qzQDo+QlgjUzfb23s6ENt+n5t/68KiYXZo2S2wi0QTwQXc I1BNqMH5kMwLJcaj5O63uL0NE6GYmTrOJK131xwK+3XxHYdR13FlYydd101VYtEsPP/r LZZQ== X-Gm-Message-State: AC+VfDzghCwI2pHauIbsoTNMpqCWVws2llibPj5UFzbs8V7QE7L8mDOQ cpCXWqlpgxJjculif0a0hSMCQg== X-Google-Smtp-Source: ACHHUZ49Lblei1XzaLcZJ1ENLHSgfvYbxjwZINob+g4GPuDl/9J8CpY7n6u+x2U4zthUt/Nb0q5T6g== X-Received: by 2002:ac2:465b:0:b0:4f6:4f9a:706e with SMTP id s27-20020ac2465b000000b004f64f9a706emr5685303lfo.15.1686638626525; Mon, 12 Jun 2023 23:43:46 -0700 (PDT) Received: from localhost ([102.36.222.112]) by smtp.gmail.com with ESMTPSA id t25-20020a1c7719000000b003f7eeec829asm13365954wmi.10.2023.06.12.23.43.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Jun 2023 23:43:44 -0700 (PDT) Date: Tue, 13 Jun 2023 09:43:39 +0300 From: Dan Carpenter To: Christoffer Dall Cc: Marc Zyngier , Oliver Upton , James Morse , Suzuki K Poulose , Zenghui Yu , Catalin Marinas , Will Deacon , linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, kernel-janitors@vger.kernel.org Subject: [PATCH v2] KVM: arm64: timers: Fix resource leaks in kvm_timer_hyp_init() Message-ID: <72fffc35-7669-40b1-9d14-113c43269cf3@kili.mountain> MIME-Version: 1.0 Content-Disposition: inline X-Mailer: git-send-email haha only kidding X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230612_234349_245633_2D334547 X-CRM114-Status: GOOD ( 12.62 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 --- 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; }