Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

scsi: isci: avoid array subscript warning

I'm getting a new warning with gcc-7:

isci/remote_node_context.c: In function 'sci_remote_node_context_destruct':
isci/remote_node_context.c:69:16: error: array subscript is above array bounds [-Werror=array-bounds]

This is odd, since we clearly cover all values for enum
scis_sds_remote_node_context_states here. Anyway, checking for an array
overflow can't harm and it makes the warning go away.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>

authored by

Arnd Bergmann and committed by
Martin K. Petersen
5cfa2a3c ce41b41e

+3
+3
drivers/scsi/isci/remote_node_context.c
··· 66 66 { 67 67 static const char * const strings[] = RNC_STATES; 68 68 69 + if (state >= ARRAY_SIZE(strings)) 70 + return "UNKNOWN"; 71 + 69 72 return strings[state]; 70 73 } 71 74 #undef C