Skip to contentSkip to conversation

rocker: fix harmless warning on 32-bit machines

PATCH Applied Arnd Bergmann 3 participants 3 messages Jan 13, 2015

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 rocker: fix harmless warning on 32-bit machines

The rocker driver tries to assign a pointer to a 64-bit integer and then back to a pointer. This is safe on all architectures, but causes a compiler warning when pointers are shorter than 64-bit:

rocker/rocker.c: In function 'rocker_desc_cookie_ptr_get':
rocker/rocker.c:809:9: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]

  return (void *) desc_info->desc->cookie;
         ^

This adds another cast to uintptr_t to tell the compiler that it's safe.

drivers/net/ethernet/rocker/rocker.c +2 -2
index 2f398fa4b9e6..cad8cf962cdf 100644
@@ -806,13 +806,13 @@ static bool rocker_desc_gen(struct rocker_desc_info *desc_info)
 
 static void *rocker_desc_cookie_ptr_get(struct rocker_desc_info *desc_info)
 {
-	return (void *) desc_info->desc->cookie;
+	return (void *)(uintptr_t)desc_info->desc->cookie;
 }
 
 static void rocker_desc_cookie_ptr_set(struct rocker_desc_info *desc_info,
 				       void *ptr)
 {
-	desc_info->desc->cookie = (long) ptr;
+	desc_info->desc->cookie = (uintptr_t) ptr;
 }
 
 static struct rocker_desc_info *
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 7 lines · arnd at arndb.de

The rocker driver tries to assign a pointer to a 64-bit integer and then back to a pointer. This is safe on all architectures, but causes a compiler warning when pointers are shorter than 64-bit:

rocker/rocker.c: In function 'rocker_desc_cookie_ptr_get':
rocker/rocker.c:809:9: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]

Quoted 7 lines
 return (void *) desc_info->desc->cookie;
        ^

This adds another cast to uintptr_t to tell the compiler that it's safe.

Quoted 22 lines
drivers/net/ethernet/rocker/rocker.c +2 -2
index 2f398fa4b9e6..cad8cf962cdf 100644
@@ -806,13 +806,13 @@ static bool rocker_desc_gen(struct rocker_desc_info *desc_info)
 
 static void *rocker_desc_cookie_ptr_get(struct rocker_desc_info *desc_info)
 {
-	return (void *) desc_info->desc->cookie;
+	return (void *)(uintptr_t)desc_info->desc->cookie;
 }
 
 static void rocker_desc_cookie_ptr_set(struct rocker_desc_info *desc_info,
 				       void *ptr)
 {
-	desc_info->desc->cookie = (long) ptr;
+	desc_info->desc->cookie = (uintptr_t) ptr;
 }
 

static struct rocker_desc_info *

maintainer Applied
#2 lore raw
In reply to Arnd Bergmann

From: Arnd Bergmann <[email protected]>
Date: Tue, 13 Jan 2015 15:23:52 +0100

Quoted 7 lines

The rocker driver tries to assign a pointer to a 64-bit integer and then back to a pointer. This is safe on all architectures, but causes a compiler warning when pointers are shorter than 64-bit:

rocker/rocker.c: In function 'rocker_desc_cookie_ptr_get':
rocker/rocker.c:809:9: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]

Quoted 7 lines
  return (void *) desc_info->desc->cookie;
         ^

This adds another cast to uintptr_t to tell the compiler that it's safe.

Applied to net-next, thanks.