lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:	Sun, 5 Jul 2009 05:01:00 +0200
From:	Ingo Molnar <mingo@...e.hu>
To:	"Figo.zhang" <figo1802@...il.com>
Cc:	Linus Torvalds <torvalds@...ux-foundation.org>,
	Andrew Morton <akpm@...l.org>,
	lkml <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH]mempool.c : clean up type-casting twice


* Figo.zhang <figo1802@...il.com> wrote:

> clean up type-casting twice
> 
> Signed-off-by: Figo.zhang <figo1802@...il.com>
> ---   
> mm/mempool.c |    6 +++---
>  1 files changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/mm/mempool.c b/mm/mempool.c
> index a46eb1b..0aec628 100644
> --- a/mm/mempool.c
> +++ b/mm/mempool.c
> @@ -303,7 +303,7 @@ EXPORT_SYMBOL(mempool_free_slab);
>   */
>  void *mempool_kmalloc(gfp_t gfp_mask, void *pool_data)
>  {
> -	size_t size = (size_t)(long)pool_data;
> +	size_t size = (size_t)pool_data;
>  	return kmalloc(size, gfp_mask);
>  }
>  EXPORT_SYMBOL(mempool_kmalloc);
> @@ -327,14 +327,14 @@ EXPORT_SYMBOL(mempool_kfree);
>   */
>  void *mempool_alloc_pages(gfp_t gfp_mask, void *pool_data)
>  {
> -	int order = (int)(long)pool_data;
> +	int order = (int)pool_data;
>  	return alloc_pages(gfp_mask, order);
>  }
>  EXPORT_SYMBOL(mempool_alloc_pages);
>  
>  void mempool_free_pages(void *element, void *pool_data)
>  {
> -	int order = (int)(long)pool_data;
> +	int order = (int)pool_data;
>  	__free_pages(element, order);

What's the motivation?

On 64-bit platforms, casting from a pointer (64-bit) straight to int 
(32-bit) can lose information and is thus a potential source of 
bugs, so certain compilers will warn about it with:

   warning: cast from pointer to integer of different size

The double cast is a "I know what I'm doing" signal.

	Ingo
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists