From: Ahmad Fatoum <a.fatoum@barebox.org>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@barebox.org>
Subject: [PATCH 07/10] resource: make NULL in release_[sdram_]region a no-op
Date: Mon, 5 Jan 2026 09:03:39 +0100 [thread overview]
Message-ID: <20260105080653.3240497-8-a.fatoum@barebox.org> (raw)
In-Reply-To: <20260105080653.3240497-1-a.fatoum@barebox.org>
By handling the NULL inside release_region, we can remove some
clutter in caller error handling for release_sdram_region.
Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
arch/arm/cpu/bootm-fip.c | 5 ++---
arch/arm/lib32/bootz.c | 3 +--
common/bootm.c | 18 ++++++------------
common/resource.c | 2 ++
fs/pstore/ram_core.c | 7 +++----
5 files changed, 14 insertions(+), 21 deletions(-)
diff --git a/arch/arm/cpu/bootm-fip.c b/arch/arm/cpu/bootm-fip.c
index a50b3f4431d0..8d1ea3f109d1 100644
--- a/arch/arm/cpu/bootm-fip.c
+++ b/arch/arm/cpu/bootm-fip.c
@@ -52,9 +52,8 @@ static int desc_to_sdram(struct fip_image_desc *loadable, ulong load_address)
static void desc_release_sdram(struct fip_image_desc *loadable)
{
- struct resource *res = loadable ? desc_get_res(loadable) : NULL;
- if (res)
- release_sdram_region(res);
+ if (loadable)
+ release_sdram_region(desc_get_res(loadable));
}
enum { IMAGE_BL33, IMAGE_HW_CONFIG, IMAGE_COUNT };
diff --git a/arch/arm/lib32/bootz.c b/arch/arm/lib32/bootz.c
index 6ed6af1d19e3..0ace36271026 100644
--- a/arch/arm/lib32/bootz.c
+++ b/arch/arm/lib32/bootz.c
@@ -127,8 +127,7 @@ static int do_bootz(int argc, char *argv[])
return 0;
err_out2:
- if (res)
- release_sdram_region(res);
+ release_sdram_region(res);
err_out1:
free(zimage);
err_out:
diff --git a/common/bootm.c b/common/bootm.c
index 26fd8227f01f..933e9dfc69fe 100644
--- a/common/bootm.c
+++ b/common/bootm.c
@@ -748,10 +748,8 @@ int bootm_boot(struct bootm_data *bootm_data)
bootm_get_override(&data->oftree_file, bootm_overrides.oftree_file);
if (bootm_get_override(&data->initrd_file, bootm_overrides.initrd_file)) {
- if (data->initrd_res) {
- release_sdram_region(data->initrd_res);
- data->initrd_res = NULL;
- }
+ release_sdram_region(data->initrd_res);
+ data->initrd_res = NULL;
}
ret = handler->bootm(data);
@@ -759,14 +757,10 @@ int bootm_boot(struct bootm_data *bootm_data)
pr_info("Dryrun. Aborted\n");
err_out:
- if (data->os_res)
- release_sdram_region(data->os_res);
- if (data->initrd_res)
- release_sdram_region(data->initrd_res);
- if (data->oftree_res)
- release_sdram_region(data->oftree_res);
- if (data->tee_res)
- release_sdram_region(data->tee_res);
+ release_sdram_region(data->os_res);
+ release_sdram_region(data->initrd_res);
+ release_sdram_region(data->oftree_res);
+ release_sdram_region(data->tee_res);
if (image_is_uimage(data))
bootm_close_uimage(data);
if (data->os_fit)
diff --git a/common/resource.c b/common/resource.c
index 078dc9f2ff2d..33eb122f4668 100644
--- a/common/resource.c
+++ b/common/resource.c
@@ -97,6 +97,8 @@ struct resource *__request_region(struct resource *parent,
*/
int release_region(struct resource *res)
{
+ if (!res)
+ return 0;
if (!list_empty(&res->children))
return -EBUSY;
diff --git a/fs/pstore/ram_core.c b/fs/pstore/ram_core.c
index 621987f1bade..6cf99fc4b284 100644
--- a/fs/pstore/ram_core.c
+++ b/fs/pstore/ram_core.c
@@ -397,10 +397,9 @@ void persistent_ram_free(struct persistent_ram_zone *prz)
if (!prz)
return;
- if (prz->res) {
- release_sdram_region(prz->res);
- prz->res = NULL;
- }
+ release_sdram_region(prz->res);
+ prz->res = NULL;
+
if (prz->rs_decoder) {
free_rs(prz->rs_decoder);
prz->rs_decoder = NULL;
--
2.47.3
next prev parent reply other threads:[~2026-01-05 8:07 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-05 8:03 [PATCH 00/10] bootm: refactor to prepare multiple initrd support Ahmad Fatoum
2026-01-05 8:03 ` [PATCH 01/10] bootm: set image_data::initrd_res at a single place Ahmad Fatoum
2026-01-05 8:03 ` [PATCH 02/10] bootm: fit: split support into dedicated file Ahmad Fatoum
2026-01-05 8:03 ` [PATCH 03/10] bootm: uimage: " Ahmad Fatoum
2026-01-05 8:03 ` [PATCH 04/10] filetype: introduce filetype_fit Ahmad Fatoum
2026-01-05 8:03 ` [PATCH 05/10] bootm: refactor for readability and extensibility Ahmad Fatoum
2026-01-05 8:03 ` [PATCH 06/10] memory: move release_sdram_region into header Ahmad Fatoum
2026-01-05 8:03 ` Ahmad Fatoum [this message]
2026-01-05 8:03 ` [PATCH 08/10] common: elf: use release_region unconditionally Ahmad Fatoum
2026-01-05 8:03 ` [PATCH 09/10] memory: always print errors on request_sdram_region failure Ahmad Fatoum
2026-01-05 8:03 ` [PATCH 10/10] memory: drop now duplicate request_sdram_region error messages Ahmad Fatoum
2026-01-09 8:20 ` [PATCH 00/10] bootm: refactor to prepare multiple initrd support Sascha Hauer
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=20260105080653.3240497-8-a.fatoum@barebox.org \
--to=a.fatoum@barebox.org \
--cc=barebox@lists.infradead.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