linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] serial: atmel: fix compiler warning on address cast
@ 2015-10-05 17:00 Andre Przywara
  2015-10-08  9:01 ` Alexandre Belloni
  0 siblings, 1 reply; 6+ messages in thread
From: Andre Przywara @ 2015-10-05 17:00 UTC (permalink / raw)
  To: Nicolas Ferre
  Cc: Uwe Kleine-König, Greg Kroah-Hartman, Jiri Slaby,
	linux-serial, linux-kernel, linux-arm-kernel

Turning on KVM and LPAE support on top of a multi_v7_defconfig will
produce a compiler warning in the Atmel serial driver:
drivers/tty/serial/atmel_serial.c: In function 'atmel_verify_port':
drivers/tty/serial/atmel_serial.c:2299:6: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
  if ((void *)port->mapbase != ser->iomem_base)
      ^

Fix that by using the cast on the right hand side instead, as similar
code already does in other drivers.

Signed-off-by: Andre Przywara <andre.przywara@arm.com>
---
 drivers/tty/serial/atmel_serial.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/tty/serial/atmel_serial.c b/drivers/tty/serial/atmel_serial.c
index cd30a45..28039ce 100644
--- a/drivers/tty/serial/atmel_serial.c
+++ b/drivers/tty/serial/atmel_serial.c
@@ -2296,7 +2296,7 @@ static int atmel_verify_port(struct uart_port *port, struct serial_struct *ser)
 		ret = -EINVAL;
 	if (port->uartclk / 16 != ser->baud_base)
 		ret = -EINVAL;
-	if ((void *)port->mapbase != ser->iomem_base)
+	if (port->mapbase != (unsigned long)ser->iomem_base)
 		ret = -EINVAL;
 	if (port->iobase != ser->port)
 		ret = -EINVAL;
-- 
2.5.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] serial: atmel: fix compiler warning on address cast
  2015-10-05 17:00 [PATCH] serial: atmel: fix compiler warning on address cast Andre Przywara
@ 2015-10-08  9:01 ` Alexandre Belloni
  2015-10-08  9:37   ` Russell King - ARM Linux
  0 siblings, 1 reply; 6+ messages in thread
From: Alexandre Belloni @ 2015-10-08  9:01 UTC (permalink / raw)
  To: Andre Przywara
  Cc: Nicolas Ferre, Greg Kroah-Hartman, Uwe Kleine-König,
	linux-kernel, linux-serial, Jiri Slaby, linux-arm-kernel

On 05/10/2015 at 18:00:52 +0100, Andre Przywara wrote :
> Turning on KVM and LPAE support on top of a multi_v7_defconfig will
> produce a compiler warning in the Atmel serial driver:
> drivers/tty/serial/atmel_serial.c: In function 'atmel_verify_port':
> drivers/tty/serial/atmel_serial.c:2299:6: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
>   if ((void *)port->mapbase != ser->iomem_base)
>       ^
> 
> Fix that by using the cast on the right hand side instead, as similar
> code already does in other drivers.
> 
> Signed-off-by: Andre Przywara <andre.przywara@arm.com>
Acked-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>

> ---
>  drivers/tty/serial/atmel_serial.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/tty/serial/atmel_serial.c b/drivers/tty/serial/atmel_serial.c
> index cd30a45..28039ce 100644
> --- a/drivers/tty/serial/atmel_serial.c
> +++ b/drivers/tty/serial/atmel_serial.c
> @@ -2296,7 +2296,7 @@ static int atmel_verify_port(struct uart_port *port, struct serial_struct *ser)
>  		ret = -EINVAL;
>  	if (port->uartclk / 16 != ser->baud_base)
>  		ret = -EINVAL;
> -	if ((void *)port->mapbase != ser->iomem_base)
> +	if (port->mapbase != (unsigned long)ser->iomem_base)
>  		ret = -EINVAL;
>  	if (port->iobase != ser->port)
>  		ret = -EINVAL;
> -- 
> 2.5.1
> 
> 
> _______________________________________________
> linux-arm-kernel mailing list
> linux-arm-kernel@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

-- 
Alexandre Belloni, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] serial: atmel: fix compiler warning on address cast
  2015-10-08  9:01 ` Alexandre Belloni
@ 2015-10-08  9:37   ` Russell King - ARM Linux
  2015-10-08 10:38     ` Alexandre Belloni
  0 siblings, 1 reply; 6+ messages in thread
