In the unlikely event that regno == nr_registers then we get an array overrun on regoff because the invalid register check is currently off-by-one. Fix this with a check that regno is >= nr_registers instead. Detected with static analysis using CoverityScan.
Unified · Split
| @@ -123,7 +123,7 @@ static int get_reg_offset(struct insn *insn, struct pt_regs *regs, · 122 unmodified lines | |||
| 123 | break; | 123 | break; |
| 124 | } | 124 | } |
| 125 | 125 | ||
| 126 | if (regno > nr_registers) { | 126 | if (regno >= nr_registers) { |
| 127 | WARN_ONCE(1, "decoded an instruction with an invalid register"); | 127 | WARN_ONCE(1, "decoded an instruction with an invalid register"); |
| 128 | return -EINVAL; | 128 | return -EINVAL; |
| 129 | } | 129 | } |