linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: 권오훈 <ohoono.kwon@samsung.com>
To: "robh+dt@kernel.org" <robh+dt@kernel.org>,
	"frowand.list@gmail.com" <frowand.list@gmail.com>
Cc: "lee.jones@linaro.org" <lee.jones@linaro.org>,
	권오훈 <ohoono.kwon@samsung.com>,
	"ohkwon1043@gmail.com" <ohkwon1043@gmail.com>,
	"devicetree@vger.kernel.org" <devicetree@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: [PATCH] of: of_reserved_mem: match memblock_free with
Date: Thu, 01 Jul 2021 23:06:14 +0900	[thread overview]
Message-ID: <20210701140614epcms1p384c7e681cd9cd08a2b836474c167c549@epcms1p3> (raw)
In-Reply-To: CGME20210701140328epcms1p85149318b6c18fa18b3c7c8e966c14db0@epcms1p3

When __reserved_mem_init_node called from fdt_init_reserved_mem fails,
we try to undo __reserved_mem_alloc_size to prevent memory leak.
'commit d0b8ed47e83a ("of: reserved_mem: fix reserve memory leak")'

Meanwhile, __reserved_mem_alloc_size calls
early_init_dt_alloc_reserved_memory_arch to allocate memory,
which calls
1) memblock_remove when rmem is declared nomap,
2) memblock_reserve, otherwise.

static int __init early_init_dt_alloc_reserved_memory_arch(
...
	if (nomap)
		return memblock_remove(base, size);

	return memblock_reserve(base, size);
}

Therefore the proper undo-logic should be as follows:
1) memblock_add when rmem is declared nomap,
2) memblock_free, otherwise.

Match the undo functions for readability.

Signed-off-by: Ohhoon Kwon <ohoono.kwon@samsung.com>
---
 drivers/of/of_reserved_mem.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/of/of_reserved_mem.c b/drivers/of/of_reserved_mem.c
index 15e2417974d6..2279e1b55d1d 100644
--- a/drivers/of/of_reserved_mem.c
+++ b/drivers/of/of_reserved_mem.c
@@ -273,9 +273,10 @@ void __init fdt_init_reserved_mem(void)
 			if (err != 0 && err != -ENOENT) {
 				pr_info("node %s compatible matching fail\n",
 					rmem->name);
-				memblock_free(rmem->base, rmem->size);
 				if (nomap)
 					memblock_add(rmem->base, rmem->size);
+				else
+					memblock_free(rmem->base, rmem->size);
 			}
 		}
 	}
-- 
2.17.1

           reply	other threads:[~2021-07-01 14:06 UTC|newest]

Thread overview: expand[flat|nested]  mbox.gz  Atom feed
 [parent not found: <CGME20210701140328epcms1p85149318b6c18fa18b3c7c8e966c14db0@epcms1p3>]

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=20210701140614epcms1p384c7e681cd9cd08a2b836474c167c549@epcms1p3 \
    --to=ohoono.kwon@samsung.com \
    --cc=devicetree@vger.kernel.org \
    --cc=frowand.list@gmail.com \
    --cc=lee.jones@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ohkwon1043@gmail.com \
    --cc=robh+dt@kernel.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;
as well as URLs for NNTP newsgroup(s).