[PATCH] powerpc/usb: use unsigned long to type cast an address of ioremap
David Laight
David.Laight at ACULAB.COM
Thu Nov 3 23:16:02 EST 2011
> >> > usb_sys_regs = (void *)dr_regs + USB_DR_SYS_OFFSET;
>
> > But that is invalid C.
>
> What's invalid about it? I haven't tried compiling this
> specific line of code, but I've done stuff like it in the past many
times.
>
> Are you talking about adding an integer to a void pointer?
> If so, then that's something that gcc supports and that the kernel
uses
> all over the place.
Arithmetic on 'void *' should not be done. I know some versions of
gcc allow it (provided some warning level/option is enabled) but
that doesn't mean it is valid.
My suspicions are that is was allowed due to the way 'void *'
was originally bodged into gcc.
> A char* is incorrect because a char could be more
> than one byte, in theory.
It is somewhat difficult to untangle the standard, but
sizeof (char) is defined to be one.
Of course, the C language doesn't actually require that
you can converts between pointers to different types in
any well-defined manner. But most of the low level device
access assumes an adequately linear address space.
David
More information about the Linuxppc-dev
mailing list