diff mbox series

net: nixge: fix warnings on 32-bit platforms

Message ID 20180926124808.1867468-1-arnd@arndb.de
State New
Headers show
Series net: nixge: fix warnings on 32-bit platforms | expand

Commit Message

Arnd Bergmann Sept. 26, 2018, 12:47 p.m. UTC
Making it work on 64-bit caused 32-bit builds to regress:

drivers/net/ethernet/ni/nixge.c: In function 'nixge_hw_dma_bd_release':
drivers/net/ethernet/ni/nixge.c:254:9: error: cast to pointer from integer of different size [-Werror=int-to-pointer-cast]
   skb = (struct sk_buff *)
         ^
In file included from include/linux/skbuff.h:17,
                 from include/linux/if_ether.h:23,
                 from include/linux/etherdevice.h:25,
                 from drivers/net/ethernet/ni/nixge.c:7:
drivers/net/ethernet/ni/nixge.c: In function 'nixge_hw_dma_bd_init':
drivers/net/ethernet/ni/nixge.c:130:37: error: cast from pointer to integer of different size [-Werror=pointer-to-int-cast]
   (bd)->field##_lo = lower_32_bits(((u64)addr)); \
                                     ^
include/linux/kernel.h:234:33: note: in definition of macro 'lower_32_bits'
 #define lower_32_bits(n) ((u32)(n))
                                 ^

Casting to a uintptr_t avoids all these warnings.

Fixes: 7e8d5755be0e ("net: nixge: Add support for 64-bit platforms")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>

---
 drivers/net/ethernet/ni/nixge.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

-- 
2.18.0

Comments

Moritz Fischer Sept. 26, 2018, 4:03 p.m. UTC | #1
Hi Arnd,

On Wed, Sep 26, 2018 at 02:47:24PM +0200, Arnd Bergmann wrote:
> Making it work on 64-bit caused 32-bit builds to regress:

> 

> drivers/net/ethernet/ni/nixge.c: In function 'nixge_hw_dma_bd_release':

> drivers/net/ethernet/ni/nixge.c:254:9: error: cast to pointer from integer of different size [-Werror=int-to-pointer-cast]

>    skb = (struct sk_buff *)

>          ^

> In file included from include/linux/skbuff.h:17,

>                  from include/linux/if_ether.h:23,

>                  from include/linux/etherdevice.h:25,

>                  from drivers/net/ethernet/ni/nixge.c:7:

> drivers/net/ethernet/ni/nixge.c: In function 'nixge_hw_dma_bd_init':

> drivers/net/ethernet/ni/nixge.c:130:37: error: cast from pointer to integer of different size [-Werror=pointer-to-int-cast]

>    (bd)->field##_lo = lower_32_bits(((u64)addr)); \

>                                      ^

> include/linux/kernel.h:234:33: note: in definition of macro 'lower_32_bits'

>  #define lower_32_bits(n) ((u32)(n))

>                                  ^

> 

> Casting to a uintptr_t avoids all these warnings.

> 

> Fixes: 7e8d5755be0e ("net: nixge: Add support for 64-bit platforms")

> Signed-off-by: Arnd Bergmann <arnd@arndb.de>

> ---

>  drivers/net/ethernet/ni/nixge.c | 10 +++++-----

>  1 file changed, 5 insertions(+), 5 deletions(-)

> 

> diff --git a/drivers/net/ethernet/ni/nixge.c b/drivers/net/ethernet/ni/nixge.c

> index 74cf52e3fb09..2e132f6a7c36 100644

> --- a/drivers/net/ethernet/ni/nixge.c

> +++ b/drivers/net/ethernet/ni/nixge.c

> @@ -127,8 +127,8 @@ struct nixge_hw_dma_bd {

>  #ifdef CONFIG_PHYS_ADDR_T_64BIT

>  #define nixge_hw_dma_bd_set_addr(bd, field, addr) \

>  	do { \

> -		(bd)->field##_lo = lower_32_bits(((u64)addr)); \

> -		(bd)->field##_hi = upper_32_bits(((u64)addr)); \

> +		(bd)->field##_lo = lower_32_bits(((uintptr_t)addr)); \

> +		(bd)->field##_hi = upper_32_bits(((uintptr_t)addr)); \

>  	} while (0)

>  #else

>  #define nixge_hw_dma_bd_set_addr(bd, field, addr) \

> @@ -251,7 +251,7 @@ static void nixge_hw_dma_bd_release(struct net_device *ndev)

>  				 NIXGE_MAX_JUMBO_FRAME_SIZE,

>  				 DMA_FROM_DEVICE);

>  

> -		skb = (struct sk_buff *)

> +		skb = (struct sk_buff *)(uintptr_t)

>  			nixge_hw_dma_bd_get_addr(&priv->rx_bd_v[i],

>  						 sw_id_offset);

>  		dev_kfree_skb(skb);

> @@ -601,8 +601,8 @@ static int nixge_recv(struct net_device *ndev, int budget)

>  		tail_p = priv->rx_bd_p + sizeof(*priv->rx_bd_v) *

>  			 priv->rx_bd_ci;

>  

> -		skb = (struct sk_buff *)nixge_hw_dma_bd_get_addr(cur_p,

> -								 sw_id_offset);

> +		skb = (struct sk_buff *)(uintptr_t)

> +			nixge_hw_dma_bd_get_addr(cur_p, sw_id_offset);

>  

>  		length = cur_p->status & XAXIDMA_BD_STS_ACTUAL_LEN_MASK;

>  		if (length > NIXGE_MAX_JUMBO_FRAME_SIZE)

> -- 

> 2.18.0

> 


I had submitted a similar patch https://lkml.org/lkml/2018/9/24/1719
here. I should probably add the Fixes tag yours has but other than that
they look largely equivalent. Comments?

Thanks,

Moritz
Arnd Bergmann Sept. 26, 2018, 6:47 p.m. UTC | #2
On Wed, Sep 26, 2018 at 6:03 PM Moritz Fischer <mdf@kernel.org> wrote:
>

> Hi Arnd,

>

> On Wed, Sep 26, 2018 at 02:47:24PM +0200, Arnd Bergmann wrote:

> > Making it work on 64-bit caused 32-bit builds to regress:


> >

>

> I had submitted a similar patch https://lkml.org/lkml/2018/9/24/1719

> here. I should probably add the Fixes tag yours has but other than that

> they look largely equivalent. Comments?


Yes, I'm sure your version is fine as well, sorry for missing that.

Adding a fixes tag is generally a good idea, but no need to resend it.
We just need one of the two to get picked up into net-next.

[note: we both forgot to tag the patch as "[PATCH net-next]"]

       Arnd
diff mbox series

Patch

diff --git a/drivers/net/ethernet/ni/nixge.c b/drivers/net/ethernet/ni/nixge.c
index 74cf52e3fb09..2e132f6a7c36 100644
--- a/drivers/net/ethernet/ni/nixge.c
+++ b/drivers/net/ethernet/ni/nixge.c
@@ -127,8 +127,8 @@  struct nixge_hw_dma_bd {
 #ifdef CONFIG_PHYS_ADDR_T_64BIT
 #define nixge_hw_dma_bd_set_addr(bd, field, addr) \
 	do { \
-		(bd)->field##_lo = lower_32_bits(((u64)addr)); \
-		(bd)->field##_hi = upper_32_bits(((u64)addr)); \
+		(bd)->field##_lo = lower_32_bits(((uintptr_t)addr)); \
+		(bd)->field##_hi = upper_32_bits(((uintptr_t)addr)); \
 	} while (0)
 #else
 #define nixge_hw_dma_bd_set_addr(bd, field, addr) \
@@ -251,7 +251,7 @@  static void nixge_hw_dma_bd_release(struct net_device *ndev)
 				 NIXGE_MAX_JUMBO_FRAME_SIZE,
 				 DMA_FROM_DEVICE);
 
-		skb = (struct sk_buff *)
+		skb = (struct sk_buff *)(uintptr_t)
 			nixge_hw_dma_bd_get_addr(&priv->rx_bd_v[i],
 						 sw_id_offset);
 		dev_kfree_skb(skb);
@@ -601,8 +601,8 @@  static int nixge_recv(struct net_device *ndev, int budget)
 		tail_p = priv->rx_bd_p + sizeof(*priv->rx_bd_v) *
 			 priv->rx_bd_ci;
 
-		skb = (struct sk_buff *)nixge_hw_dma_bd_get_addr(cur_p,
-								 sw_id_offset);
+		skb = (struct sk_buff *)(uintptr_t)
+			nixge_hw_dma_bd_get_addr(cur_p, sw_id_offset);
 
 		length = cur_p->status & XAXIDMA_BD_STS_ACTUAL_LEN_MASK;
 		if (length > NIXGE_MAX_JUMBO_FRAME_SIZE)