Skip to content

Commit

Permalink
s390/perf: fix gcc 8 array-bounds warning
Browse files Browse the repository at this point in the history
arch/s390/kernel/perf_regs.c:36:19: warning: array subscript 16 is above
array bounds of 'long unsigned int[16]' [-Warray-bounds]
  return regs->gprs[idx];

gcc tries to be smart here and since there is a condition:
if (idx >= PERF_REG_S390_R0 && idx <= PERF_REG_S390_R15)
	return regs->gprs[idx];
which covers all possible array subscripts, it gives the warning
for the last function return statement:
	return regs->gprs[idx];
which in presence of that condition does not really make sense and
should be replaced with "return 0;"

Also move WARN_ON_ONCE((u32)idx >= PERF_REG_S390_MAX) to the end of the
function.

Reviewed-by: Hendrik Brueckner <brueckner@linux.ibm.com>
Signed-off-by: Vasily Gorbik <gor@linux.ibm.com>
Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
  • Loading branch information
Vasily Gorbik authored and Martin Schwidefsky committed Jul 2, 2018
1 parent f6ea4d2 commit ad82a92
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions arch/s390/kernel/perf_regs.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ u64 perf_reg_value(struct pt_regs *regs, int idx)
{
freg_t fp;

if (WARN_ON_ONCE((u32)idx >= PERF_REG_S390_MAX))
return 0;

if (idx >= PERF_REG_S390_R0 && idx <= PERF_REG_S390_R15)
return regs->gprs[idx];

Expand All @@ -33,7 +30,8 @@ u64 perf_reg_value(struct pt_regs *regs, int idx)
if (idx == PERF_REG_S390_PC)
return regs->psw.addr;

return regs->gprs[idx];
WARN_ON_ONCE((u32)idx >= PERF_REG_S390_MAX);
return 0;
}

#define REG_RESERVED (~((1UL << PERF_REG_S390_MAX) - 1))
Expand Down

0 comments on commit ad82a92

Please sign in to comment.