public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Figo.zhang" <figo1802@gmail.com>
To: Ingo Molnar <mingo@elte.hu>
Cc: Linus Torvalds <torvalds@linux-foundation.org>,
	Andrew Morton <akpm@osdl.org>,
	lkml <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH]mempool.c : clean up type-casting twice
Date: Sun, 05 Jul 2009 11:11:56 +0800	[thread overview]
Message-ID: <1246763517.15308.10.camel@myhost> (raw)
In-Reply-To: <20090705030100.GA9341@elte.hu>

On Sun, 2009-07-05 at 05:01 +0200, Ingo Molnar wrote:
> * Figo.zhang <figo1802@gmail.com> wrote:
> 
> > clean up type-casting twice
> > 
> > Signed-off-by: Figo.zhang <figo1802@gmail.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.
> 

thanks.


void *mempool_kmalloc(gfp_t gfp_mask, void *pool_data)
{
	size_t size = (size_t)(long)pool_data;
	return kmalloc(size, gfp_mask);
}

void *mempool_kzalloc(gfp_t gfp_mask, void *pool_data)
{
	size_t size = (size_t) pool_data;
	return kzalloc(size, gfp_mask);
}

at this point, is it no need for type-casting twice ? because size_t is
typedef "unsigned int" in x86_32, "unsigned long " in x86_64.

Best,
Figo.zhang


  reply	other threads:[~2009-07-05  3:12 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-07-05  2:48 [PATCH]mempool.c : clean up type-casting twice Figo.zhang
2009-07-05  3:01 ` Ingo Molnar
2009-07-05  3:11   ` Figo.zhang [this message]
2009-07-05  4:04 ` [PATCH v2]mempool.c " Figo.zhang
2009-07-05  8:48   ` Ingo Molnar
2009-07-05  9:01   ` [PATCH v3]mempool.c " Figo.zhang
2009-07-05  9:04     ` Ingo Molnar
2009-07-05  9:13       ` Figo.zhang
2009-07-05  9:20     ` [PATCH v4]mempool.c " Figo.zhang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1246763517.15308.10.camel@myhost \
    --to=figo1802@gmail.com \
    --cc=akpm@osdl.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=torvalds@linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox