[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20150428094939.23440.50962.stgit@warthog.procyon.org.uk>
Date: Tue, 28 Apr 2015 10:49:39 +0100
From: David Howells <dhowells@...hat.com>
To: torvalds@...ux-foundation.org
Cc: linux-kernel@...r.kernel.org, mathieu.poirier@...aro.org
Subject: [PATCH] Adjust sysrq_register_handler() to avoid an array subscript
warning
sysrq_register_handler() iterates over platform_sysrq_reset_seq[] using
ARRAY_SIZE() on sysrq_reset_seq[] as a limit (indeed, the platform array is
expected to be shorter). gcc-5 spots the potential dereference beyond the end
of the array and issues the following warnings:
CC drivers/tty/sysrq.o
../drivers/tty/sysrq.c: In function 'sysrq_init':
../drivers/tty/sysrq.c:958:33: warning: array subscript is above array bounds [-Warray-bounds]
key = platform_sysrq_reset_seq[i];
^
../drivers/tty/sysrq.c: In function 'sysrq_toggle_support':
../drivers/tty/sysrq.c:958:33: warning: array subscript is above array bounds [-Warray-bounds]
key = platform_sysrq_reset_seq[i];
^
Since the platform_sysrq_reset_seq[] array is apparently meant to be
terminated rather than being fixed length, use a pointer to iterate over it
instead.
One further note: Should platform_sysrq_reset_seq[] be const?
Signed-off-by: David Howells <dhowells@...hat.com>
---
drivers/tty/sysrq.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
index 843f2cdc280b..431af8b6bdb7 100644
--- a/drivers/tty/sysrq.c
+++ b/drivers/tty/sysrq.c
@@ -949,13 +949,14 @@ static bool sysrq_handler_registered;
static inline void sysrq_register_handler(void)
{
+ const unsigned short *p = platform_sysrq_reset_seq;
unsigned short key;
int error;
int i;
/* First check if a __weak interface was instantiated. */
for (i = 0; i < ARRAY_SIZE(sysrq_reset_seq); i++) {
- key = platform_sysrq_reset_seq[i];
+ key = *p++;
if (key == KEY_RESERVED || key > KEY_MAX)
break;
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists