[PATCH] pstore/ram: fix resource leak when ioremap() fails
From: Cole Leavitt
Date: Wed Feb 25 2026 - 18:54:39 EST
In persistent_ram_iomap(), ioremap() or ioremap_wc() may return NULL on
failure. Currently, if this happens, the function returns NULL without
releasing the memory region acquired by request_mem_region().
This leads to a resource leak where the memory region remains reserved
but unusable.
Additionally, the caller persistent_ram_buffer_map() handles NULL
correctly by returning -ENOMEM, but without this check, a NULL return
combined with request_mem_region() succeeding leaves resources in an
inconsistent state.
This is the ioremap() counterpart to commit 05363abc7625 ("pstore:
ram_core: fix incorrect success return when vmap() fails") which fixed
a similar issue in the vmap() path.
Fixes: 404a6043385d ("staging: android: persistent_ram: handle reserving and mapping memory")
Signed-off-by: Cole Leavitt <cole@xxxxxxxxx>
---
fs/pstore/ram_core.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/fs/pstore/ram_core.c b/fs/pstore/ram_core.c
index ed97494abf60..0cc971f70eb0 100644
--- a/fs/pstore/ram_core.c
+++ b/fs/pstore/ram_core.c
@@ -493,6 +493,15 @@ static void *persistent_ram_iomap(phys_addr_t start, size_t size,
* there is no need handle anything special like we do when the
* vmap() case in persistent_ram_vmap() above.
*/
+ /*
+ * ioremap() may fail. Release the mem region and return NULL
+ * to let the caller handle the error.
+ */
+ if (!va) {
+ release_mem_region(start, size);
+ return NULL;
+ }
+
return va;
}
--
2.52.0