public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] hvsi: Messed up error checking getting state name
@ 2010-04-16 11:49 Phil Carmody
  2010-04-16 22:18 ` Andrew Morton
  0 siblings, 1 reply; 2+ messages in thread
From: Phil Carmody @ 2010-04-16 11:49 UTC (permalink / raw)
  To: akpm; +Cc: benh, roel.kluin, linux-kernel

From: Phil Carmody <ext-phil.2.carmody@nokia.com>

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>
---
 drivers/char/hvsi.c |    6 ++----
 1 files changed, 2 insertions(+), 4 deletions(-)

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 */
-- 
1.6.0.4


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2010-04-16 22:18 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-04-16 11:49 [PATCH] hvsi: Messed up error checking getting state name Phil Carmody
2010-04-16 22:18 ` Andrew Morton

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox