[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: [Xen-devel] [PATCH] xen/x86: Remove unnecessary cast on void pointer
On Sat, Mar 28, 2020 at 05:47:18PM +0530, Simran Singhal wrote: [...] > > > > > 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. 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.
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |