Skip to content

Commit

Permalink
hvsi: fix messed up error checking getting state name
Browse files Browse the repository at this point in the history
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 <ext-phil.2.carmody@nokia.com>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Roel Kluin <roel.kluin@gmail.com>
Cc: Grant Likely <grant.likely@secretlab.ca>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
  • Loading branch information
Phil Carmody authored and Linus Torvalds committed May 25, 2010
1 parent 4be929b commit 08a82c6
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions drivers/char/hvsi.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down

0 comments on commit 08a82c6

Please sign in to comment.