public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Mostafa Saleh <smostafa@google.com>
To: kvm@vger.kernel.org, will@kernel.org, julien.thierry.kdev@gmail.com
Cc: Mostafa Saleh <smostafa@google.com>
Subject: [PATCH kvmtool] arm: Initialize target in kvm_cpu__arch_init
Date: Wed, 27 Sep 2023 11:21:17 +0000	[thread overview]
Message-ID: <20230927112117.3935537-1-smostafa@google.com> (raw)

After updating my toolchain to:
aarch64-linux-gnu-gcc (Debian 13.2.0-2) 13.2.0

I hit compilation error:
arm/kvm-cpu.c: In function ‘kvm_cpu__arch_init’:
arm/kvm-cpu.c:119:41: error: ‘target’ may be used uninitialized [-Werror=maybe-uninitialized]
  119 |         vcpu->cpu_compatible    = target->compatible;
      |                                   ~~~~~~^~~~~~~~~~~~
arm/kvm-cpu.c:40:32: note: ‘target’ was declared here
   40 |         struct kvm_arm_target *target;
      |                                ^~~~~~

target is guaranteed to be initialized, as targets would be registered
from other compilation units (arm/aarch(32|64)/arm-cpu.c).

Initializing the variable to NULL is sufficient to silence the compiler.

Signed-off-by: Mostafa Saleh <smostafa@google.com>
---
 arm/kvm-cpu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arm/kvm-cpu.c b/arm/kvm-cpu.c
index 98bc5fd..57f92ee 100644
--- a/arm/kvm-cpu.c
+++ b/arm/kvm-cpu.c
@@ -37,7 +37,7 @@ int kvm_cpu__register_kvm_arm_target(struct kvm_arm_target *target)
 
 struct kvm_cpu *kvm_cpu__arch_init(struct kvm *kvm, unsigned long cpu_id)
 {
-	struct kvm_arm_target *target;
+	struct kvm_arm_target *target = NULL;
 	struct kvm_cpu *vcpu;
 	int coalesced_offset, mmap_size, err = -1;
 	unsigned int i;
-- 
2.42.0.582.g8ccd20d70d-goog


             reply	other threads:[~2023-09-27 11:21 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-27 11:21 Mostafa Saleh [this message]
2023-09-27 12:21 ` [PATCH kvmtool] arm: Initialize target in kvm_cpu__arch_init Zenghui Yu
2023-09-27 12:31   ` Mostafa Saleh

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230927112117.3935537-1-smostafa@google.com \
    --to=smostafa@google.com \
    --cc=julien.thierry.kdev@gmail.com \
    --cc=kvm@vger.kernel.org \
    --cc=will@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox