Skip to contentSkip to conversation

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

PATCH linmiaohe 2 participants 2 messages Feb 15, 2020 KVM

lore
Share & tools
lore

linmiaohe

author
#0 lore raw

Hi:

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()'.

Add the check and free to avoid unknown errors.

Add the check and free? According to the code,it seem what you mean is "add the check against free" ?

Review

Quoted 13 lines
  	if (kvm->debugfs_stat_data) {
(quoted diff) +4 -1
-		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);
  	}
  }

If (!kvm->debugfs_stat_data[i]) is checked in kfree() internal. And break early seems have no different effect. Could you please explain what unknown errors may occur? And how? Thanks.

#1 lore raw
Quoted 10 lines · linmiaohe <[email protected]> 于2020年2月15日周六 上午10:00写道:

Hi:

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()'.

Add the check and free to avoid unknown errors.

Add the check and free? According to the code,it seem what you mean is "add the check against free" ?

Right, i can change the description.

Quoted 15 lines
Quoted 5 lines
      if (kvm->debugfs_stat_data) {

Review

Quoted 9 lines
(quoted diff) +4 -1
-             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);
      }
  }
Quoted 2 lines

If (!kvm->debugfs_stat_data[i]) is checked in kfree() internal. And break early seems have no different effect. Could you please explain what unknown errors may occur? And how? Thanks.

I get the free() code. It is just like what you said. Thanks a lot. Break early is useful. If kvm->debugfs_stat_data[i] is null, breaking early can reduce the check.

Quoted 1 line