linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] vmalloc: use ZERO_SIZE_PTR / ZERO_OR_NULL_PTR
@ 2012-02-28  9:33 Dmitry Antipov
  2012-02-28  9:34 ` [PATCH 2/2] module: use ZERO_OR_NULL_PTR allocation pointer checking Dmitry Antipov
  2012-02-28  9:44 ` [PATCH 1/2] vmalloc: use ZERO_SIZE_PTR / ZERO_OR_NULL_PTR Dan Carpenter
  0 siblings, 2 replies; 8+ messages in thread
From: Dmitry Antipov @ 2012-02-28  9:33 UTC (permalink / raw)
  To: Rusty Russell, Andrew Morton
  Cc: linux-kernel, linux-mm, linaro-dev, patches, Dmitry Antipov

 - Fix vmap() to return ZERO_SIZE_PTR if 0 pages are requested;
 - fix __vmalloc_node_range() to return ZERO_SIZE_PTR if 0 bytes
   are requested;
 - fix __vunmap() to check passed pointer with ZERO_OR_NULL_PTR.

Signed-off-by: Dmitry Antipov <dmitry.antipov@linaro.org>
---
 mm/vmalloc.c |   10 +++++++---
 1 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/mm/vmalloc.c b/mm/vmalloc.c
index 86ce9a5..040a9cd 100644
--- a/mm/vmalloc.c
+++ b/mm/vmalloc.c
@@ -1456,7 +1456,7 @@ static void __vunmap(const void *addr, int deallocate_pages)
 {
 	struct vm_struct *area;
 
-	if (!addr)
+	if (unlikely(ZERO_OR_NULL_PTR(addr)))
 		return;
 
 	if ((PAGE_SIZE-1) & (unsigned long)addr) {
@@ -1548,7 +1548,9 @@ void *vmap(struct page **pages, unsigned int count,
 
 	might_sleep();
 
-	if (count > totalram_pages)
+	if (unlikely(!count))
+		return ZERO_SIZE_PTR;
+	if (unlikely(count > totalram_pages))
 		return NULL;
 
 	area = get_vm_area_caller((count << PAGE_SHIFT), flags,
@@ -1648,8 +1650,10 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
 	void *addr;
 	unsigned long real_size = size;
 
+	if (unlikely(!size))
+		return ZERO_SIZE_PTR;
 	size = PAGE_ALIGN(size);
-	if (!size || (size >> PAGE_SHIFT) > totalram_pages)
+	if (unlikely((size >> PAGE_SHIFT) > totalram_pages))
 		goto fail;
 
 	area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST,
-- 
1.7.7.6


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

* [PATCH 2/2] module: use ZERO_OR_NULL_PTR allocation pointer checking
  2012-02-28  9:33 [PATCH 1/2] vmalloc: use ZERO_SIZE_PTR / ZERO_OR_NULL_PTR Dmitry Antipov
@ 2012-02-28  9:34 ` Dmitry Antipov
  2012-02-28  9:44 ` [PATCH 1/2] vmalloc: use ZERO_SIZE_PTR / ZERO_OR_NULL_PTR Dan Carpenter
  1 sibling, 0 replies; 8+ messages in thread
From: Dmitry Antipov @ 2012-02-28  9:34 UTC (permalink / raw)
  To: Rusty Russell, Andrew Morton
  Cc: linux-kernel, linux-mm, linaro-dev, patches, Dmitry Antipov

Use ZERO_OR_NULL_PTR allocation pointer checking where allocation
function may return ZERO_SIZE_PTR.
---
 kernel/module.c |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/kernel/module.c b/kernel/module.c
index 2c93276..ae438db 100644
--- a/kernel/module.c
+++ b/kernel/module.c
@@ -2322,14 +2322,14 @@ static void dynamic_debug_remove(struct _ddebug *debug)
 
 void * __weak module_alloc(unsigned long size)
 {
-	return size == 0 ? NULL : vmalloc_exec(size);
+	return vmalloc_exec(size);
 }
 
 static void *module_alloc_update_bounds(unsigned long size)
 {
 	void *ret = module_alloc(size);
 
-	if (ret) {
+	if (likely(!ZERO_OR_NULL_PTR(ret))) {
 		mutex_lock(&module_mutex);
 		/* Update module bounds. */
 		if ((unsigned long)ret < module_addr_min)
@@ -2638,7 +2638,7 @@ static int move_module(struct module *mod, struct load_info *info)
 	 * leak.
 	 */
 	kmemleak_not_leak(ptr);
-	if (!ptr)
+	if (unlikely(ZERO_OR_NULL_PTR(ptr)))
 		return -ENOMEM;
 
 	memset(ptr, 0, mod->core_size);
@@ -2652,7 +2652,7 @@ static int move_module(struct module *mod, struct load_info *info)
 	 * after the module is initialized.
 	 */
 	kmemleak_ignore(ptr);
-	if (!ptr && mod->init_size) {
+	if (unlikely(ZERO_OR_NULL_PTR(ptr))) {
 		module_free(mod, mod->module_core);
 		return -ENOMEM;
 	}
-- 
1.7.7.6


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

* Re: [PATCH 1/2] vmalloc: use ZERO_SIZE_PTR / ZERO_OR_NULL_PTR
  2012-02-28  9:33 [PATCH 1/2] vmalloc: use ZERO_SIZE_PTR / ZERO_OR_NULL_PTR Dmitry Antipov
  2012-02-28  9:34 ` [PATCH 2/2] module: use ZERO_OR_NULL_PTR allocation pointer checking Dmitry Antipov
@ 2012-02-28  9:44 ` Dan Carpenter
  2012-02-28 11:59   ` Dmitry Antipov
  1 sibling, 1 reply; 8+ messages in thread
From: Dan Carpenter @ 2012-02-28  9:44 UTC (permalink / raw)
  To: Dmitry Antipov
  Cc: Rusty Russell, Andrew Morton, linux-kernel, linux-mm, linaro-dev,
	patches

[-- Attachment #1: Type: text/plain, Size: 399 bytes --]

On Tue, Feb 28, 2012 at 01:33:59PM +0400, Dmitry Antipov wrote:
>  - Fix vmap() to return ZERO_SIZE_PTR if 0 pages are requested;
>  - fix __vmalloc_node_range() to return ZERO_SIZE_PTR if 0 bytes
>    are requested;
>  - fix __vunmap() to check passed pointer with ZERO_OR_NULL_PTR.
> 

Why?

Also patch 2/2 should go in before patch 1/2 or it breaks things.

regards,
dan carpenter


[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

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

* Re: [PATCH 1/2] vmalloc: use ZERO_SIZE_PTR / ZERO_OR_NULL_PTR
  2012-02-28  9:44 ` [PATCH 1/2] vmalloc: use ZERO_SIZE_PTR / ZERO_OR_NULL_PTR Dan Carpenter
@ 2012-02-28 11:59   ` Dmitry Antipov
  2012-02-28 13:30     ` Dan Carpenter
  0 siblings, 1 reply; 8+ messages in thread
From: Dmitry Antipov @ 2012-02-28 11:59 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Rusty Russell, Andrew Morton, linux-kernel, linux-mm, linaro-dev,
	patches

On 02/28/2012 01:44 PM, Dan Carpenter wrote:
> On Tue, Feb 28, 2012 at 01:33:59PM +0400, Dmitry Antipov wrote:
>>   - Fix vmap() to return ZERO_SIZE_PTR if 0 pages are requested;
>>   - fix __vmalloc_node_range() to return ZERO_SIZE_PTR if 0 bytes
>>     are requested;
>>   - fix __vunmap() to check passed pointer with ZERO_OR_NULL_PTR.
>>
>
> Why?

1) it was requested by the subsystem (co?)maintainer, see http://lkml.org/lkml/2012/1/27/475;
2) this looks to be a convenient way to trace/debug zero-size allocation errors (although
    I don't advocate it as a best way).

Dmitry

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

* Re: [PATCH 1/2] vmalloc: use ZERO_SIZE_PTR / ZERO_OR_NULL_PTR
  2012-02-28 11:59   ` Dmitry Antipov
@ 2012-02-28 13:30     ` Dan Carpenter
  2012-02-29  6:53       ` Dmitry Antipov
  0 siblings, 1 reply; 8+ messages in thread
From: Dan Carpenter @ 2012-02-28 13:30 UTC (permalink / raw)
  To: Dmitry Antipov
  Cc: Rusty Russell, Andrew Morton, linux-kernel, linux-mm, linaro-dev,
	patches

[-- Attachment #1: Type: text/plain, Size: 777 bytes --]

On Tue, Feb 28, 2012 at 03:59:25PM +0400, Dmitry Antipov wrote:
> On 02/28/2012 01:44 PM, Dan Carpenter wrote:
> >On Tue, Feb 28, 2012 at 01:33:59PM +0400, Dmitry Antipov wrote:
> >>  - Fix vmap() to return ZERO_SIZE_PTR if 0 pages are requested;
> >>  - fix __vmalloc_node_range() to return ZERO_SIZE_PTR if 0 bytes
> >>    are requested;
> >>  - fix __vunmap() to check passed pointer with ZERO_OR_NULL_PTR.
> >>
> >
> >Why?
> 
> 1) it was requested by the subsystem (co?)maintainer, see http://lkml.org/lkml/2012/1/27/475;
> 2) this looks to be a convenient way to trace/debug zero-size allocation errors (although
>    I don't advocate it as a best way).

Could you include that in the changelog when the final version is
ready?

regards,
dan carpenter

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

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

* Re: [PATCH 1/2] vmalloc: use ZERO_SIZE_PTR / ZERO_OR_NULL_PTR
  2012-02-28 13:30     ` Dan Carpenter
@ 2012-02-29  6:53       ` Dmitry Antipov
  2012-02-29  7:10         ` Dan Carpenter
  2012-02-29  8:29         ` Amit Kucheria
  0 siblings, 2 replies; 8+ messages in thread
From: Dmitry Antipov @ 2012-02-29  6:53 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Rusty Russell, Andrew Morton, linux-kernel, linux-mm, linaro-dev,
	patches

On 02/28/2012 05:30 PM, Dan Carpenter wrote:

> Could you include that in the changelog when the final version is
> ready?

What changelog you're saying about?

Dmitry

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

* Re: [PATCH 1/2] vmalloc: use ZERO_SIZE_PTR / ZERO_OR_NULL_PTR
  2012-02-29  6:53       ` Dmitry Antipov
@ 2012-02-29  7:10         ` Dan Carpenter
  2012-02-29  8:29         ` Amit Kucheria
  1 sibling, 0 replies; 8+ messages in thread
From: Dan Carpenter @ 2012-02-29  7:10 UTC (permalink / raw)
  To: Dmitry Antipov
  Cc: Rusty Russell, Andrew Morton, linux-kernel, linux-mm, linaro-dev,
	patches

[-- Attachment #1: Type: text/plain, Size: 549 bytes --]

On Wed, Feb 29, 2012 at 10:53:13AM +0400, Dmitry Antipov wrote:
> On 02/28/2012 05:30 PM, Dan Carpenter wrote:
> 
> >Could you include that in the changelog when the final version is
> >ready?
> 
> What changelog you're saying about?
> 

The commit message to this patch.  Right now it just says "fix
vmalloc" but it doesn't say what the bug is or why the new version
is better.  You and Rusty know the reasons already but we should
write them down in the changelog so other people can follow along as
well.

regards,
dan carpenter

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

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

* Re: [PATCH 1/2] vmalloc: use ZERO_SIZE_PTR / ZERO_OR_NULL_PTR
  2012-02-29  6:53       ` Dmitry Antipov
  2012-02-29  7:10         ` Dan Carpenter
@ 2012-02-29  8:29         ` Amit Kucheria
  1 sibling, 0 replies; 8+ messages in thread
From: Amit Kucheria @ 2012-02-29  8:29 UTC (permalink / raw)
  To: Dmitry Antipov
  Cc: Dan Carpenter, linaro-dev, patches, linux-kernel, linux-mm,
	Rusty Russell, Andrew Morton

On Wed, Feb 29, 2012 at 8:53 AM, Dmitry Antipov
<dmitry.antipov@linaro.org> wrote:
> On 02/28/2012 05:30 PM, Dan Carpenter wrote:
>
>> Could you include that in the changelog when the final version is
>> ready?
>
>
> What changelog you're saying about?

Dmitry, he means your commit log message.

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

end of thread, other threads:[~2012-02-29  8:29 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-02-28  9:33 [PATCH 1/2] vmalloc: use ZERO_SIZE_PTR / ZERO_OR_NULL_PTR Dmitry Antipov
2012-02-28  9:34 ` [PATCH 2/2] module: use ZERO_OR_NULL_PTR allocation pointer checking Dmitry Antipov
2012-02-28  9:44 ` [PATCH 1/2] vmalloc: use ZERO_SIZE_PTR / ZERO_OR_NULL_PTR Dan Carpenter
2012-02-28 11:59   ` Dmitry Antipov
2012-02-28 13:30     ` Dan Carpenter
2012-02-29  6:53       ` Dmitry Antipov
2012-02-29  7:10         ` Dan Carpenter
2012-02-29  8:29         ` Amit Kucheria

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).