From: Marek Szyprowski <m.szyprowski@samsung.com>
To: Wandun Chen <chenwandun1@gmail.com>,
robh@kernel.org, saravanak@kernel.org, rppt@kernel.org,
devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-mm@kvack.org
Cc: akpm@linux-foundation.org
Subject: Re: [PATCH v2 4/5] of: reserved_mem: release dynamically allocated no-map region on init failure
Date: Wed, 26 Aug 2026 15:17:46 +0200 [thread overview]
Message-ID: <8948e46d-bcc2-47e9-84de-dd6907cf0876@samsung.com> (raw)
In-Reply-To: <20260818092420.2859026-5-chenwandun1@gmail.com>
On 18.08.2026 11:24, Wandun Chen wrote:
> From: Wandun Chen <chenwandun@lixiang.com>
>
> Dynamically reserved-memory regions are added to memblock.reserved by
> memblock_phys_alloc_range() during __reserved_mem_alloc_size(). When a
> reserved-memory region's driver initialization fails,
> fdt_init_reserved_mem_node() cleans up the reservation. For no-map
> regions it only calls memblock_clear_nomap(), leaving the range in
> memblock.reserved and unavailable for normal memory use.
>
> Fix it by freeing the region on init failure when it was dynamically
> allocated.
>
> Sashiko found this issue in [1].
>
> Fixes: 7b25995f5319 ("of: of_reserved_mem: mark nomap memory instead of removing")
> Signed-off-by: Wandun Chen <chenwandun@lixiang.com>
Acked-by: Marek Szyprowski <m.szyprowski@samsung.com>
> Link: https://protect2.fireeye.com/v1/url?k=37bb3269-68033acb-37bab926-000babff88b5-00648778f1201363&q=1&e=40542077-d5ad-41ca-88fd-1cf102a816c1&u=https%3A%2F%2Fsashiko.dev%2F%23%2Fmessage%2F20260806100605.2C2C01F000E9%2540smtp.kernel.org [1]
> ---
> drivers/of/of_reserved_mem.c | 14 +++++++++-----
> 1 file changed, 9 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/of/of_reserved_mem.c b/drivers/of/of_reserved_mem.c
> index 767ef702392e..ac5db19dcc93 100644
> --- a/drivers/of/of_reserved_mem.c
> +++ b/drivers/of/of_reserved_mem.c
> @@ -136,7 +136,8 @@ static int __init alloc_reserved_mem_array(void)
> }
>
> static void fdt_init_reserved_mem_node(unsigned long node, const char *uname,
> - phys_addr_t base, phys_addr_t size);
> + phys_addr_t base, phys_addr_t size,
> + bool dynamic);
> static int fdt_validate_reserved_mem_node(unsigned long node,
> phys_addr_t *align);
> static int fdt_fixup_reserved_mem_node(unsigned long node,
> @@ -352,7 +353,7 @@ void __init fdt_scan_reserved_mem_late(void)
> continue;
>
> uname = fdt_get_name(fdt, child, NULL);
> - fdt_init_reserved_mem_node(child, uname, base, size);
> + fdt_init_reserved_mem_node(child, uname, base, size, false);
> }
>
> /* check for overlapping reserved regions */
> @@ -567,7 +568,7 @@ static int __init __reserved_mem_alloc_size(unsigned long node, const char *unam
> }
>
> fdt_fixup_reserved_mem_node(node, base, size);
> - fdt_init_reserved_mem_node(node, uname, base, size);
> + fdt_init_reserved_mem_node(node, uname, base, size, true);
>
> return 0;
> }
> @@ -676,13 +677,15 @@ static int __init __reserved_mem_init_node(struct reserved_mem *rmem,
> * @uname: name of the reserved memory node
> * @base: base address of the reserved memory region
> * @size: size of the reserved memory region
> + * @dynamic: whether the region was dynamically allocated
> *
> * This function calls the region-specific initialization function for a
> * reserved memory region and saves all region-specific data to the
> * reserved_mem array to allow of_reserved_mem_lookup() to find it.
> */
> static void __init fdt_init_reserved_mem_node(unsigned long node, const char *uname,
> - phys_addr_t base, phys_addr_t size)
> + phys_addr_t base, phys_addr_t size,
> + bool dynamic)
> {
> int err = 0;
> bool nomap;
> @@ -708,7 +711,8 @@ static void __init fdt_init_reserved_mem_node(unsigned long node, const char *un
>
> if (nomap)
> memblock_clear_nomap(rmem->base, rmem->size);
> - else
> +
> + if (dynamic || !nomap)
> memblock_phys_free(rmem->base, rmem->size);
> return;
> } else {
Best regards
--
Marek Szyprowski, PhD
Samsung R&D Institute Poland
next prev parent reply other threads:[~2026-08-26 13:17 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-18 9:24 [PATCH v2 0/5] of: reserved_mem: several fixes about reserved memory Wandun Chen
2026-08-18 9:24 ` [PATCH v2 1/5] of: reserved_mem: skip init for regions whose early reservation failed Wandun Chen
2026-08-26 13:14 ` Marek Szyprowski
2026-08-18 9:24 ` [PATCH v2 2/5] of: reserved_mem: reject static regions overlapping no-map memory Wandun Chen
2026-08-18 9:40 ` sashiko-bot
2026-08-19 2:26 ` Wandun
2026-08-26 13:16 ` Marek Szyprowski
2026-08-18 9:24 ` [PATCH v2 3/5] of: reserved_mem: reject statically placed regions overlapping existing reservations Wandun Chen
2026-08-18 9:41 ` sashiko-bot
2026-08-19 3:00 ` Wandun
2026-08-26 13:16 ` Marek Szyprowski
2026-08-18 9:24 ` [PATCH v2 4/5] of: reserved_mem: release dynamically allocated no-map region on init failure Wandun Chen
2026-08-18 9:38 ` sashiko-bot
2026-08-19 3:14 ` Wandun
2026-08-26 13:17 ` Marek Szyprowski [this message]
2026-08-18 9:24 ` [PATCH v2 5/5] of: reserved_mem: retain static no-map memory " Wandun Chen
2026-08-18 9:34 ` sashiko-bot
2026-08-19 3:16 ` Wandun
2026-08-26 13:18 ` Marek Szyprowski
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=8948e46d-bcc2-47e9-84de-dd6907cf0876@samsung.com \
--to=m.szyprowski@samsung.com \
--cc=akpm@linux-foundation.org \
--cc=chenwandun1@gmail.com \
--cc=devicetree@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=robh@kernel.org \
--cc=rppt@kernel.org \
--cc=saravanak@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