All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mm/slob: avoid type warning about alignment value
@ 2012-07-10 20:55 ` Arnd Bergmann
  0 siblings, 0 replies; 8+ messages in thread
From: Arnd Bergmann @ 2012-07-10 20:55 UTC (permalink / raw)
  To: Pekka Enberg; +Cc: Christoph Lameter, linux-kernel, Matt Mackall, linux-mm

The types for ARCH_KMALLOC_MINALIGN and ARCH_SLAB_MINALIGN are not always
the same, as seen by building ARM collie_defconfig:

mm/slob.c: In function 'kfree':
mm/slob.c:482:153: warning: comparison of distinct pointer types lacks a cast
mm/slob.c: In function 'ksize':
mm/slob.c:501:153: warning: comparison of distinct pointer types lacks a cast

Using max_t to find the correct alignment avoids the warning.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
diff --git a/mm/slob.c b/mm/slob.c
index 95d1c7d..51d6a27 100644
--- a/mm/slob.c
+++ b/mm/slob.c
@@ -426,7 +426,7 @@ out:
 void *__kmalloc_node(size_t size, gfp_t gfp, int node)
 {
 	unsigned int *m;
-	int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
+	int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
 	void *ret;
 
 	gfp &= gfp_allowed_mask;
@@ -479,7 +479,7 @@ void kfree(const void *block)
 
 	sp = virt_to_page(block);
 	if (PageSlab(sp)) {
-		int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
+		int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
 		unsigned int *m = (unsigned int *)(block - align);
 		slob_free(m, *m + align);
 	} else
@@ -498,7 +498,7 @@ size_t ksize(const void *block)
 
 	sp = virt_to_page(block);
 	if (PageSlab(sp)) {
-		int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
+		int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
 		unsigned int *m = (unsigned int *)(block - align);
 		return SLOB_UNITS(*m) * SLOB_UNIT;
 	} else

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

* [PATCH] mm/slob: avoid type warning about alignment value
@ 2012-07-10 20:55 ` Arnd Bergmann
  0 siblings, 0 replies; 8+ messages in thread
From: Arnd Bergmann @ 2012-07-10 20:55 UTC (permalink / raw)
  To: Pekka Enberg; +Cc: Christoph Lameter, linux-kernel, Matt Mackall, linux-mm

The types for ARCH_KMALLOC_MINALIGN and ARCH_SLAB_MINALIGN are not always
the same, as seen by building ARM collie_defconfig:

mm/slob.c: In function 'kfree':
mm/slob.c:482:153: warning: comparison of distinct pointer types lacks a cast
mm/slob.c: In function 'ksize':
mm/slob.c:501:153: warning: comparison of distinct pointer types lacks a cast

