aboutsummaryrefslogtreecommitdiff
path: root/arch/x86/kvm/debugfs.c
diff options
context:
space:
mode:
authorHou Wenlong2022-10-14 15:55:11 +0800
committerPaolo Bonzini2022-10-27 04:41:54 -0400
commit5aa02366773376a1fd3a5c6a815e5f6e026ab391 (patch)
tree31bdbb0d36548f7fe84e6062f27c0e7de0f09a88 /arch/x86/kvm/debugfs.c
parent86c4f0d547f6460d0426ebb3ba0614f1134b8cda (diff)
KVM: x86: Reduce refcount if single_open() fails in kvm_mmu_rmaps_stat_open()
Refcount is increased before calling single_open() in kvm_mmu_rmaps_stat_open(), If single_open() fails, refcount should be restored, otherwise the vm couldn't be destroyed. Fixes: 3bcd0662d66fd ("KVM: X86: Introduce mmu_rmaps_stat per-vm debugfs file") Signed-off-by: Hou Wenlong <houwenlong.hwl@antgroup.com> Message-Id: <a75900413bb8b1e556be690e9588a0f92e946a30.1665733883.git.houwenlong.hwl@antgroup.com> [Preserved return value of single_open. - Paolo] Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'arch/x86/kvm/debugfs.c')
-rw-r--r--arch/x86/kvm/debugfs.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/arch/x86/kvm/debugfs.c b/arch/x86/kvm/debugfs.c
index cfed36aba2f7..c1390357126a 100644
--- a/arch/x86/kvm/debugfs.c
+++ b/arch/x86/kvm/debugfs.c
@@ -158,11 +158,16 @@ out:
static int kvm_mmu_rmaps_stat_open(struct inode *inode, struct file *file)
{
struct kvm *kvm = inode->i_private;
+ int r;
if (!kvm_get_kvm_safe(kvm))
return -ENOENT;
- return single_open(file, kvm_mmu_rmaps_stat_show, kvm);
+ r = single_open(file, kvm_mmu_rmaps_stat_show, kvm);
+ if (r < 0)
+ kvm_put_kvm(kvm);
+
+ return r;
}
static int kvm_mmu_rmaps_stat_release(struct inode *inode, struct file *file)