[U-Boot] [Patch v2 08/16] net/fm: fix compile warnings for 64-bit platform

Scott Wood scottwood at freescale.com
Thu Sep 17 20:13:44 CEST 2015


On Thu, 2015-09-17 at 15:06 +0800, Gong Qianyu wrote:
> This patch fixes such compile warnings:
> 
> drivers/net/fm/eth.c: In function 'fm_eth_recv':
> drivers/net/fm/eth.c:549:11: warning: cast to pointer from integer of
> different size [-Wint-to-pointer-cast]
>       data = (u8 *)in_be32(&rxbd->buf_ptr_lo);
> drivers/net/fm/fm.c: In function 'fm_muram_alloc':
> drivers/net/fm/fm.c:52:9: warning: cast to pointer from integer of
> different size [-Wint-to-pointer-cast]
>       memset((void *)ret, 0, size);
> drivers/net/fm/fm.c: In function 'fm_init_muram':
> drivers/net/fm/fm.c:59:13: warning: cast from pointer to integer of
> different size [-Wpointer-to-int-cast]
>       u32 base = (u32)reg;
> 
> Just make the cast explicit for them.
> 
> Signed-off-by: Gong Qianyu <Qianyu.Gong at freescale.com>
> ---
>  drivers/net/fm/eth.c | 31 ++++++++++++++++---------------
>  drivers/net/fm/fm.c  |  4 ++--
>  2 files changed, 18 insertions(+), 17 deletions(-)
> 
> diff --git a/drivers/net/fm/eth.c b/drivers/net/fm/eth.c
> index 12eb9b8..6ef0afb 100644
> --- a/drivers/net/fm/eth.c
> +++ b/drivers/net/fm/eth.c
> @@ -120,12 +120,12 @@ static int tgec_is_fibre(struct eth_device *dev)
>  
>  static u16 muram_readw(u16 *addr)
>  {
> -     u32 base = (u32)addr & ~0x3;
> +     ulong base = (ulong)addr & ~0x3;

This will still truncate the address at 32 bits.  It needs to be ~0x3UL.


>       u32 val32 = in_be32((u32 *)base);
>       int byte_pos;
>       u16 ret;
>  
> -     byte_pos = (u32)addr & 0x3;
> +     byte_pos = (ulong)addr & 0x3;
>       if (byte_pos)
>               ret = (u16)(val32 & 0x0000ffff);
>       else
> @@ -136,12 +136,12 @@ static u16 muram_readw(u16 *addr)
>  
>  static void muram_writew(u16 *addr, u16 val)
>  {
> -     u32 base = (u32)addr & ~0x3;
> +     ulong base = (ulong)addr & ~0x3;
>       u32 org32 = in_be32((u32 *)base);
>       u32 val32;
>       int byte_pos;
>  
> -     byte_pos = (u32)addr & 0x3;
> +     byte_pos = (ulong)addr & 0x3;
>       if (byte_pos)
>               val32 = (org32 & 0xffff0000) | val;
>       else
> @@ -217,12 +217,12 @@ static int fm_eth_rx_port_parameter_init(struct 
> fm_eth *fm_eth)
>       int i;
>  
>       /* alloc global parameter ram at MURAM */
> -     pram = (struct fm_port_global_pram *)fm_muram_alloc(fm_eth->fm_index,
> -             FM_PRAM_SIZE, FM_PRAM_ALIGN);
> +     pram = (struct fm_port_global_pram *)(ulong)fm_muram_alloc(
> +                     fm_eth->fm_index, FM_PRAM_SIZE, FM_PRAM_ALIGN);

Make fm_muram_alloc() return a pointer instead.  If muram were >= 4 GiB the 
above would fail.

>       fm_eth->rx_pram = pram;
>  
>       /* parameter page offset to MURAM */
> -     pram_page_offset = (u32)pram - fm_muram_base(fm_eth->fm_index);
> +     pram_page_offset = (u32)(ulong)pram - fm_muram_base(fm_eth->fm_index);

Get rid of the u32 cast -- again, if the muram base were above >= 4 GiB this 
would fail because you're dropping the high bits before the subtraction 
rather than after.

>  
>       /* enable global mode- snooping data buffers and BDs */
>       out_be32(&pram->mode, PRAM_MODE_GLOBAL);
> @@ -258,7 +258,8 @@ static int fm_eth_rx_port_parameter_init(struct fm_eth 
> *fm_eth)
>               muram_writew(&rxbd->status, RxBD_EMPTY);
>               muram_writew(&rxbd->len, 0);
>               muram_writew(&rxbd->buf_ptr_hi, 0);
> -             out_be32(&rxbd->buf_ptr_lo, (u32)rx_buf_pool + i * MAX_RXBUF_LEN);
> +             out_be32(&rxbd->buf_ptr_lo, (u32)(ulong)rx_buf_pool +
> +                                                     i * MAX_RXBUF_LEN);
>               rxbd++;

Use virt_to_phys() and lower_32_bits().  Is there a "hi" register to handle 
the upper 32 bits?

Likewise elsewhere.  Don't just apply the minimum bandage to get rid of the 
warning.  Make the code actually be 64-bit clean.

-Scott



More information about the U-Boot mailing list