Using max_t to find the correct alignment avoids the warning.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
diff --git a/mm/slob.c b/mm/slob.c
index 95d1c7d..51d6a27 100644
--- a/mm/slob.c
+++ b/mm/slob.c
@@ -426,7 +426,7 @@ out:
 void *__kmalloc_node(size_t size, gfp_t gfp, int node)
 {
 	unsigned int *m;
-	int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
+	int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
 	void *ret;
 
 	gfp &= gfp_allowed_mask;
@@ -479,7 +479,7 @@ void kfree(const void *block)
 
 	sp = virt_to_page(block);
 	if (PageSlab(sp)) {
-		int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
+		int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
 		unsigned int *m = (unsigned int *)(block - align);
 		slob_free(m, *m + align);
 	} else
@@ -498,7 +498,7 @@ size_t ksize(const void *block)
 
 	sp = virt_to_page(block);
 	if (PageSlab(sp)) {
-		int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
+		int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
 		unsigned int *m = (unsigned int *)(block - align);
 		return SLOB_UNITS(*m) * SLOB_UNIT;
 	} else

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

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

* Re: [PATCH] mm/slob: avoid type warning about alignment value
  2012-07-10 20:55 ` Arnd Bergmann
@ 2012-07-11  1:18   ` David Rientjes
  -1 siblings, 0 replies; 8+ messages in thread
From: David Rientjes @ 2012-07-11  1:18 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Pekka Enberg, Christoph Lameter, linux-kernel, Matt Mackall, linux-mm

On Tue, 10 Jul 2012, Arnd Bergmann wrote:

> diff --git a/mm/slob.c b/mm/slob.c
> index 95d1c7d..51d6a27 100644
> --- a/mm/slob.c
> +++ b/mm/slob.c
> @@ -426,7 +426,7 @@ out:
>  void *__kmalloc_node(size_t size, gfp_t gfp, int node)
>  {
>  	unsigned int *m;
> -	int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
> +	int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
>  	void *ret;
>  
>  	gfp &= gfp_allowed_mask;
> @@ -479,7 +479,7 @@ void kfree(const void *block)
>  
>  	sp = virt_to_page(block);
>  	if (PageSlab(sp)) {
> -		int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
> +		int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
>  		unsigned int *m = (unsigned int *)(block - align);
>  		slob_free(m, *m + align);
>  	} else
> @@ -498,7 +498,7 @@ size_t ksize(const void *block)
>  
>  	sp = virt_to_page(block);
>  	if (PageSlab(sp)) {
> -		int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
> +		int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
>  		unsigned int *m = (unsigned int *)(block - align);
>  		return SLOB_UNITS(*m) * SLOB_UNIT;
>  	} else

Wouldn't it be better to avoid this problem more generally by casting the 
__alignof__ for ARCH_{KMALLOC,SLAB}_MINALIGN to int in slab.h?  All 
architectures that define these themselves will be using plain integers, 
the problem is __alignof__ returning size_t when undefined.

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

* Re: [PATCH] mm/slob: avoid type warning about alignment value
@ 2012-07-11  1:18   ` David Rientjes
  0 siblings, 0 replies; 8+ messages in thread
From: David Rientjes @ 2012-07-11  1:18 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Pekka Enberg, Christoph Lameter, linux-kernel, Matt Mackall, linux-mm

On Tue, 10 Jul 2012, Arnd Bergmann wrote:

> diff --git a/mm/slob.c b/mm/slob.c
> index 95d1c7d..51d6a27 100644
> --- a/mm/slob.c
> +++ b/mm/slob.c
> @@ -426,7 +426,7 @@ out:
>  void *__kmalloc_node(size_t size, gfp_t gfp, int node)
>  {
>  	unsigned int *m;
> -	int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
> +	int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
>  	void *ret;
>  
>  	gfp &= gfp_allowed_mask;
> @@ -479,7 +479,7 @@ void kfree(const void *block)
>  
>  	sp = virt_to_page(block);
>  	if (PageSlab(sp)) {
> -		int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
> +		int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
>  		unsigned int *m = (unsigned int *)(block - align);
>  		slob_free(m, *m + align);
>  	} else
> @@ -498,7 +498,7 @@ size_t ksize(const void *block)
>  
>  	sp = virt_to_page(block);
>  	if (PageSlab(sp)) {
> -		int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
> +		int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
>  		unsigned int *m = (unsigned int *)(block - align);
>  		return SLOB_UNITS(*m) * SLOB_UNIT;
>  	} else

Wouldn't it be better to avoid this problem more generally by casting the 
__alignof__ for ARCH_{KMALLOC,SLAB}_MINALIGN to int in slab.h?  All 
architectures that define these themselves will be using plain integers, 
the problem is __alignof__ returning size_t when undefined.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

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

* Re: [PATCH] mm/slob: avoid type warning about alignment value
  2012-07-11  1:18   ` David Rientjes
@ 2012-07-11  6:39     ` Arnd Bergmann
  -1 siblings, 0 replies; 8+ messages in thread
From: Arnd Bergmann @ 2012-07-11  6:39 UTC (permalink / raw)
  To: David Rientjes
  Cc: Pekka Enberg, Christoph Lameter, linux-kernel, Matt Mackall, linux-mm

On Wednesday 11 July 2012, David Rientjes wrote:
> Wouldn't it be better to avoid this problem more generally by casting the 
> __alignof__ for ARCH_{KMALLOC,SLAB}_MINALIGN to int in slab.h?  All 
> architectures that define these themselves will be using plain integers, 
> the problem is __alignof__ returning size_t when undefined.

I thought about it but I wasn't sure if that would cover all possible
cases. My version at least is known not to introduce a different type
mismatch on another architecture.

Also, size_t seems to be the correct type here, while the untyped
definition is just an int.

	Arnd

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

* Re: [PATCH] mm/slob: avoid type warning about alignment value
@ 2012-07-11  6:39     ` Arnd Bergmann
  0 siblings, 0 replies; 8+ messages in thread
From: Arnd Bergmann @ 2012-07-11  6:39 UTC (permalink / raw)
  To: David Rientjes
  Cc: Pekka Enberg, Christoph Lameter, linux-kernel, Matt Mackall, linux-mm

On Wednesday 11 July 2012, David Rientjes wrote:
> Wouldn't it be better to avoid this problem more generally by casting the 
> __alignof__ for ARCH_{KMALLOC,SLAB}_MINALIGN to int in slab.h?  All 
> architectures that define these themselves will be using plain integers, 
> the problem is __alignof__ returning size_t when undefined.

I thought about it but I wasn't sure if that would cover all possible
cases. My version at least is known not to introduce a different type
mismatch on another architecture.

Also, size_t seems to be the correct type here, while the untyped
definition is just an int.

	Arnd

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

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

* Re: [PATCH] mm/slob: avoid type warning about alignment value
  2012-07-11  6:39     ` Arnd Bergmann
@ 2012-07-11 20:42       ` David Rientjes
  -1 siblings, 0 replies; 8+ messages in thread
From: David Rientjes @ 2012-07-11 20:42 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Pekka Enberg, Christoph Lameter, linux-kernel, Matt Mackall, linux-mm

On Wed, 11 Jul 2012, Arnd Bergmann wrote:

> Also, size_t seems to be the correct type here, while the untyped
> definition is just an int.
> 

Ok, sounds good, thanks.

Acked-by: David Rientjes <rientjes@google.com>

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

* Re: [PATCH] mm/slob: avoid type warning about alignment value
@ 2012-07-11 20:42       ` David Rientjes
  0 siblings, 0 replies; 8+ messages in thread
From: David Rientjes @ 2012-07-11 20:42 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Pekka Enberg, Christoph Lameter, linux-kernel, Matt Mackall, linux-mm

On Wed, 11 Jul 2012, Arnd Bergmann wrote:

> Also, size_t seems to be the correct type here, while the untyped
> definition is just an int.
> 

Ok, sounds good, thanks.

Acked-by: David Rientjes <rientjes@google.com>

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

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

end of thread, other threads:[~2012-07-11 20:43 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-07-10 20:55 [PATCH] mm/slob: avoid type warning about alignment value Arnd Bergmann
2012-07-10 20:55 ` Arnd Bergmann
2012-07-11  1:18 ` David Rientjes
2012-07-11  1:18   ` David Rientjes
2012-07-11  6:39   ` Arnd Bergmann
2012-07-11  6:39     ` Arnd Bergmann
2012-07-11 20:42     ` David Rientjes
2012-07-11 20:42       ` David Rientjes

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.