mempool.c : clean up type-casting twice
Subsystems (2)
PATCH 1/1 mempool.c : clean up type-casting twice
clean up type-casting twice
---mm/mempool.c | 6 +++---
1 files changed, 3 insertions(+), 3 deletions(-)
mm/mempool.c +3 -3
@@ -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); }EXPORT_SYMBOL (mempool_free_pages);
Quoted 25 lines · Figo.zhang
clean up type-casting twice
Signed-off-by Figo.zhang <[email protected]>---
mm/mempool.c| 6 +++---1 files changed, 3 insertions(+), 3 deletions(-)mm/mempool.c +1
-2@@ -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;
mm/mempool.c EXPORT_SYMBOL(mempool_kfree); · line 338
Quoted 10 lines
mm/mempool.c +2
-1+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
Quoted 40 lines · Ingo Molnar
Quoted 25 lines · Figo.zhang
clean up type-casting twice
Signed-off-by Figo.zhang <[email protected]>---
mm/mempool.c| 6 +++---1 files changed, 3 insertions(+), 3 deletions(-)mm/mempool.c +1
-2@@ -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;mm/mempool.c EXPORT_SYMBOL(mempool_kfree); · line 338
Quoted 10 lines
mm/mempool.c +2
-1+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?
Quoted 8 lines
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
PATCH v2 1/1 mempool.c : clean up type-casting twice
In reply to Figo.zhangclean up type-casting twice. "size_t" typedef as "unsigned long" in 64-bit system, and "unsigned int" in 32-bit system.
---mm/mempool.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
mm/mempool.c +1 -1
@@ -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);
Quoted 13 lines · Figo.zhang
clean up type-casting twice. "
size_t" typedef as "unsigned long" in 64-bit system, and "unsigned int" in 32-bit system.Signed-off-by Figo.zhang <[email protected]>---
mm/mempool.c| 2 +-1 files changed, 1 insertions(+), 1 deletions(-)mm/mempool.c +0
-0
mm/mempool.c EXPORT_SYMBOL(mempool_free_slab); · line 309
Quoted 8 lines
mm/mempool.c +1
-1@@ -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);
(Style detail: please dont add spaces to casts. That should be fixed in mempool_kzalloc() too btw.)
Looks good otherwise - size_t ought to be long on all 64-bit architectures.
Ingo
PATCH v3 1/1 mempool.c : clean up type-casting twice
In reply to Figo.zhangclean up type-casting twice. "size_t" typedef as "unsigned long" in 64-bit system, and "unsigned int" in 32-bit system.
in v3, remove the space to casts.
---mm/mempool.c | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
mm/mempool.c +2 -2
@@ -303,14 +303,14 @@ 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);void *mempool_kzalloc (gfp_t gfp_mask,void *pool_data) { -size_t size = (size_t ) pool_data; +size_t size = (size_t )pool_data;return kzalloc (size, gfp_mask); }EXPORT_SYMBOL (mempool_kzalloc);
Quoted 2 lines · Figo.zhang
clean up type-casting twice. "
size_t" typedef as "unsigned long" in 64-bit system, and "unsigned int" in 32-bit system.
[
You should line-length limit your changelogs btw., to 60 characters or so. git log will add another 4 characters. The ~/.vimrc magic for this is:
autocmd BufNewFile,BufRead *.patch setlocal textwidth=60
]
Quoted 19 lines
in v3, remove the space to casts.
Signed-off-by Figo.zhang <[email protected]>---
mm/mempool.c| 4 ++--1 files changed, 2 insertions(+), 2 deletions(-)mm/mempool.c +1
-1@@ -303,14 +303,14 @@ 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);
mm/mempool.c EXPORT_SYMBOL(mempool_free_slab); · line 316
Quoted 10 lines
mm/mempool.c +1
-1}EXPORT_SYMBOL (mempool_kmalloc);void *mempool_kzalloc (gfp_t gfp_mask,void *pool_data) { -size_t size = (size_t ) pool_data; +size_t size = (size_t )pool_data;return kzalloc (size, gfp_mask); }EXPORT_SYMBOL (mempool_kzalloc);
Ingo
Quoted 5 lines · Ingo Molnar
Quoted 2 lines · Figo.zhang
clean up type-casting twice. "
size_t" typedef as "unsigned long" in 64-bit system, and "unsigned int" in 32-bit system.
Quoted 7 lines
[
You should line-length limit your changelogs btw., to 60 characters or so. git log will add another 4 characters. The ~/.vimrc magic for this is:autocmd BufNewFile,BufRead *.patch setlocal textwidth=60
]
hi,Ingo,
Thanks a lot.
should i motify the log, and send it again?
Best,
Figo.zhang
Quoted 34 lines
Quoted 20 lines
in v3, remove the space to casts.
Signed-off-by Figo.zhang <[email protected]>---
mm/mempool.c| 4 ++--1 files changed, 2 insertions(+), 2 deletions(-)mm/mempool.c +1
-1@@ -303,14 +303,14 @@ 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);mm/mempool.c EXPORT_SYMBOL(mempool_free_slab); · line 316
Quoted 10 lines
mm/mempool.c +1
-1}EXPORT_SYMBOL (mempool_kmalloc);void *mempool_kzalloc (gfp_t gfp_mask,void *pool_data) { -size_t size = (size_t ) pool_data; +size_t size = (size_t )pool_data;return kzalloc (size, gfp_mask); }EXPORT_SYMBOL (mempool_kzalloc);Acked-by Ingo Molnar <[email protected]>Ingo
PATCH v4 1/1 mempool.c : clean up type-casting twice
In reply to Figo.zhangclean up type-casting twice. "size_t" typedef as "unsigned long" in 64-bit system, and "unsigned int" in 32-bit system.
in v3, remove the space to casts.
in v4, change the line-length limit for git log.
---
mm/mempool.c | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
mm/mempool.c +2 -2
@@ -303,14 +303,14 @@ 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);void *mempool_kzalloc (gfp_t gfp_mask,void *pool_data) { -size_t size = (size_t ) pool_data; +size_t size = (size_t )pool_data;return kzalloc (size, gfp_mask); }EXPORT_SYMBOL (mempool_kzalloc);