Skip to content
/ linux Public

Commit bea2848

Browse files
seehearfeelgregkh
authored andcommitted
LoongArch: Check return values for set_memory_{rw,rox}
[ Upstream commit 431ce83 ] set_memory_rw() and set_memory_rox() may fail, so we should check the return values and return immediately in larch_insn_text_copy(). Cc: stable@vger.kernel.org Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn> Signed-off-by: Huacai Chen <chenhuacai@loongson.cn> [ kept `stop_machine()` instead of `stop_machine_cpuslocked()` ] Signed-off-by: Sasha Levin <sashal@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent fc9d699 commit bea2848

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

arch/loongarch/kernel/inst.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ static int text_copy_cb(void *data)
260260
int larch_insn_text_copy(void *dst, void *src, size_t len)
261261
{
262262
int ret = 0;
263+
int err = 0;
263264
size_t start, end;
264265
struct insn_copy copy = {
265266
.dst = dst,
@@ -271,9 +272,19 @@ int larch_insn_text_copy(void *dst, void *src, size_t len)
271272
start = round_down((size_t)dst, PAGE_SIZE);
272273
end = round_up((size_t)dst + len, PAGE_SIZE);
273274

274-
set_memory_rw(start, (end - start) / PAGE_SIZE);
275+
err = set_memory_rw(start, (end - start) / PAGE_SIZE);
276+
if (err) {
277+
pr_info("%s: set_memory_rw() failed\n", __func__);
278+
return err;
279+
}
280+
275281
ret = stop_machine(text_copy_cb, &copy, cpu_online_mask);
276-
set_memory_rox(start, (end - start) / PAGE_SIZE);
282+
283+
err = set_memory_rox(start, (end - start) / PAGE_SIZE);
284+
if (err) {
285+
pr_info("%s: set_memory_rox() failed\n", __func__);
286+
return err;
287+
}
277288

278289
return ret;
279290
}

0 commit comments

Comments
 (0)