Explorar o código

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 <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>
Phil Carmody %!s(int64=15) %!d(string=hai) anos
pai
achega
08a82c6872
Modificáronse 1 ficheiros con 2 adicións e 4 borrados
  1. 2 4
      drivers/char/hvsi.c

+ 2 - 4
drivers/char/hvsi.c

@@ -194,10 +194,8 @@ static inline void print_state(struct hvsi_struct *hp)
 		"HVSI_WAIT_FOR_MCTRL_RESPONSE",
 		"HVSI_WAIT_FOR_MCTRL_RESPONSE",
 		"HVSI_FSP_DIED",
 		"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);
 	pr_debug("hvsi%i: state = %s\n", hp->index, name);
 #endif /* DEBUG */
 #endif /* DEBUG */