xen/x86: Remove unnecessary cast on void pointer
PATCH v2 1/1 xen/x86: Remove unnecessary cast on void pointer
Assignment to a typed pointer is sufficient in C.
No cast is needed.
Also, changed some u64/u32 to uint64_t/uint32_t.
---
Changes in v2:
- Took the chance to change some uintX to uintX_t.
xen/arch/x86/acpi/cpufreq/powernow.c | 2 +- xen/arch/x86/cpu/vpmu.c | 2 +- xen/arch/x86/hpet.c | 2 +- xen/arch/x86/hvm/save.c | 2 +- xen/arch/x86/hvm/vmx/vvmx.c | 12 ++++++------ 5 files changed, 10 insertions(+), 10 deletions(-)
xen/arch/x86/acpi/cpufreq/powernow.c +1 -1
@@ -58,7 +58,7 @@ static void transition_pstate(void *pstate)static void update_cpb (void *data) { -struct cpufreq_policy *policy = (struct cpufreq_policy *)data; +struct cpufreq_policy *policy = data;if (policy->turbo !=CPUFREQ_TURBO_UNSUPPORTED ) {uint64_t msr_content;
xen/arch/x86/cpu/vpmu.c +1 -1
@@ -337,7 +337,7 @@ void vpmu_do_interrupt(struct cpu_user_regs *regs)static void vpmu_save_force (void *arg) { -struct vcpu *v = (struct vcpu *)arg; +struct vcpu *v = arg;struct vpmu_struct *vpmu =vcpu_vpmu (v);if ( !vpmu_is_set (vpmu,VPMU_CONTEXT_LOADED ) )
xen/arch/x86/hpet.c +1 -1
@@ -215,7 +215,7 @@ again:static void hpet_interrupt_handler (int irq,void *data,struct cpu_user_regs *regs) { -struct hpet_event_channel *ch = (struct hpet_event_channel *)data; +struct hpet_event_channel *ch = data;this_cpu (irq_count)--;
xen/arch/x86/hvm/save.c +1 -1
@@ -417,7 +417,7 @@ void _hvm_read_entry(struct hvm_domain_context *h, void *dest,memcpy (dest, &h->data[h->cur], d->length);if ( d->length < dest_len ) -memset ((char *)dest + d->length,0 , dest_len - d->length); +memset (dest + d->length,0 , dest_len - d->length); h->cur += d->length; }
xen/arch/x86/hvm/vmx/vvmx.c +6 -6
@@ -253,12 +253,12 @@ static int vvmcs_offset(u32 width, u32 type, u32 index)return offset; } -u64 get_vvmcs_virtual (void *vvmcs,u32 vmcs_encoding) +uint64_t get_vvmcs_virtual (void *vvmcs,uint32_t vmcs_encoding) {union vmcs_encoding enc; -u64 *content = (u64 *) vvmcs; +uint64_t *content = vvmcs;int offset; -u64 res; +uint64_t res; enc.word = vmcs_encoding; offset =vvmcs_offset (enc.width, enc.type, enc.index);
@@ -307,12 +307,12 @@ enum vmx_insn_errno get_vvmcs_real_safe(const struct vcpu *v, u32 encoding,return virtual_vmcs_vmread_safe (v, encoding, val); } -void set_vvmcs_virtual (void *vvmcs,u32 vmcs_encoding,u64 val) +void set_vvmcs_virtual (void *vvmcs,uint32_t vmcs_encoding,uint64_t val) {union vmcs_encoding enc; -u64 *content = (u64 *) vvmcs; +uint64_t *content = vvmcs;int offset; -u64 res; +uint64_t res; enc.word = vmcs_encoding; offset =vvmcs_offset (enc.width, enc.type, enc.index);
Signature · 1 line
2.17.1
Quoted 61 lines · Simran Singhal
Assignment to a typed pointer is sufficient in C.
No cast is needed.Also, changed some u64/u32 to uint64_t/uint32_t.
Signed-off-by Simran Singhal <[email protected]>---
Changes in v2:
- Took the chance to change some uintX touintX_t.xen/arch/x86/acpi/cpufreq/powernow.c | 2 +- xen/arch/x86/cpu/vpmu.c | 2 +- xen/arch/x86/hpet.c | 2 +- xen/arch/x86/hvm/save.c | 2 +- xen/arch/x86/hvm/vmx/vvmx.c | 12 ++++++------ 5 files changed, 10 insertions(+), 10 deletions(-)xen/arch/x86/acpi/cpufreq/powernow.c +1
-1@@ -58,7 +58,7 @@ static void transition_pstate(void *pstate)static void update_cpb (void *data) { -struct cpufreq_policy *policy = (struct cpufreq_policy *)data; +struct cpufreq_policy *policy = data;if (policy->turbo !=CPUFREQ_TURBO_UNSUPPORTED ) {uint64_t msr_content;xen/arch/x86/cpu/vpmu.c +1
-1@@ -337,7 +337,7 @@ void vpmu_do_interrupt(struct cpu_user_regs *regs)static void vpmu_save_force (void *arg) { -struct vcpu *v = (struct vcpu *)arg; +struct vcpu *v = arg;struct vpmu_struct *vpmu =vcpu_vpmu (v);if ( !vpmu_is_set (vpmu,VPMU_CONTEXT_LOADED ) )xen/arch/x86/hpet.c +1
-1@@ -215,7 +215,7 @@ again:static void hpet_interrupt_handler (int irq,void *data,struct cpu_user_regs *regs) { -struct hpet_event_channel *ch = (struct hpet_event_channel *)data; +struct hpet_event_channel *ch = data;this_cpu (irq_count)--;xen/arch/x86/hvm/save.c +0
-0
xen/arch/x86/hvm/save.c void _hvm_read_entry(struct hvm_domain_context *h, void *dest, · line 420
Quoted 5 lines
xen/arch/x86/hvm/save.c +1
-1@@ -417,7 +417,7 @@ void _hvm_read_entry(struct hvm_domain_context *h, void *dest,memcpy (dest, &h->data[h->cur], d->length);if ( d->length < dest_len ) -memset ((char *)dest + d->length,0 , dest_len - d->length); +memset (dest + d->length,0 , dest_len - d->length);
I believe you shouldn't drop the cast here either because dest is of type void*.
Although the calculation in the end is the same (void* considered of size 1), I would still keep the cast such that the semantics is correct.
Wei.
Quoted 71 lines · Wei Liu
Quoted 61 lines · Simran Singhal
Assignment to a typed pointer is sufficient in C.
No cast is needed.Also, changed some u64/u32 to uint64_t/uint32_t.
Signed-off-by Simran Singhal <[email protected]>---
Changes in v2:
- Took the chance to change some uintX touintX_t.xen/arch/x86/acpi/cpufreq/powernow.c | 2 +- xen/arch/x86/cpu/vpmu.c | 2 +- xen/arch/x86/hpet.c | 2 +- xen/arch/x86/hvm/save.c | 2 +- xen/arch/x86/hvm/vmx/vvmx.c | 12 ++++++------ 5 files changed, 10 insertions(+), 10 deletions(-)xen/arch/x86/acpi/cpufreq/powernow.c +1
-1@@ -58,7 +58,7 @@ static void transition_pstate(void *pstate)static void update_cpb (void *data) { -struct cpufreq_policy *policy = (struct cpufreq_policy *)data; +struct cpufreq_policy *policy = data;if (policy->turbo !=CPUFREQ_TURBO_UNSUPPORTED ) {uint64_t msr_content;xen/arch/x86/cpu/vpmu.c +1
-1@@ -337,7 +337,7 @@ void vpmu_do_interrupt(struct cpu_user_regs *regs)static void vpmu_save_force (void *arg) { -struct vcpu *v = (struct vcpu *)arg; +struct vcpu *v = arg;struct vpmu_struct *vpmu =vcpu_vpmu (v);if ( !vpmu_is_set (vpmu,VPMU_CONTEXT_LOADED ) )xen/arch/x86/hpet.c +1
-1@@ -215,7 +215,7 @@ again:static void hpet_interrupt_handler (int irq,void *data,struct cpu_user_regs *regs) { -struct hpet_event_channel *ch = (struct hpet_event_channel *)data; +struct hpet_event_channel *ch = data;this_cpu (irq_count)--;xen/arch/x86/hvm/save.c +0
-0xen/arch/x86/hvm/save.c void _hvm_read_entry(struct hvm_domain_context *h, void *dest, · line 420
Quoted 5 lines
xen/arch/x86/hvm/save.c +1
-1@@ -417,7 +417,7 @@ void _hvm_read_entry(struct hvm_domain_context *h, void *dest,memcpy (dest, &h->data[h->cur], d->length);if ( d->length < dest_len ) -memset ((char *)dest + d->length,0 , dest_len - d->length); +memset (dest + d->length,0 , dest_len - d->length);I believe you shouldn't drop the cast here either because dest is of type void*.
Quoted 2 lines
Although the calculation in the end is the same (void* considered of size 1), I would still keep the cast such that the semantics is correct.
IMO dropping the case here is fine, as dest is of type void * the calculation is correct and the cast just obfuscates it.
I usually cast things to void * instead of char * or uint8_t * in order to do pointer additions with size 1.
Thanks, Roger.
Quoted 72 lines · Roger Pau Monné
Quoted 71 lines · Wei Liu
Quoted 61 lines · Simran Singhal
Assignment to a typed pointer is sufficient in C.
No cast is needed.Also, changed some u64/u32 to uint64_t/uint32_t.
Signed-off-by Simran Singhal <[email protected]>---
Changes in v2:
- Took the chance to change some uintX touintX_t.xen/arch/x86/acpi/cpufreq/powernow.c | 2 +- xen/arch/x86/cpu/vpmu.c | 2 +- xen/arch/x86/hpet.c | 2 +- xen/arch/x86/hvm/save.c | 2 +- xen/arch/x86/hvm/vmx/vvmx.c | 12 ++++++------ 5 files changed, 10 insertions(+), 10 deletions(-)xen/arch/x86/acpi/cpufreq/powernow.c +1
-1@@ -58,7 +58,7 @@ static void transition_pstate(void *pstate)static void update_cpb (void *data) { -struct cpufreq_policy *policy = (struct cpufreq_policy *)data; +struct cpufreq_policy *policy = data;if (policy->turbo !=CPUFREQ_TURBO_UNSUPPORTED ) {uint64_t msr_content;xen/arch/x86/cpu/vpmu.c +1
-1@@ -337,7 +337,7 @@ void vpmu_do_interrupt(struct cpu_user_regs *regs)static void vpmu_save_force (void *arg) { -struct vcpu *v = (struct vcpu *)arg; +struct vcpu *v = arg;struct vpmu_struct *vpmu =vcpu_vpmu (v);if ( !vpmu_is_set (vpmu,VPMU_CONTEXT_LOADED ) )xen/arch/x86/hpet.c +1
-1@@ -215,7 +215,7 @@ again:static void hpet_interrupt_handler (int irq,void *data,struct cpu_user_regs *regs) { -struct hpet_event_channel *ch = (struct hpet_event_channel *)data; +struct hpet_event_channel *ch = data;this_cpu (irq_count)--;xen/arch/x86/hvm/save.c +0
-0xen/arch/x86/hvm/save.c void _hvm_read_entry(struct hvm_domain_context *h, void *dest, · line 420
Quoted 5 lines
xen/arch/x86/hvm/save.c +1
-1@@ -417,7 +417,7 @@ void _hvm_read_entry(struct hvm_domain_context *h, void *dest,memcpy (dest, &h->data[h->cur], d->length);if ( d->length < dest_len ) -memset ((char *)dest + d->length,0 , dest_len - d->length); +memset (dest + d->length,0 , dest_len - d->length);I believe you shouldn't drop the cast here either because dest is of type void*.
Quoted 5 lines
Quoted 2 lines
Although the calculation in the end is the same (void* considered of size 1), I would still keep the cast such that the semantics is correct.
IMO dropping the case here is fine, as dest is of type void * the calculation is correct and the cast just obfuscates it.
+1
Jan
Quoted 23 lines · Simran Singhal
xen/arch/x86/hvm/vmx/vvmx.c +3
-3@@ -253,12 +253,12 @@ static int vvmcs_offset(u32 width, u32 type, u32 index)return offset; } -u64 get_vvmcs_virtual (void *vvmcs,u32 vmcs_encoding) +uint64_t get_vvmcs_virtual (void *vvmcs,uint32_t vmcs_encoding) {union vmcs_encoding enc; -u64 *content = (u64 *) vvmcs; +uint64_t *content = vvmcs;int offset; -u64 res; +uint64_t res; enc.word = vmcs_encoding; offset =vvmcs_offset (enc.width, enc.type, enc.index);@@ -307,12 +307,12 @@ enum vmx_insn_errno get_vvmcs_real_safe(const struct vcpu *v, u32 encoding,return virtual_vmcs_vmread_safe (v, encoding, val); }
xen/arch/x86/hvm/vmx/vvmx.c enum vmx_insn_errno get_vvmcs_real_safe(const struct vcpu *v, u32 encoding, · line 315
Quoted 10 lines
xen/arch/x86/hvm/vmx/vvmx.c +3
-3-void set_vvmcs_virtual (void *vvmcs,u32 vmcs_encoding,u64 val) +void set_vvmcs_virtual (void *vvmcs,uint32_t vmcs_encoding,uint64_t val) {union vmcs_encoding enc; -u64 *content = (u64 *) vvmcs; +uint64_t *content = vvmcs;int offset; -u64 res; +uint64_t res;
Thanks for doing the switch of content to type uint64_t. You should however not change the type of res to uint64_t also IMO, as you are not touching that line anyway.
With that fixed:
Thanks!
Quoted 38 lines · Roger Pau Monné
xen/arch/x86/hvm/vmx/vvmx.c static int vvmcs_offset(u32 width, u32 type, u32
Quoted 5 lines · Simran Singhal
xen/arch/x86/hvm/vmx/vvmx.c +0
-0@@ -253,12 +253,12 @@ static int vvmcs_offset(u32 width, u32 type, u32index)
xen/arch/x86/hvm/vmx/vvmx.c enum vmx_insn_errno get_vvmcs_real_safe(const
Quoted 16 lines
xen/arch/x86/hvm/vmx/vvmx.c +3
-3return offset; } -u64 get_vvmcs_virtual (void *vvmcs,u32 vmcs_encoding) +uint64_t get_vvmcs_virtual (void *vvmcs,uint32_t vmcs_encoding) {union vmcs_encoding enc; -u64 *content = (u64 *) vvmcs; +uint64_t *content = vvmcs;int offset; -u64 res; +uint64_t res; enc.word = vmcs_encoding; offset =vvmcs_offset (enc.width, enc.type, enc.index);@@ -307,12 +307,12 @@ enum vmx_insn_errno get_vvmcs_real_safe(conststruct vcpu *v, u32 encoding,
xen/arch/x86/hvm/vmx/vvmx.c enum vmx_insn_errno get_vvmcs_real_safe(const struct vcpu *v, u32 encoding,
Quoted 5 lines
xen/arch/x86/hvm/vmx/vvmx.c +1
-1return virtual_vmcs_vmread_safe (v, encoding, val); } -void set_vvmcs_virtual (void *vvmcs,u32 vmcs_encoding,u64 val) +void set_vvmcs_virtual(void *vvmcs, uint32_t vmcs_encoding, uint64_tval)
xen/arch/x86/hvm/vmx/vvmx.c static int vvmcs_offset(u32 width, u32 type, u32 index) · line 261
Quoted 7 lines
xen/arch/x86/hvm/vmx/vvmx.c +2
-2{union vmcs_encoding enc; -u64 *content = (u64 *) vvmcs; +uint64_t *content = vvmcs;int offset; -u64 res; +uint64_t res;
Quoted 4 lines
Thanks for doing the switch of content to type
uint64_t. You should however not change the type of res touint64_talso IMO, as you are not touching that line anyway.
Thanks for your feedback Roger and Wei.
My bad, I thought I need to change all the unintX to uintX_t in the function set_vvmcs_virtual().
Sorry for the inconvenience.
Quoted 7 lines
With that fixed:
Reviewed-by Roger Pau Monné <[email protected]>Thanks!
Jan Beulich
Acked-byQuoted 25 lines · Roger Pau Monné
Quoted 24 lines · Simran Singhal
xen/arch/x86/hvm/vmx/vvmx.c +3
-3@@ -253,12 +253,12 @@ static int vvmcs_offset(u32 width, u32 type, u32 index)return offset; } -u64 get_vvmcs_virtual (void *vvmcs,u32 vmcs_encoding) +uint64_t get_vvmcs_virtual (void *vvmcs,uint32_t vmcs_encoding) {union vmcs_encoding enc; -u64 *content = (u64 *) vvmcs; +uint64_t *content = vvmcs;int offset; -u64 res; +uint64_t res; enc.word = vmcs_encoding; offset =vvmcs_offset (enc.width, enc.type, enc.index);@@ -307,12 +307,12 @@ enum vmx_insn_errno get_vvmcs_real_safe(const struct vcpu *v, u32 encoding,return virtual_vmcs_vmread_safe (v, encoding, val); }
Quoted 13 lines
xen/arch/x86/hvm/vmx/vvmx.c enum vmx_insn_errno get_vvmcs_real_safe(const struct vcpu *v, u32 encoding, · line 315
Quoted 9 lines
xen/arch/x86/hvm/vmx/vvmx.c +3
-3-void set_vvmcs_virtual (void *vvmcs,u32 vmcs_encoding,u64 val) +void set_vvmcs_virtual (void *vvmcs,uint32_t vmcs_encoding,uint64_t val) {union vmcs_encoding enc; -u64 *content = (u64 *) vvmcs; +uint64_t *content = vvmcs;int offset; -u64 res; +uint64_t res;Thanks for doing the switch of content to type
uint64_t. You should however not change the type of res touint64_talso IMO, as you are not touching that line anyway.
I actually wouldn't mind the patch being left as is?
Quoted 3 lines
With that fixed:
Reviewed-by Roger Pau Monné <[email protected]>
Roger - please clarify if your R-b is also fine without the requested adjustment.
Jan
Quoted 42 lines · Jan Beulich
Quoted 25 lines · Roger Pau Monné
Quoted 24 lines · Simran Singhal
xen/arch/x86/hvm/vmx/vvmx.c +3
-3@@ -253,12 +253,12 @@ static int vvmcs_offset(u32 width, u32 type, u32 index)return offset; } -u64 get_vvmcs_virtual (void *vvmcs,u32 vmcs_encoding) +uint64_t get_vvmcs_virtual (void *vvmcs,uint32_t vmcs_encoding) {union vmcs_encoding enc; -u64 *content = (u64 *) vvmcs; +uint64_t *content = vvmcs;int offset; -u64 res; +uint64_t res; enc.word = vmcs_encoding; offset =vvmcs_offset (enc.width, enc.type, enc.index);@@ -307,12 +307,12 @@ enum vmx_insn_errno get_vvmcs_real_safe(const struct vcpu *v, u32 encoding,return virtual_vmcs_vmread_safe (v, encoding, val); }Quoted 13 lines
xen/arch/x86/hvm/vmx/vvmx.c enum vmx_insn_errno get_vvmcs_real_safe(const struct vcpu *v, u32 encoding, · line 315
Quoted 9 lines
xen/arch/x86/hvm/vmx/vvmx.c +3
-3-void set_vvmcs_virtual (void *vvmcs,u32 vmcs_encoding,u64 val) +void set_vvmcs_virtual (void *vvmcs,uint32_t vmcs_encoding,uint64_t val) {union vmcs_encoding enc; -u64 *content = (u64 *) vvmcs; +uint64_t *content = vvmcs;int offset; -u64 res; +uint64_t res;Thanks for doing the switch of content to type
uint64_t. You should however not change the type of res touint64_talso IMO, as you are not touching that line anyway.I actually wouldn't mind the patch being left as is?
Quoted 8 lines
Quoted 3 lines
With that fixed:
Reviewed-by Roger Pau Monné <[email protected]>Acked-by Jan Beulich <[email protected]>Roger - please clarify if your R-b is also fine without the requested adjustment.
Yes, TBH I was borderline on requesting the change, as the type change is correct.
Roger.