All of lore.kernel.org
 help / color / mirror / Atom feed
From: Yinghai Lu <yinghai@kernel.org>
To: Namhyung Kim <namhyung@gmail.com>
Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	Benjamin Herrenschmidt <benh@kernel.crashing.org>
Subject: Re: [PATCH] memblock: Fix error path in memblock_add_region()
Date: Sun, 06 Feb 2011 09:46:17 -0800	[thread overview]
Message-ID: <4D4EDE69.9060200@kernel.org> (raw)
In-Reply-To: <1296999075-8022-1-git-send-email-namhyung@gmail.com>

On 02/06/2011 05:31 AM, Namhyung Kim wrote:
> @type->regions should be restored if memblock_double_array() fails.
> 
> Signed-off-by: Namhyung Kim <namhyung@gmail.com>
> Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
> Cc: Yinghai Lu <yinghai@kernel.org>
> ---
>  mm/memblock.c |    4 ++++
>  1 files changed, 4 insertions(+), 0 deletions(-)
> 
> diff --git a/mm/memblock.c b/mm/memblock.c
> index bdba245d8afd..49284f9f99a6 100644
> --- a/mm/memblock.c
> +++ b/mm/memblock.c
> @@ -379,6 +379,10 @@ static long __init_memblock memblock_add_region(struct memblock_type *type, phys
>  	 */
>  	if (type->cnt == type->max && memblock_double_array(type)) {
>  		type->cnt--;
> +		for (++i; i < type->cnt; i++) {
> +			type->regions[i].base = type->regions[i+1].base;
> +			type->regions[i].size = type->regions[i+1].size;
> +		}
>  		return -1;
>  	}
>  

we can skip the restoring.

Thanks

Yinghai

diff --git a/mm/memblock.c b/mm/memblock.c
index bdba245..3231657 100644
--- a/mm/memblock.c
+++ b/mm/memblock.c
@@ -374,13 +374,9 @@ static long __init_memblock memblock_add_region(struct memblock_type *type, phys
 	}
 	type->cnt++;
 
-	/* The array is full ? Try to resize it. If that fails, we undo
-	 * our allocation and return an error
-	 */
-	if (type->cnt == type->max && memblock_double_array(type)) {
-		type->cnt--;
+	/* The array is full ? Try to resize it  */
+	if (type->cnt == type->max && memblock_double_array(type))
 		return -1;
-	}
 
 	return 0;
 }

WARNING: multiple messages have this Message-ID (diff)
From: Yinghai Lu <yinghai@kernel.org>
To: Namhyung Kim <namhyung@gmail.com>
Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	Benjamin Herrenschmidt <benh@kernel.crashing.org>
Subject: Re: [PATCH] memblock: Fix error path in memblock_add_region()
Date: Sun, 06 Feb 2011 09:46:17 -0800	[thread overview]
Message-ID: <4D4EDE69.9060200@kernel.org> (raw)
In-Reply-To: <1296999075-8022-1-git-send-email-namhyung@gmail.com>

On 02/06/2011 05:31 AM, Namhyung Kim wrote:
> @type->regions should be restored if memblock_double_array() fails.
> 
> Signed-off-by: Namhyung Kim <namhyung@gmail.com>
> Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
> Cc: Yinghai Lu <yinghai@kernel.org>
> ---
>  mm/memblock.c |    4 ++++
>  1 files changed, 4 insertions(+), 0 deletions(-)
> 
> diff --git a/mm/memblock.c b/mm/memblock.c
> index bdba245d8afd..49284f9f99a6 100644
> --- a/mm/memblock.c
> +++ b/mm/memblock.c
> @@ -379,6 +379,10 @@ static long __init_memblock memblock_add_region(struct memblock_type *type, phys
>  	 */
>  	if (type->cnt == type->max && memblock_double_array(type)) {
>  		type->cnt--;
> +		for (++i; i < type->cnt; i++) {
> +			type->regions[i].base = type->regions[i+1].base;
> +			type->regions[i].size = type->regions[i+1].size;
> +		}
>  		return -1;
>  	}
>  

we can skip the restoring.

Thanks

Yinghai

diff --git a/mm/memblock.c b/mm/memblock.c
index bdba245..3231657 100644
--- a/mm/memblock.c
+++ b/mm/memblock.c
@@ -374,13 +374,9 @@ static long __init_memblock memblock_add_region(struct memblock_type *type, phys
 	}
 	type->cnt++;
 
-	/* The array is full ? Try to resize it. If that fails, we undo
-	 * our allocation and return an error
-	 */
-	if (type->cnt == type->max && memblock_double_array(type)) {
-		type->cnt--;
+	/* The array is full ? Try to resize it  */
+	if (type->cnt == type->max && memblock_double_array(type))
 		return -1;
-	}
 
 	return 0;
 }

--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

  reply	other threads:[~2011-02-06 17:47 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-02-06 13:31 [PATCH] memblock: Fix error path in memblock_add_region() Namhyung Kim
2011-02-06 13:31 ` Namhyung Kim
2011-02-06 17:46 ` Yinghai Lu [this message]
2011-02-06 17:46   ` Yinghai Lu
2011-02-07  5:00   ` Namhyung Kim
2011-02-07  5:00     ` Namhyung Kim

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=4D4EDE69.9060200@kernel.org \
    --to=yinghai@kernel.org \
    --cc=benh@kernel.crashing.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=namhyung@gmail.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.