From: Russell King - ARM Linux @ 2015-10-08  9:37 UTC (permalink / raw)
  To: Alexandre Belloni
  Cc: Andre Przywara, Greg Kroah-Hartman, Uwe Kleine-König,
	Nicolas Ferre, linux-kernel, linux-serial, Jiri Slaby,
	linux-arm-kernel

On Thu, Oct 08, 2015 at 11:01:48AM +0200, Alexandre Belloni wrote:
> On 05/10/2015 at 18:00:52 +0100, Andre Przywara wrote :
> > Turning on KVM and LPAE support on top of a multi_v7_defconfig will
> > produce a compiler warning in the Atmel serial driver:
> > drivers/tty/serial/atmel_serial.c: In function 'atmel_verify_port':
> > drivers/tty/serial/atmel_serial.c:2299:6: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
> >   if ((void *)port->mapbase != ser->iomem_base)
> >       ^
> > 
> > Fix that by using the cast on the right hand side instead, as similar
> > code already does in other drivers.
> > 
> > Signed-off-by: Andre Przywara <andre.przywara@arm.com>
> Acked-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>

Hmm, this actually points at a problem, and the cast screems out about it.
Think about it, can you guess what it is?

-- 
FTTC broadband for 0.8mile line: currently at 9.6Mbps down 400kbps up
according to speedtest.net.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] serial: atmel: fix compiler warning on address cast
  2015-10-08  9:37   ` Russell King - ARM Linux
@ 2015-10-08 10:38     ` Alexandre Belloni
  2015-10-08 14:49       ` Andre Przywara
  0 siblings, 1 reply; 6+ messages in thread
From: Alexandre Belloni @ 2015-10-08 10:38 UTC (permalink / raw)
  To: Russell King - ARM Linux
  Cc: Greg Kroah-Hartman, Andre Przywara, Jiri Slaby, Nicolas Ferre,
	linux-kernel, linux-serial, Uwe Kleine-König,
	linux-arm-kernel

On 08/10/2015 at 10:37:49 +0100, Russell King - ARM Linux wrote :
> On Thu, Oct 08, 2015 at 11:01:48AM +0200, Alexandre Belloni wrote:
> > On 05/10/2015 at 18:00:52 +0100, Andre Przywara wrote :
> > > Turning on KVM and LPAE support on top of a multi_v7_defconfig will
> > > produce a compiler warning in the Atmel serial driver:
> > > drivers/tty/serial/atmel_serial.c: In function 'atmel_verify_port':
> > > drivers/tty/serial/atmel_serial.c:2299:6: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
> > >   if ((void *)port->mapbase != ser->iomem_base)
> > >       ^
> > > 
> > > Fix that by using the cast on the right hand side instead, as similar
> > > code already does in other drivers.
> > > 
> > > Signed-off-by: Andre Przywara <andre.przywara@arm.com>
> > Acked-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
> 
> Hmm, this actually points at a problem, and the cast screems out about it.
> Think about it, can you guess what it is?
> 

My understanding of the issue is that port->mapbase is a 64bit
resource_size_t, and is larger than void * hence the warning. Casting
iomem_base to unsigned long seems safe to me, am I wrong?


-- 
Alexandre Belloni, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] serial: atmel: fix compiler warning on address cast
  2015-10-08 10:38     ` Alexandre Belloni
@ 2015-10-08 14:49       ` Andre Przywara
  2015-10-08 15:01         ` Russell King - ARM Linux
  0 siblings, 1 reply; 6+ messages in thread
From: Andre Przywara @ 2015-10-08 14:49 UTC (permalink / raw)
  To: Alexandre Belloni, Russell King - ARM Linux
  Cc: Greg Kroah-Hartman, Jiri Slaby, Nicolas Ferre, linux-kernel,
	linux-serial, Uwe Kleine-König, linux-arm-kernel

Hi,

On 08/10/15 11:38, Alexandre Belloni wrote:
> On 08/10/2015 at 10:37:49 +0100, Russell King - ARM Linux wrote :
>> On Thu, Oct 08, 2015 at 11:01:48AM +0200, Alexandre Belloni wrote:
>>> On 05/10/2015 at 18:00:52 +0100, Andre Przywara wrote :
>>>> Turning on KVM and LPAE support on top of a multi_v7_defconfig will
>>>> produce a compiler warning in the Atmel serial driver:
>>>> drivers/tty/serial/atmel_serial.c: In function 'atmel_verify_port':
>>>> drivers/tty/serial/atmel_serial.c:2299:6: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
>>>>   if ((void *)port->mapbase != ser->iomem_base)
>>>>       ^
>>>>
>>>> Fix that by using the cast on the right hand side instead, as similar
>>>> code already does in other drivers.
>>>>
>>>> Signed-off-by: Andre Przywara <andre.przywara@arm.com>
>>> Acked-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
>>
>> Hmm, this actually points at a problem, and the cast screems out about it.
>> Think about it, can you guess what it is?

