Skip to contentSkip to conversation

KVM: Add the check and free to avoid unknown errors.

PATCH In review Haiwei Li 2 participants 2 messages Feb 14, 2020 – Feb 17, 2020 KVM

lore
Share & tools
lore

Haiwei Li

author
#0 lore raw

PATCH 1/1 KVM: Add the check and free to avoid unknown errors.

From: Haiwei Li <[email protected]>

If 'kvm_create_vm_debugfs()' fails in 'kzalloc(sizeof(*stat_data), ...)', 'kvm_destroy_vm_debugfs()' will be called by the final fput(file) in 'kvm_dev_ioctl_create_vm()'.

Add the check and free to avoid unknown errors.

---
 virt/kvm/kvm_main.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
virt/kvm/kvm_main.c +4 -1
index 67ae2d5..18a32e1 100644
@@ -617,8 +617,11 @@ static void kvm_destroy_vm_debugfs(struct kvm *kvm)
 	debugfs_remove_recursive(kvm->debugfs_dentry);
 
 	if (kvm->debugfs_stat_data) {
-		for (i = 0; i < kvm_debugfs_num_entries; i++)
+		for (i = 0; i < kvm_debugfs_num_entries; i++) {
+			if (!kvm->debugfs_stat_data[i])
+				break;
 			kfree(kvm->debugfs_stat_data[i]);
+		}
 		kfree(kvm->debugfs_stat_data);
 	}
 }

--
1.8.3.1

maintainer
#1 lore raw
Quoted 5 lines · Haiwei Li

From: Haiwei Li <[email protected]>

If 'kvm_create_vm_debugfs()' fails in 'kzalloc(sizeof(*stat_data), ...)', 'kvm_destroy_vm_debugfs()' will be called by the final fput(file) in 'kvm_dev_ioctl_create_vm()'.

Can you explain better? It is okay to pass NULL to kfree.

Paolo

Quoted 27 lines

Add the check and free to avoid unknown errors.

---
 virt/kvm/kvm_main.c | 5 ++++-

 1 file changed, 4 insertions(+), 1 deletion(-)
virt/kvm/kvm_main.c +4 -1
index 67ae2d5..18a32e1 100644
@@ -617,8 +617,11 @@ static void kvm_destroy_vm_debugfs(struct kvm *kvm)
      debugfs_remove_recursive(kvm->debugfs_dentry);
 
      if (kvm->debugfs_stat_data) {
-        for (i = 0; i < kvm_debugfs_num_entries; i++)
+        for (i = 0; i < kvm_debugfs_num_entries; i++) {
+            if (!kvm->debugfs_stat_data[i])
+                break;
              kfree(kvm->debugfs_stat_data[i]);
+        }
          kfree(kvm->debugfs_stat_data);
      }
  }
Signature · 1 line
1.8.3.1