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 <jbeulich@suse.com>
Reviewed-by: Dmytro Prokopchuk <dmytro_prokopchuk1@epam.com>
This commit is contained in:
Jan Beulich committed 2026-10-12 09:39:43 +02:00
1 parent 6c98c5368f
commit b6326545ef
1 file changed
+2 -2
+2 -2
View File
@@ -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;
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.