Russell, I'd really appreciate if we wouldn't have to play
"guess-what-I-am-thinking" here. Can't you just say what's bothering you?

> My understanding of the issue is that port->mapbase is a 64bit
> resource_size_t, and is larger than void * hence the warning. Casting
> iomem_base to unsigned long seems safe to me, am I wrong?

That is what I found out as well: it's comparing a physical address with
a pointer. And I tried to get to the root of this mismatch and fix it
there, but it turned out to be really old code to allow userspace to
setup serial ports by providing the MMIO address (IIRC this was for old
PC-style non-PnP serial ports some 20 years ago).
This whole concept is really outdated and probably does not make sense
at all for most drivers (except 8250 on i386).
Fixing this is a different task, I think, since it would impact most
serial drivers. I am happy to tackle this later, btw.

But this patch was just to fix the compiler warning I see every time now
and still meant for 4.3, so I kept it deliberately simple and contained.

Is that a solution we can agree on?

Cheers,
Andre.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] serial: atmel: fix compiler warning on address cast
  2015-10-08 14:49       ` Andre Przywara
@ 2015-10-08 15:01         ` Russell King - ARM Linux
  0 siblings, 0 replies; 6+ messages in thread
From: Russell King - ARM Linux @ 2015-10-08 15:01 UTC (permalink / raw)
  To: Andre Przywara
  Cc: Alexandre Belloni, Greg Kroah-Hartman, Jiri Slaby, Nicolas Ferre,
	linux-kernel, linux-serial, Uwe Kleine-König,
	linux-arm-kernel

On Thu, Oct 08, 2015 at 03:49:54PM +0100, Andre Przywara wrote:
> Hi,
> 
> On 08/10/15 11:38, Alexandre Belloni wrote:
> > On 08/10/2015 at 10:37:49 +0100, Russell King - ARM Linux wrote :
> >> On Thu, Oct 08, 2015 at 11:01:48AM +0200, Alexandre Belloni wrote:
> >>> On 05/10/2015 at 18:00:52 +0100, Andre Przywara wrote :
> >>>> Turning on KVM and LPAE support on top of a multi_v7_defconfig will
> >>>> produce a compiler warning in the Atmel serial driver:
> >>>> drivers/tty/serial/atmel_serial.c: In function 'atmel_verify_port':
> >>>> drivers/tty/serial/atmel_serial.c:2299:6: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
> >>>>   if ((void *)port->mapbase != ser->iomem_base)
> >>>>       ^
> >>>>
> >>>> Fix that by using the cast on the right hand side instead, as similar
> >>>> code already does in other drivers.
> >>>>
> >>>> Signed-off-by: Andre Przywara <andre.przywara@arm.com>
> >>> Acked-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
> >>
> >> Hmm, this actually points at a problem, and the cast screems out about it.
> >> Think about it, can you guess what it is?
> 
> Russell, I'd really appreciate if we wouldn't have to play
> "guess-what-I-am-thinking" here. Can't you just say what's bothering you?

Actually, I think it's fine - the interface is just another one of the
weird cases we have in the kernel.

However, for the record, things get typed a certain way for a reason.
Virtual addresses that can be dereferenced are generally pointer like.
Physical addresses are generally integers.

Casting between the two generally indicates a bug, and whenever you see
a cast between the two, it should have special attention paid to it to
make sure that it really is correct.

There are a few famous places in the kernel where casting between an
unsigned long and a virtual address is pretty standard, but they're
the exception to the rule (eg, the argument to a timer, get_free_page()).
This is another example.

Sorry for creating confusion.

-- 
FTTC broadband for 0.8mile line: currently at 9.6Mbps down 400kbps up
according to speedtest.net.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2015-10-08 15:01 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-10-05 17:00 [PATCH] serial: atmel: fix compiler warning on address cast Andre Przywara
2015-10-08  9:01 ` Alexandre Belloni
2015-10-08  9:37   ` Russell King - ARM Linux
2015-10-08 10:38     ` Alexandre Belloni
2015-10-08 14:49       ` Andre Przywara
2015-10-08 15:01         ` Russell King - ARM Linux

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).