[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Xen-devel] [PATCH] xen/x86: Remove unnecessary cast on void pointer
Hi Roger,
Thanks for your suggestions!
Thanks!
On Sat, Mar 28, 2020 at 11:08:35AM +0530, Simran Singhal wrote:
> diff --git a/xen/arch/x86/hvm/vmx/vvmx.c b/xen/arch/x86/hvm/vmx/vvmx.c
> index f049920196..a53d3ca2a4 100644
> --- a/xen/arch/x86/hvm/vmx/vvmx.c
> +++ b/xen/arch/x86/hvm/vmx/vvmx.c
> @@ -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;
While there, would you mind changing u64 to uint64_t? (here and
above)
I'll do that in the next version.
> int offset;
> u64 res;
>
> diff --git a/xen/arch/x86/mm/p2m-pt.c b/xen/arch/x86/mm/p2m-pt.c
> index eb66077496..058b9b8adf 100644
> --- a/xen/arch/x86/mm/p2m-pt.c
> +++ b/xen/arch/x86/mm/p2m-pt.c
> @@ -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 *.
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
Thanks, Roger.
|