Skip to contentSkip to conversation

kvm/kvm_main: Modify the offset type to size_t, which is consistent with the calling function

PATCH In review Li kunyu 2 participants 8 messages Aug 12, 2022 – Aug 19, 2022 KVM

lore
Share & tools
lore

Li kunyu

author
#0 lore raw

PATCH 1/5 kvm/kvm_main: Modify the offset type to size_t, which is consistent with the calling function

The offset variable is called size_t in the calling function. Considering the number of bits in different architectures (32 and 64 represent different types), change it to a consistent variable.

---
 virt/kvm/kvm_main.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
virt/kvm/kvm_main.c +4 -4
index 515dfe9d3bcf..1b9700160eb1 100644
@@ -5526,7 +5526,7 @@ static const struct file_operations stat_fops_per_vm = {
 
 static int vm_stat_get(void *_offset, u64 *val)
 {
-	unsigned offset = (long)_offset;
+	size_t offset = (size_t)_offset;
 	struct kvm *kvm;
 	u64 tmp_val;
 
@@ -5542,7 +5542,7 @@ static int vm_stat_get(void *_offset, u64 *val)
 
 static int vm_stat_clear(void *_offset, u64 val)
 {
-	unsigned offset = (long)_offset;
+	size_t offset = (size_t)_offset;
 	struct kvm *kvm;
 
 	if (val)
@@ -5562,7 +5562,7 @@ DEFINE_SIMPLE_ATTRIBUTE(vm_stat_readonly_fops, vm_stat_get, NULL, "%llu\n");
 
 static int vcpu_stat_get(void *_offset, u64 *val)
 {
-	unsigned offset = (long)_offset;
+	size_t offset = (size_t)_offset;
 	struct kvm *kvm;
 	u64 tmp_val;
 
@@ -5578,7 +5578,7 @@ static int vcpu_stat_get(void *_offset, u64 *val)
 
 static int vcpu_stat_clear(void *_offset, u64 val)
 {
-	unsigned offset = (long)_offset;
+	size_t offset = (size_t)_offset;
 	struct kvm *kvm;
 
 	if (val)
Signature · 1 line
2.18.2
author
#1 lore raw

PATCH 2/5 kvm/kvm_main: remove unnecessary (void*) conversions

remove unnecessary void* type castings.

---
 virt/kvm/kvm_main.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)
virt/kvm/kvm_main.c +5 -7
index 1b9700160eb1..80f7934c1f59 100644
@@ -3839,7 +3839,7 @@ static int create_vcpu_fd(struct kvm_vcpu *vcpu)
 #ifdef __KVM_HAVE_ARCH_VCPU_DEBUGFS
 static int vcpu_get_pid(void *data, u64 *val)
 {
-	struct kvm_vcpu *vcpu = (struct kvm_vcpu *) data;
+	struct kvm_vcpu *vcpu = data;
 	*val = pid_nr(rcu_access_pointer(vcpu->pid));
 	return 0;
 }
@@ -5396,8 +5396,7 @@ static int kvm_debugfs_open(struct inode *inode, struct file *file,
 			   int (*get)(void *, u64 *), int (*set)(void *, u64),
 			   const char *fmt)
 {
-	struct kvm_stat_data *stat_data = (struct kvm_stat_data *)
-					  inode->i_private;
+	struct kvm_stat_data *stat_data = inode->i_private;
 
 	/*
 	 * The debugfs files are a reference to the kvm struct which
@@ -5420,8 +5419,7 @@ static int kvm_debugfs_open(struct inode *inode, struct file *file,
 
 static int kvm_debugfs_release(struct inode *inode, struct file *file)
 {
-	struct kvm_stat_data *stat_data = (struct kvm_stat_data *)
-					  inode->i_private;
+	struct kvm_stat_data *stat_data = inode->i_private;
 
 	simple_attr_release(inode, file);
 	kvm_put_kvm(stat_data->kvm);
@@ -5470,7 +5468,7 @@ static int kvm_clear_stat_per_vcpu(struct kvm *kvm, size_t offset)
 static int kvm_stat_data_get(void *data, u64 *val)
 {
 	int r = -EFAULT;
-	struct kvm_stat_data *stat_data = (struct kvm_stat_data *)data;
+	struct kvm_stat_data *stat_data = data;
 
 	switch (stat_data->kind) {
 	case KVM_STAT_VM:
@@ -5489,7 +5487,7 @@ static int kvm_stat_data_get(void *data, u64 *val)
 static int kvm_stat_data_clear(void *data, u64 val)
 {
 	int r = -EFAULT;
-	struct kvm_stat_data *stat_data = (struct kvm_stat_data *)data;
+	struct kvm_stat_data *stat_data = data;
 
 	if (val)
 		return -EINVAL;
Signature · 1 line
2.18.2
author
#2 lore raw

PATCH 3/5 kvm/kvm_main: The ops pointer variable does not need to be initialized and assigned, it is first allocated a memory address

In reply to Li kunyu

The ops pointer variable does not need to be initialized, because it first allocates a memory address before it is used.

---
 virt/kvm/kvm_main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
virt/kvm/kvm_main.c +1 -1
index 80f7934c1f59..82f2b90718a9 100644
@@ -4378,7 +4378,7 @@ void kvm_unregister_device_ops(u32 type)
 static int kvm_ioctl_create_device(struct kvm *kvm,
 				   struct kvm_create_device *cd)
 {
-	const struct kvm_device_ops *ops = NULL;
+	const struct kvm_device_ops *ops;
 	struct kvm_device *dev;
 	bool test = cd->flags & KVM_CREATE_DEVICE_TEST;
 	int type;
Signature · 1 line
2.18.2
reviewer Reviewed-by on v1 3/5
#3 lore raw

Re: [PATCH 3/5] kvm/kvm_main: The ops pointer variable does not need to be initialized and assigned, it is first allocated a memory address

Needs a proper shortlog.

Quoted 5 lines · Li kunyu

The ops pointer variable does not need to be initialized, because it first allocates a memory address before it is used.

---

Again, with a fixed shortlog,

author
#4 lore raw

PATCH 4/5 kvm/kvm_main: The npages variable does not need to be initialized and assigned, it is used after assignment

In reply to Li kunyu

The npages variable does not need to be initialized and assigned, it is first assigned before it is used.

---
 virt/kvm/kvm_main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
virt/kvm/kvm_main.c +1 -1
index 82f2b90718a9..f047799bf19b 100644
@@ -2516,7 +2516,7 @@ static int hva_to_pfn_slow(unsigned long addr, bool *async, bool write_fault,
 {
 	unsigned int flags = FOLL_HWPOISON;
 	struct page *page;
-	int npages = 0;
+	int npages;
 
 	might_sleep();
 
Signature · 1 line
2.18.2
reviewer Reviewed-by on v1 4/5
#5 lore raw

Re: [PATCH 4/5] kvm/kvm_main: The npages variable does not need to be initialized and assigned, it is used after assignment

Please use "KVM: " for the shortlog scope, and write an actual shortlog. E.g.

KVM: Drop unnecessary initialization of "npages" in hva_to_pfn_slow()

Quoted 5 lines · Li kunyu

The npages variable does not need to be initialized and assigned, it is first assigned before it is used.

---

With a proper shortlog,

author
#6 lore raw

Re: [PATCH 4/5] kvm/kvm_main: The npages variable does not need to be initialized and assigned, it is used after assignment

thanks, re-send these two patches after modification.

author
#7 lore raw

PATCH 5/5 kvm/kvm_main: remove unnecessary (const void*) conversions

In reply to Li kunyu

Casting from a pointer of type void * to a pointer of type const void * does not require a cast.

---
 virt/kvm/kvm_main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
virt/kvm/kvm_main.c +1 -1
index f047799bf19b..01883ecd8cc4 100644
@@ -3278,7 +3278,7 @@ EXPORT_SYMBOL_GPL(kvm_read_guest_cached);
 
 int kvm_clear_guest(struct kvm *kvm, gpa_t gpa, unsigned long len)
 {
-	const void *zero_page = (const void *) __va(page_to_phys(ZERO_PAGE(0)));
+	const void *zero_page = __va(page_to_phys(ZERO_PAGE(0)));
 	gfn_t gfn = gpa >> PAGE_SHIFT;
 	int seg;
 	int offset = offset_in_page(gpa);
Signature · 1 line
2.18.2