2022-08-12 10:23:09

by Li kunyu

[permalink] [raw]
Subject: [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.

Signed-off-by: Li kunyu <[email protected]>
---
virt/kvm/kvm_main.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index 515dfe9d3bcf..1b9700160eb1 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -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)
--
2.18.2


2022-08-12 10:27:16

by Li kunyu

[permalink] [raw]
Subject: [PATCH 2/5] kvm/kvm_main: remove unnecessary (void*) conversions

remove unnecessary void* type castings.

Signed-off-by: Li kunyu <[email protected]>
---
virt/kvm/kvm_main.c | 12 +++++-------
1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index 1b9700160eb1..80f7934c1f59 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -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;
--
2.18.2

2022-08-12 10:49:08

by Li kunyu

[permalink] [raw]
Subject: [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

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

Signed-off-by: Li kunyu <[email protected]>
---
virt/kvm/kvm_main.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index 80f7934c1f59..82f2b90718a9 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -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;
--
2.18.2

2022-08-12 10:54:37

by Li kunyu

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

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

Signed-off-by: Li kunyu <[email protected]>
---
virt/kvm/kvm_main.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index 82f2b90718a9..f047799bf19b 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -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();

--
2.18.2

2022-08-12 10:57:00

by Li kunyu

[permalink] [raw]
Subject: [PATCH 5/5] kvm/kvm_main: remove unnecessary (const void*) conversions

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

Signed-off-by: Li kunyu <[email protected]>
---
virt/kvm/kvm_main.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index f047799bf19b..01883ecd8cc4 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -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);
--
2.18.2

2022-08-19 00:09:27

by Sean Christopherson

[permalink] [raw]
Subject: 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.

On Fri, Aug 12, 2022, Li kunyu wrote:
> The ops pointer variable does not need to be initialized, because it
> first allocates a memory address before it is used.
>
> Signed-off-by: Li kunyu <[email protected]>
> ---

Again, with a fixed shortlog,

Reviewed-by: Sean Christopherson <[email protected]>

2022-08-19 00:21:41

by Sean Christopherson

[permalink] [raw]
Subject: 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()

On Fri, Aug 12, 2022, Li kunyu wrote:
> The npages variable does not need to be initialized and assigned, it is
> first assigned before it is used.
>
> Signed-off-by: Li kunyu <[email protected]>
> ---

With a proper shortlog,

Reviewed-by: Sean Christopherson <[email protected]>