]> git.baikalelectronics.ru Git - kernel.git/commitdiff
KVM: Shove vm stats_id init into kvm_create_vm()
authorOliver Upton <oupton@google.com>
Wed, 20 Jul 2022 09:22:47 +0000 (09:22 +0000)
committerPaolo Bonzini <pbonzini@redhat.com>
Wed, 10 Aug 2022 19:08:27 +0000 (15:08 -0400)
Initialize stats_id alongside other struct kvm fields to make it more
difficult to unintentionally access stats_id before it's set.  While at
it, move the format string to the first line of the call and fix the
indentation of the second line.

No functional change intended.

Signed-off-by: Oliver Upton <oupton@google.com>
Message-Id: <20220720092259.3491733-2-oliver.upton@linux.dev>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
virt/kvm/kvm_main.c

index 32896c845ffe20efc98d3fcc93708a0d6915f6b4..8230f22cc01c725169026f795661a0a8e27cd674 100644 (file)
@@ -1155,6 +1155,9 @@ static struct kvm *kvm_create_vm(unsigned long type)
         */
        kvm->debugfs_dentry = ERR_PTR(-ENOENT);
 
+       snprintf(kvm->stats_id, sizeof(kvm->stats_id), "kvm-%d",
+                task_pid_nr(current));
+
        if (init_srcu_struct(&kvm->srcu))
                goto out_err_no_srcu;
        if (init_srcu_struct(&kvm->irq_srcu))
@@ -4902,9 +4905,6 @@ static int kvm_dev_ioctl_create_vm(unsigned long type)
        if (r < 0)
                goto put_kvm;
 
-       snprintf(kvm->stats_id, sizeof(kvm->stats_id),
-                       "kvm-%d", task_pid_nr(current));
-
        file = anon_inode_getfile("kvm-vm", &kvm_vm_fops, kvm, O_RDWR);
        if (IS_ERR(file)) {
                put_unused_fd(r);