From: WANG Cong <xiyou.wangcong@gmail.com>
To: Dave Hansen <haveblue@us.ibm.com>
Cc: WANG Cong <xiyou.wangcong@gmail.com>,
Yasunori Goto <y-goto@jp.fujitsu.com>,
LKML <linux-kernel@vger.kernel.org>,
Rik van Riel <riel@redhat.com>,
Christoph Lameter <clameter@sgi.com>,
Andrew Morton <akpm@osdl.org>,
linux-mm@kvack.org, Andy Whitcroft <apw@shadowen.org>
Subject: Re: [Patch](Resend) mm/sparse.c: Improve the error handling for sparse_add_one_section()
Date: Wed, 28 Nov 2007 20:44:20 +0800 [thread overview]
Message-ID: <20071128124420.GJ2464@hacking> (raw)
In-Reply-To: <1196189625.5764.36.camel@localhost>
On Tue, Nov 27, 2007 at 10:53:45AM -0800, Dave Hansen wrote:
>On Tue, 2007-11-27 at 10:26 +0800, WANG Cong wrote:
>>
>> @@ -414,7 +418,7 @@ int sparse_add_one_section(struct zone *
>> out:
>> pgdat_resize_unlock(pgdat, &flags);
>> if (ret <= 0)
>> - __kfree_section_memmap(memmap, nr_pages);
>> + kfree(usemap);
>> return ret;
>> }
>> #endif
>
>Why did you get rid of the memmap free here? A bad return from
>sparse_init_one_section() indicates that we didn't use the memmap, so it
>will leak otherwise.
Sorry, I was confused by the recursion. This one should be OK.
Thanks.
Improve the error handling for mm/sparse.c::sparse_add_one_section(). And I
see no reason to check 'usemap' until holding the 'pgdat_resize_lock'.
Cc: Christoph Lameter <clameter@sgi.com>
Cc: Dave Hansen <haveblue@us.ibm.com>
Cc: Rik van Riel <riel@redhat.com>
Cc: Yasunori Goto <y-goto@jp.fujitsu.com>
Cc: Andy Whitcroft <apw@shadowen.org>
Signed-off-by: WANG Cong <xiyou.wangcong@gmail.com>
---
Index: linux-2.6/mm/sparse.c
===================================================================
--- linux-2.6.orig/mm/sparse.c
+++ linux-2.6/mm/sparse.c
@@ -391,9 +391,17 @@ int sparse_add_one_section(struct zone *
* no locking for this, because it does its own
* plus, it does a kmalloc
*/
- sparse_index_init(section_nr, pgdat->node_id);
+ ret = sparse_index_init(section_nr, pgdat->node_id);
+ if (ret < 0)
+ return ret;
memmap = kmalloc_section_memmap(section_nr, pgdat->node_id, nr_pages);
+ if (!memmap)
+ return -ENOMEM;
usemap = __kmalloc_section_usemap();
+ if (!usemap) {
+ __kfree_section_memmap(memmap, nr_pages);
+ return -ENOMEM;
+ }
pgdat_resize_lock(pgdat, &flags);
@@ -403,18 +411,16 @@ int sparse_add_one_section(struct zone *
goto out;
}
- if (!usemap) {
- ret = -ENOMEM;
- goto out;
- }
ms->section_mem_map |= SECTION_MARKED_PRESENT;
ret = sparse_init_one_section(ms, section_nr, memmap, usemap);
out:
pgdat_resize_unlock(pgdat, &flags);
- if (ret <= 0)
+ if (ret <= 0) {
+ kfree(usemap);
__kfree_section_memmap(memmap, nr_pages);
+ }
return ret;
}
#endif
WARNING: multiple messages have this Message-ID (diff)
From: WANG Cong <xiyou.wangcong@gmail.com>
To: Dave Hansen <haveblue@us.ibm.com>
Cc: WANG Cong <xiyou.wangcong@gmail.com>,
Yasunori Goto <y-goto@jp.fujitsu.com>,
LKML <linux-kernel@vger.kernel.org>,
Rik van Riel <riel@redhat.com>,
Christoph Lameter <clameter@sgi.com>,
Andrew Morton <akpm@osdl.org>,
linux-mm@kvack.org, Andy Whitcroft <apw@shadowen.org>
Subject: Re: [Patch](Resend) mm/sparse.c: Improve the error handling for sparse_add_one_section()
Date: Wed, 28 Nov 2007 20:44:20 +0800 [thread overview]
Message-ID: <20071128124420.GJ2464@hacking> (raw)
In-Reply-To: <1196189625.5764.36.camel@localhost>
On Tue, Nov 27, 2007 at 10:53:45AM -0800, Dave Hansen wrote:
>On Tue, 2007-11-27 at 10:26 +0800, WANG Cong wrote:
>>
>> @@ -414,7 +418,7 @@ int sparse_add_one_section(struct zone *
>> out:
>> pgdat_resize_unlock(pgdat, &flags);
>> if (ret <= 0)
>> - __kfree_section_memmap(memmap, nr_pages);
>> + kfree(usemap);
>> return ret;
>> }
>> #endif
>
>Why did you get rid of the memmap free here? A bad return from
>sparse_init_one_section() indicates that we didn't use the memmap, so it
>will leak otherwise.
Sorry, I was confused by the recursion. This one should be OK.
Thanks.
Improve the error handling for mm/sparse.c::sparse_add_one_section(). And I
see no reason to check 'usemap' until holding the 'pgdat_resize_lock'.
Cc: Christoph Lameter <clameter@sgi.com>
Cc: Dave Hansen <haveblue@us.ibm.com>
Cc: Rik van Riel <riel@redhat.com>
Cc: Yasunori Goto <y-goto@jp.fujitsu.com>
Cc: Andy Whitcroft <apw@shadowen.org>
Signed-off-by: WANG Cong <xiyou.wangcong@gmail.com>
---
Index: linux-2.6/mm/sparse.c
===================================================================
--- linux-2.6.orig/mm/sparse.c
+++ linux-2.6/mm/sparse.c
@@ -391,9 +391,17 @@ int sparse_add_one_section(struct zone *
* no locking for this, because it does its own
* plus, it does a kmalloc
*/
- sparse_index_init(section_nr, pgdat->node_id);
+ ret = sparse_index_init(section_nr, pgdat->node_id);
+ if (ret < 0)
+ return ret;
memmap = kmalloc_section_memmap(section_nr, pgdat->node_id, nr_pages);
+ if (!memmap)
+ return -ENOMEM;
usemap = __kmalloc_section_usemap();
+ if (!usemap) {
+ __kfree_section_memmap(memmap, nr_pages);
+ return -ENOMEM;
+ }
pgdat_resize_lock(pgdat, &flags);
@@ -403,18 +411,16 @@ int sparse_add_one_section(struct zone *
goto out;
}
- if (!usemap) {
- ret = -ENOMEM;
- goto out;
- }
ms->section_mem_map |= SECTION_MARKED_PRESENT;
ret = sparse_init_one_section(ms, section_nr, memmap, usemap);
out:
pgdat_resize_unlock(pgdat, &flags);
- if (ret <= 0)
+ if (ret <= 0) {
+ kfree(usemap);
__kfree_section_memmap(memmap, nr_pages);
+ }
return ret;
}
#endif
--
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>
next prev parent reply other threads:[~2007-11-28 12:48 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-11-15 13:54 [Patch] mm/sparse.c: Check the return value of sparse_index_alloc() WANG Cong
2007-11-15 13:54 ` WANG Cong
2007-11-16 21:37 ` Andrew Morton
2007-11-16 21:37 ` Andrew Morton
2007-11-19 21:17 ` Dave Hansen
2007-11-19 21:17 ` Dave Hansen
2007-11-20 4:57 ` WANG Cong
2007-11-20 4:57 ` WANG Cong
2007-11-23 5:51 ` [Patch] mm/sparse.c: Improve the error handling for sparse_add_one_section() WANG Cong
2007-11-23 5:51 ` WANG Cong
2007-11-26 10:19 ` Yasunori Goto
2007-11-26 10:19 ` Yasunori Goto
2007-11-27 2:26 ` [Patch](Resend) " WANG Cong
2007-11-27 2:26 ` WANG Cong
2007-11-27 11:55 ` Yasunori Goto
2007-11-27 11:55 ` Yasunori Goto
2007-11-27 18:53 ` Dave Hansen
2007-11-27 18:53 ` Dave Hansen
2007-11-28 12:44 ` WANG Cong [this message]
2007-11-28 12:44 ` WANG Cong
2007-11-29 2:42 ` Yasunori Goto
2007-11-29 2:42 ` Yasunori Goto
2007-11-29 17:47 ` Dave Hansen
2007-11-29 17:47 ` Dave Hansen
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=20071128124420.GJ2464@hacking \
--to=xiyou.wangcong@gmail.com \
--cc=akpm@osdl.org \
--cc=apw@shadowen.org \
--cc=clameter@sgi.com \
--cc=haveblue@us.ibm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=riel@redhat.com \
--cc=y-goto@jp.fujitsu.com \
/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 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.