From b6326545ef0a95092882ac98921d92e012df9f21 Mon Sep 17 00:00:00 2001 From: Jan Beulich Date: Mon, 12 Oct 2026 09:39:43 +0200 Subject: [PATCH] x86/alternatives: adjust _apply_alternatives() to comply to Misra rule 18.2 While avoiding casts would be preferable here, the subtraction ends up violating "Subtraction between pointers shall only be applied to pointers that address elements of the same array". Use long arithmetic instead. No functional change intended. Signed-off-by: Jan Beulich Reviewed-by: Dmytro Prokopchuk --- xen/arch/x86/alternative.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xen/arch/x86/alternative.c b/xen/arch/x86/alternative.c index 80c4dc721b..a4cadd9b0b 100644 --- a/xen/arch/x86/alternative.c +++ b/xen/arch/x86/alternative.c @@ -342,13 +342,13 @@ static int init_or_livepatch _apply_alternatives(struct alt_instr *start, /* 0xe8/0xe9 are relative branches; fix the offset. */ if ( a->repl_len >= 5 && (*buf & 0xfe) == 0xe8 ) - *(int32_t *)(buf + 1) += repl - orig; + *(int32_t *)(buf + 1) += (long)repl - (long)orig; else if ( IS_ENABLED(CONFIG_RETURN_THUNK) && a->repl_len > 5 && buf[a->repl_len - 5] == 0xe9 && ((long)repl + a->repl_len + *(int32_t *)(buf + a->repl_len - 4) == (long)__x86_return_thunk) ) - *(int32_t *)(buf + a->repl_len - 4) += repl - orig; + *(int32_t *)(buf + a->repl_len - 4) += (long)repl - (long)orig; a->priv = 1;