]> git.baikalelectronics.ru Git - kernel.git/commit
s390/perf: fix gcc 8 array-bounds warning
authorVasily Gorbik <gor@linux.ibm.com>
Mon, 18 Jun 2018 15:51:29 +0000 (17:51 +0200)
committerMartin Schwidefsky <schwidefsky@de.ibm.com>
Mon, 2 Jul 2018 09:24:54 +0000 (11:24 +0200)
commite8fd8354c2ab73f14902fd28ce71c6af702224e7
tree87704376889741ce43bac62e0e2bd3e8109a6d5f
parent07ac19b9d3480082bc02402e7bf683cfb912c192
s390/perf: fix gcc 8 array-bounds warning

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>
arch/s390/kernel/perf_regs.c