Skip to content

Commit

Permalink
KVM: Shove vm stats_id init into kvm_create_vm()
Browse files Browse the repository at this point in the history
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 <[email protected]>
Message-Id: <[email protected]>
Signed-off-by: Paolo Bonzini <[email protected]>
  • Loading branch information
oupton authored and bonzini committed Aug 10, 2022
1 parent 8bad460 commit f2759c0
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions virt/kvm/kvm_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit f2759c0

Please sign in to comment.