UPSTREAM: arm64: module: fix relocation of movz instruction with negative immediate

The test whether a movz instruction with a signed immediate should be
turned into a movn instruction (i.e., when the immediate is negative)
is flawed, since the value of imm is always positive. Also, the
subsequent bounds check is incorrect since the limit update never
executes, due to the fact that the imm_type comparison will always be
false for negative signed immediates.

Let's fix this by performing the sign test on sval directly, and
replacing the bounds check with a simple comparison against U16_MAX.

Signed-off-by: Ard Biesheuvel <>
[will: tidied up use of sval, renamed MOVK enum value to MOVKZ]
Signed-off-by: Will Deacon <>

Bug: None
Patchset: arm64-kmod-loading-fixes

(cherry-picked from b24a557527f97ad88619d5bd4c8017c635056d69)
Signed-off-by: Mattias Nissler <>

Change-Id: If881c1c7fcd6e67c835cb1b678654b9545ba3192
1 file changed