From: Phil Carmody Date: Mon, 24 May 2010 21:33:04 +0000 (-0700) Subject: hvsi: fix messed up error checking getting state name X-Git-Tag: v2.6.35-rc1~341 X-Git-Url: http://ftp.safe.ca/?p=safe%2Fjmp%2Flinux-2.6;a=commitdiff_plain;h=08a82c6872ac1d37cb993a52f1b35f97f48295bd hvsi: fix messed up error checking getting state name Handle out-of-range indices before reading what they refer to. And don't access the one-past-the-end element of the array either. Signed-off-by: Phil Carmody Cc: Benjamin Herrenschmidt Cc: Roel Kluin Cc: Grant Likely Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- diff --git a/drivers/char/hvsi.c b/drivers/char/hvsi.c index 793b236..d4b14ff 100644 --- a/drivers/char/hvsi.c +++ b/drivers/char/hvsi.c @@ -194,10 +194,8 @@ static inline void print_state(struct hvsi_struct *hp) "HVSI_WAIT_FOR_MCTRL_RESPONSE", "HVSI_FSP_DIED", }; - const char *name = state_names[hp->state]; - - if (hp->state > ARRAY_SIZE(state_names)) - name = "UNKNOWN"; + const char *name = (hp->state < ARRAY_SIZE(state_names)) + ? state_names[hp->state] : "UNKNOWN"; pr_debug("hvsi%i: state = %s\n", hp->index, name); #endif /* DEBUG */