[PATCH 4/8] s390/module: Add error handling to module_alloc_ftrace_hotpatch_trampolines()

From: Heiko Carstens

Date: Wed Nov 18 2026 - 09:47:54 EST


Let module_alloc_ftrace_hotpatch_trampolines() return NULL, instead of
a pointer to a not executable page if set_memory_rox() fails.

Signed-off-by: Heiko Carstens <hca@xxxxxxxxxxxxx>
---
arch/s390/kernel/module.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
index 9d1f8a50f5a4..86ace854e22d 100644
--- a/arch/s390/kernel/module.c
+++ b/arch/s390/kernel/module.c
@@ -473,13 +473,18 @@ static int module_alloc_ftrace_hotpatch_trampolines(struct module *me,
char *start, *end;
int numpages;
size_t size;
+ int rc;

size = FTRACE_HOTPATCH_TRAMPOLINES_SIZE(s->sh_size);
numpages = DIV_ROUND_UP(size, PAGE_SIZE);
start = execmem_alloc(EXECMEM_FTRACE, numpages * PAGE_SIZE);
if (!start)
return -ENOMEM;
- set_memory_rox((unsigned long)start, numpages);
+ rc = set_memory_rox((unsigned long)start, numpages);
+ if (rc) {
+ execmem_free(start);
+ return rc;
+ }
end = start + size;

me->arch.trampolines_start = (struct ftrace_hotpatch_trampoline *)start;
--
2.56.1