* [PATCH] powerpc/usb: use unsigned long to type cast an address of ioremap
@ 2011-11-03 9:58 Shaohui Xie
2011-11-03 11:14 ` David Laight
2011-11-03 11:38 ` Tabi Timur-B04825
0 siblings, 2 replies; 8+ messages in thread
From: Shaohui Xie @ 2011-11-03 9:58 UTC (permalink / raw)
To: linuxppc-dev; +Cc: linux-usb, Shaohui Xie
Below are codes for accessing usb sysif_regs in driver:
usb_sys_regs = (struct usb_sys_interface *)
((u32)dr_regs + USB_DR_SYS_OFFSET);
these codes work in 32-bit, but in 64-bit, use u32 to type cast the address
of ioremap is not right, and accessing members of 'usb_sys_regs' will cause
call trace, so use unsigned long for both 32-bit and 64-bit.
Signed-off-by: Shaohui Xie <Shaohui.Xie@freescale.com>
---
drivers/usb/gadget/fsl_udc_core.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/drivers/usb/gadget/fsl_udc_core.c b/drivers/usb/gadget/fsl_udc_core.c
index c81fbad..581b7cc 100644
--- a/drivers/usb/gadget/fsl_udc_core.c
+++ b/drivers/usb/gadget/fsl_udc_core.c
@@ -2498,7 +2498,7 @@ static int __init fsl_udc_probe(struct platform_device *pdev)
#ifndef CONFIG_ARCH_MXC
if (pdata->have_sysif_regs)
usb_sys_regs = (struct usb_sys_interface *)
- ((u32)dr_regs + USB_DR_SYS_OFFSET);
+ ((unsigned long)dr_regs + USB_DR_SYS_OFFSET);
#endif
/* Initialize USB clocks */
--
1.6.4
^ permalink raw reply related [flat|nested] 8+ messages in thread
* RE: [PATCH] powerpc/usb: use unsigned long to type cast an address of ioremap
2011-11-03 9:58 [PATCH] powerpc/usb: use unsigned long to type cast an address of ioremap Shaohui Xie
@ 2011-11-03 11:14 ` David Laight
2011-11-03 11:38 ` Tabi Timur-B04825
1 sibling, 0 replies; 8+ messages in thread
From: David Laight @ 2011-11-03 11:14 UTC (permalink / raw)
To: Shaohui Xie, linuxppc-dev; +Cc: linux-usb
=20
> Below are codes for accessing usb sysif_regs in driver:
>=20
> usb_sys_regs =3D (struct usb_sys_interface *)
> ((u32)dr_regs + USB_DR_SYS_OFFSET);
>=20
> these codes work in 32-bit, but in 64-bit, use u32 to type cast the
address
> of ioremap is not right, and accessing members of 'usb_sys_regs' will
cause
> call trace, so use unsigned long for both 32-bit and 64-bit.
Wouldn't a (char *) cast be even better?
David
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] powerpc/usb: use unsigned long to type cast an address of ioremap
2011-11-03 9:58 [PATCH] powerpc/usb: use unsigned long to type cast an address of ioremap Shaohui Xie
2011-11-03 11:14 ` David Laight
@ 2011-11-03 11:38 ` Tabi Timur-B04825
2011-11-03 11:38 ` David Laight
1 sibling, 1 reply; 8+ messages in thread
From: Tabi Timur-B04825 @ 2011-11-03 11:38 UTC (permalink / raw)
To: Xie Shaohui-B21989; +Cc: linux-usb, linuxppc-dev
On Thu, Nov 3, 2011 at 4:58 AM, Shaohui Xie <Shaohui.Xie@freescale.com> wro=
te:
>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0usb_sys_regs =3D (struct usb_sys_interface=
*)
> - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ((u32)dr_re=
gs + USB_DR_SYS_OFFSET);
> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ((unsigned =
long)dr_regs + USB_DR_SYS_OFFSET);
This makes more sense:
usb_sys_regs =3D (void *)dr_regs + USB_DR_SYS_OFFSET;
--=20
Timur Tabi
Linux kernel developer at Freescale=
^ permalink raw reply [flat|nested] 8+ messages in thread
* RE: [PATCH] powerpc/usb: use unsigned long to type cast an address of ioremap
2011-11-03 11:38 ` Tabi Timur-B04825
@ 2011-11-03 11:38 ` David Laight
2011-11-03 12:07 ` Tabi Timur-B04825
0 siblings, 1 reply; 8+ messages in thread
From: David Laight @ 2011-11-03 11:38 UTC (permalink / raw)
To: Tabi Timur-B04825, Xie Shaohui-B21989; +Cc: linux-usb, linuxppc-dev
=20
> On Thu, Nov 3, 2011 at 4:58 AM, Shaohui Xie =
<Shaohui.Xie@freescale.com> wrote:
> >
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0usb_sys_regs =3D (struct =
usb_sys_interface *)
> > - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
((u32)dr_regs + USB_DR_SYS_OFFSET);
> > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =
((unsigned long)dr_regs + USB_DR_SYS_OFFSET);
>=20
> This makes more sense:
>=20
> usb_sys_regs =3D (void *)dr_regs + USB_DR_SYS_OFFSET;
But that is invalid C.
David
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] powerpc/usb: use unsigned long to type cast an address of ioremap
2011-11-03 11:38 ` David Laight
@ 2011-11-03 12:07 ` Tabi Timur-B04825
2011-11-03 12:16 ` David Laight
0 siblings, 1 reply; 8+ messages in thread
From: Tabi Timur-B04825 @ 2011-11-03 12:07 UTC (permalink / raw)
To: David Laight; +Cc: linux-usb, linuxppc-dev, Xie Shaohui-B21989
David Laight wrote:
>> > usb_sys_regs =3D (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=20
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=20
that's something that gcc supports and that the kernel uses all over the=20
place. A char* is incorrect because a char could be more than one byte,=20
in theory.
--=20
Timur Tabi
Linux kernel developer at Freescale=
^ permalink raw reply [flat|nested] 8+ messages in thread
* RE: [PATCH] powerpc/usb: use unsigned long to type cast an address of ioremap
2011-11-03 12:07 ` Tabi Timur-B04825
@ 2011-11-03 12:16 ` David Laight
2011-11-03 14:12 ` Timur Tabi
2011-11-03 22:08 ` Segher Boessenkool
0 siblings, 2 replies; 8+ messages in thread
From: David Laight @ 2011-11-03 12:16 UTC (permalink / raw)
To: Tabi Timur-B04825; +Cc: linux-usb, linuxppc-dev, Xie Shaohui-B21989
> >> > usb_sys_regs =3D (void *)dr_regs + USB_DR_SYS_OFFSET;
>=20
> > But that is invalid C.
>=20
> What's invalid about it? I haven't tried compiling this=20
> specific line of code, but I've done stuff like it in the past many
times.
>=20
> Are you talking about adding an integer to a void pointer? =20
> If so, then that's something that gcc supports and that the kernel
uses=20
> 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=20
> 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
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] powerpc/usb: use unsigned long to type cast an address of ioremap
2011-11-03 12:16 ` David Laight
@ 2011-11-03 14:12 ` Timur Tabi
2011-11-03 22:08 ` Segher Boessenkool
1 sibling, 0 replies; 8+ messages in thread
From: Timur Tabi @ 2011-11-03 14:12 UTC (permalink / raw)
To: David Laight
Cc: <linux-usb@vger.kernel.org>,
<linuxppc-dev@lists.ozlabs.org>,
Xie Shaohui-B21989
On Nov 3, 2011, at 7:16 AM, David Laight <David.Laight@ACULAB.COM> wrote:
> 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.
Well, I don't know what else to say. Arithmetic on void* is done all over t=
he kernel. You're a little late to the party if you're going to advocate it=
s avoidance. =20
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] powerpc/usb: use unsigned long to type cast an address of ioremap
2011-11-03 12:16 ` David Laight
2011-11-03 14:12 ` Timur Tabi
@ 2011-11-03 22:08 ` Segher Boessenkool
1 sibling, 0 replies; 8+ messages in thread
From: Segher Boessenkool @ 2011-11-03 22:08 UTC (permalink / raw)
To: David Laight
Cc: linuxppc-dev, linux-usb, Tabi Timur-B04825, Xie Shaohui-B21989
> 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.
All relevant GCC versions support it (going back to 2.x at least).
It is _always_ allowed, whatever compiler options you use; -pedantic
or -Wpointer-arith will warn (which you can upgrade to an error).
The Linux kernel is not built with these warnings enabled.
>> 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.
A char takes exactly one byte. A byte could be more than eight bits,
of course.
In GCC, sizeof(void) is 1 as well.
> Of course, the C language doesn't actually require that
> you can converts between pointers to different types in
> any well-defined manner.
It does actually, see 6.3.2.3/7. You can convert any pointer to object
to a pointer to a different object type, as long as it is properly
aligned.
You cannot in general access the object as that new type of course, but
it is perfectly well-defined; in particular, you can convert it back to
the original type and get the same value again, and you can walk
consecutive
bytes of the object by using a pointer to character type.
Segher
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2011-11-03 22:08 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-11-03 9:58 [PATCH] powerpc/usb: use unsigned long to type cast an address of ioremap Shaohui Xie
2011-11-03 11:14 ` David Laight
2011-11-03 11:38 ` Tabi Timur-B04825
2011-11-03 11:38 ` David Laight
2011-11-03 12:07 ` Tabi Timur-B04825
2011-11-03 12:16 ` David Laight
2011-11-03 14:12 ` Timur Tabi
2011-11-03 22:08 ` Segher Boessenkool
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).