xen/x86: Remove unnecessary cast on void pointer
PATCH 1/1 xen/x86: Remove unnecessary cast on void pointer
Assignment to a typed pointer is sufficient in C.
No cast is needed.
--- 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 | 4 ++-- xen/arch/x86/mm/p2m-pt.c | 2 +- 6 files changed, 7 insertions(+), 7 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 +2 -2
@@ -256,7 +256,7 @@ static int vvmcs_offset(u32 width, u32 type, u32 index)u64 get_vvmcs_virtual (void *vvmcs,u32 vmcs_encoding) {union vmcs_encoding enc; -u64 *content = (u64 *) vvmcs; +u64 *content = vvmcs;int offset;u64 res;
@@ -310,7 +310,7 @@ enum vmx_insn_errno get_vvmcs_real_safe(const struct vcpu *v, u32 encoding,void set_vvmcs_virtual (void *vvmcs,u32 vmcs_encoding,u64 val) {union vmcs_encoding enc; -u64 *content = (u64 *) vvmcs; +u64 *content = vvmcs;int offset;u64 res;
xen/arch/x86/mm/p2m-pt.c +1 -1
@@ -127,7 +127,7 @@ p2m_find_entry(void *table, unsigned long *gfn_remainder,return NULL ; } *gfn_remainder &= (1 << shift) -1 ; -return (l1_pgentry_t *)table + index; +return table + index; }/* Free intermediate tables from a p2m sub-tree */
Signature · 1 line
2.17.1
Thanks!
Quoted 14 lines · Simran Singhal
xen/arch/x86/hvm/vmx/vvmx.c +1
-1@@ -256,7 +256,7 @@ static int vvmcs_offset(u32 width, u32 type, u32 index)u64 get_vvmcs_virtual (void *vvmcs,u32 vmcs_encoding) {union vmcs_encoding enc; -u64 *content = (u64 *) vvmcs; +u64 *content = vvmcs;int offset;u64 res;
xen/arch/x86/hvm/vmx/vvmx.c enum vmx_insn_errno get_vvmcs_real_safe(const struct vcpu *v, u32 encoding, · line 313
Quoted 5 lines
xen/arch/x86/hvm/vmx/vvmx.c +1
-1@@ -310,7 +310,7 @@ enum vmx_insn_errno get_vvmcs_real_safe(const struct vcpu *v, u32 encoding,void set_vvmcs_virtual (void *vvmcs,u32 vmcs_encoding,u64 val) {union vmcs_encoding enc; -u64 *content = (u64 *) vvmcs; +u64 *content = vvmcs;
While there, would you mind changing u64 to uint64_t? (here and above)
xen/arch/x86/mm/p2m-pt.c p2m_find_entry(void *table, unsigned long *gfn_remainder, · line 130
Quoted 13 lines
xen/arch/x86/hvm/vmx/vvmx.c +0
-0int offset;u64 res;xen/arch/x86/mm/p2m-pt.c +1
-1@@ -127,7 +127,7 @@ p2m_find_entry(void *table, unsigned long *gfn_remainder,return NULL ; } *gfn_remainder &= (1 << shift) -1 ; -return (l1_pgentry_t *)table + index; +return table + index;
I don't think removing this cast is correct, as you would be doing a plain addition to a pointer instead of fetching the next entry in the array of l1_pgentry_t entries.
If you want to get rid of the cast here you need to change the type of the table parameter to l1_pgentry_t * instead of void *.
Thanks, Roger.
Quoted 16 lines · Roger Pau Monné
Thanks!
Quoted 13 lines · Simran Singhal
xen/arch/x86/hvm/vmx/vvmx.c +1
-1@@ -256,7 +256,7 @@ static int vvmcs_offset(u32 width, u32 type, u32 index)u64 get_vvmcs_virtual (void *vvmcs,u32 vmcs_encoding) {union vmcs_encoding enc; -u64 *content = (u64 *) vvmcs; +u64 *content = vvmcs;int offset;u64 res;
Quoted 10 lines
xen/arch/x86/hvm/vmx/vvmx.c enum vmx_insn_errno get_vvmcs_real_safe(const struct vcpu *v, u32 encoding, · line 313
Quoted 6 lines
xen/arch/x86/hvm/vmx/vvmx.c +1
-1@@ -310,7 +310,7 @@ enum vmx_insn_errno get_vvmcs_real_safe(const struct vcpu *v, u32 encoding,void set_vvmcs_virtual (void *vvmcs,u32 vmcs_encoding,u64 val) {union vmcs_encoding enc; -u64 *content = (u64 *) vvmcs; +u64 *content = vvmcs;While there, would you mind changing u64 to
uint64_t? (here and above)
To add some context to this comment: new code has been using uintX variants. We want to migrate existing code gradually. Since you're touching these lines anyway, it is a good chance to do the migration.
When you do this in your next version, please add a line in the commit message saying something along the line that "Take the chance to change some u64 to uint64_t".
Wei.
Quoted 30 lines · Wei Liu
Quoted 8 lines · Roger Pau Monné
Thanks!
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@@ -256,7 +256,7 @@ static int vvmcs_offset(u32 width, u32 type, u32index)
Quoted 9 lines
xen/arch/x86/hvm/vmx/vvmx.c enum vmx_insn_errno get_vvmcs_real_safe(const
Quoted 9 lines
xen/arch/x86/hvm/vmx/vvmx.c +1
-1u64 get_vvmcs_virtual (void *vvmcs,u32 vmcs_encoding) {union vmcs_encoding enc; -u64 *content = (u64 *) vvmcs; +u64 *content = vvmcs;int offset;u64 res;@@ -310,7 +310,7 @@ enum vmx_insn_errno get_vvmcs_real_safe(conststruct vcpu *v, u32 encoding,
Quoted 9 lines
xen/arch/x86/hvm/vmx/vvmx.c enum vmx_insn_errno get_vvmcs_real_safe(const struct vcpu *v, u32 encoding, · line 313
Quoted 5 lines
xen/arch/x86/hvm/vmx/vvmx.c +1
-1void set_vvmcs_virtual (void *vvmcs,u32 vmcs_encoding,u64 val) {union vmcs_encoding enc; -u64 *content = (u64 *) vvmcs; +u64 *content = vvmcs;While there, would you mind changing u64 to
uint64_t? (here and above)
Quoted 8 lines
To add some context to this comment: new code has been using uintX variants. We want to migrate existing code gradually. Since you're touching these lines anyway, it is a good chance to do the migration.
When you do this in your next version, please add a line in the commit message saying something along the line that "Take the chance to change some u64 to
uint64_t".
Thanks for the suggestion. I'll do the changes in the next version.
Thanks
Simran
Quoted 3 lines
Wei.
Hi Roger,
Thanks for your suggestions!
Quoted 19 lines · Roger Pau Monné
Thanks!
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@@ -256,7 +256,7 @@ 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 struct
Quoted 9 lines
xen/arch/x86/hvm/vmx/vvmx.c +1
-1u64 get_vvmcs_virtual (void *vvmcs,u32 vmcs_encoding) {union vmcs_encoding enc; -u64 *content = (u64 *) vvmcs; +u64 *content = vvmcs;int offset;u64 res;@@ -310,7 +310,7 @@ enum vmx_insn_errno get_vvmcs_real_safe(const structvcpu *v, u32 encoding,
Quoted 9 lines
xen/arch/x86/hvm/vmx/vvmx.c enum vmx_insn_errno get_vvmcs_real_safe(const struct vcpu *v, u32 encoding, · line 313
Quoted 5 lines
xen/arch/x86/hvm/vmx/vvmx.c +1
-1void set_vvmcs_virtual (void *vvmcs,u32 vmcs_encoding,u64 val) {union vmcs_encoding enc; -u64 *content = (u64 *) vvmcs; +u64 *content = vvmcs;While there, would you mind changing u64 to
uint64_t? (here and above)
I'll do that in the next version.
Quoted 16 lines
xen/arch/x86/mm/p2m-pt.c p2m_find_entry(void *table, unsigned long
Quoted 9 lines
xen/arch/x86/hvm/vmx/vvmx.c +0
-0int offset;u64 res;xen/arch/x86/mm/p2m-pt.c +0
-0@@ -127,7 +127,7 @@ p2m_find_entry(void *table, unsigned long
*gfn_remainder,xen/arch/x86/mm/p2m-pt.c p2m_find_entry(void *table, unsigned long *gfn_remainder, · line 130
Quoted 5 lines
xen/arch/x86/mm/p2m-pt.c +1
-1return NULL ; } *gfn_remainder &= (1 << shift) -1 ; -return (l1_pgentry_t *)table + index; +return table + index;
Quoted 7 lines
I don't think removing this cast is correct, as you would be doing a plain addition to a pointer instead of fetching the next entry in the array of
l1_pgentry_tentries.If you want to get rid of the cast here you need to change the type of the table parameter to
l1_pgentry_t* instead of void *.
Yes, you are correct. Since void* is a pointer to an unknown type we can't do pointer arithmetic on it, as the compiler wouldn't know how big the thing pointed to is. Thus, it is necessary to keep the cast on the "table".
Ah! I am sorry for this mistake. But, I am afraid why I didn't get warning during compilation.
I'll remove these changes in the next version.
Thanks
Simran
Quoted 3 lines
Thanks, Roger.
On Sat, Mar 28, 2020 at 05:47:18PM +0530, Simran Singhal wrote:
[...]
Quoted 24 lines
Quoted 16 lines
xen/arch/x86/mm/p2m-pt.c p2m_find_entry(void *table, unsigned long
Quoted 9 lines
int offset; u64 res;xen/arch/x86/mm/p2m-pt.c +0
-0@@ -127,7 +127,7 @@ p2m_find_entry(void *table, unsigned long
*gfn_remainder,xen/arch/x86/mm/p2m-pt.c p2m_find_entry(void *table, unsigned long *gfn_remainder, · line 130
Quoted 5 lines
xen/arch/x86/mm/p2m-pt.c +1
-1return NULL ; } *gfn_remainder &= (1 << shift) -1 ; -return (l1_pgentry_t *)table + index; +return table + index;Quoted 7 lines
I don't think removing this cast is correct, as you would be doing a plain addition to a pointer instead of fetching the next entry in the array of
l1_pgentry_tentries.If you want to get rid of the cast here you need to change the type of the table parameter to
l1_pgentry_t* instead of void *.
Quoted 6 lines
Yes, you are correct. Since void* is a pointer to an unknown type we can't do pointer arithmetic on it, as the compiler wouldn't know how big the thing pointed to is. Thus, it is necessary to keep the cast on the "table".
Ah! I am sorry for this mistake. But, I am afraid why I didn't get warning during compilation.
Pointer arithmetic on void* is allowed. It is treated as if the size of the object is 1. That's probably why you didn't get a warning.
Wei.