diff mbox series

[v3,1/6] KVM: Shove vm stats_id init into kvm_create_vm()

Message ID 20220720092259.3491733-2-oliver.upton@linux.dev (mailing list archive)
State New, archived
Headers show
Series KVM: Clean up debugfs init/destroy | expand

Commit Message

Oliver Upton July 20, 2022, 9:22 a.m. UTC
From: Oliver Upton <oupton@google.com>

Initialize stats_id alongside the other struct kvm fields to futureproof
against possible initialization order mistakes in KVM. 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>
---
 virt/kvm/kvm_main.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Comments

Sean Christopherson Aug. 5, 2022, 7:09 p.m. UTC | #1
On Wed, Jul 20, 2022, Oliver Upton wrote:
> From: Oliver Upton <oupton@google.com>
> 
> Initialize stats_id alongside the other struct kvm fields to futureproof
> against possible initialization order mistakes in KVM.

Same nit about handwaving.  Maybe it's just me, but even though I already know
what this patch is doing, this changelog still somehow leaves me wondering what
"possible initialization order mistakes" this prevents.

> 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>
> ---

Reviewed-by: Sean Christopherson <seanjc@google.com>
diff mbox series

Patch

diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index da263c370d00..cc760ebcd390 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -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);