2022-10-29 20:44:02

by Jiaxun Yang

[permalink] [raw]
Subject: [PATCH] MIPS: jump_label: Fix compat branch range check

Cast upper bound of branch range to long to do signed compare,
avoid negtive offset trigger this warning.

Fixes: 9b6584e35f40 ("MIPS: jump_label: Use compact branches for >= r6")
Signed-off-by: Jiaxun Yang <[email protected]>
Cc: [email protected]
---
arch/mips/kernel/jump_label.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/mips/kernel/jump_label.c b/arch/mips/kernel/jump_label.c
index 71a882c8c6eb..f7978d50a2ba 100644
--- a/arch/mips/kernel/jump_label.c
+++ b/arch/mips/kernel/jump_label.c
@@ -56,7 +56,7 @@ void arch_jump_label_transform(struct jump_entry *e,
* The branch offset must fit in the instruction's 26
* bit field.
*/
- WARN_ON((offset >= BIT(25)) ||
+ WARN_ON((offset >= (long)BIT(25)) ||
(offset < -(long)BIT(25)));

insn.j_format.opcode = bc6_op;
--
2.34.1



2022-10-30 00:05:14

by Philippe Mathieu-Daudé

[permalink] [raw]
Subject: Re: [PATCH] MIPS: jump_label: Fix compat branch range check

On 29/10/22 22:35, Jiaxun Yang wrote:
> Cast upper bound of branch range to long to do signed compare,
> avoid negtive offset trigger this warning.

Typo "negative".

> Fixes: 9b6584e35f40 ("MIPS: jump_label: Use compact branches for >= r6")
> Signed-off-by: Jiaxun Yang <[email protected]>
> Cc: [email protected]
> ---
> arch/mips/kernel/jump_label.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arch/mips/kernel/jump_label.c b/arch/mips/kernel/jump_label.c
> index 71a882c8c6eb..f7978d50a2ba 100644
> --- a/arch/mips/kernel/jump_label.c
> +++ b/arch/mips/kernel/jump_label.c
> @@ -56,7 +56,7 @@ void arch_jump_label_transform(struct jump_entry *e,
> * The branch offset must fit in the instruction's 26
> * bit field.
> */
> - WARN_ON((offset >= BIT(25)) ||
> + WARN_ON((offset >= (long)BIT(25)) ||
> (offset < -(long)BIT(25)));

Reviewed-by: Philippe Mathieu-Daudé <[email protected]>