Skip to contentSkip to conversation

hvsi: Keep index within state_names[]

PATCH In review Roel Kluin 1 participant 2 messages Jul 12, 2009 – Jul 13, 2009 Char and misc drivers

lore
Share & tools
lore

Roel Kluin

author
#0 lore raw

PATCH 1/1 hvsi: Keep index within state_names[]

Keep index within state_names[]

---

drivers/char/hvsi.c +1 -1
index 2989056..05dd854 100644
@@ -196,7 +196,7 @@ static inline void print_state(struct hvsi_struct *hp)
 	};
 	const char *name = state_names[hp->state];
 
-	if (hp->state > ARRAY_SIZE(state_names))
+	if (hp->state >= ARRAY_SIZE(state_names))
 		name = "UNKNOWN";
 
 	pr_debug("hvsi%i: state = %s\n", hp->index, name);
author
#1 lore raw

Keep index within state_names[]

---

Quoted 1 line

Hmm, using "hp->state" before the check is somewhat disturbing.

Ok. How about this?

drivers/char/hvsi.c +4 -2
index 2989056..cacb8c3 100644
@@ -194,10 +194,12 @@ static inline void print_state(struct hvsi_struct *hp)
 		"HVSI_WAIT_FOR_MCTRL_RESPONSE",
 		"HVSI_FSP_DIED",
 	};
-	const char *name = state_names[hp->state];
+	const char *name;
 
-	if (hp->state > ARRAY_SIZE(state_names))
+	if (hp->state >= ARRAY_SIZE(state_names))
 		name = "UNKNOWN";
+	else
+		name = state_names[hp->state];
 
 	pr_debug("hvsi%i: state = %s\n", hp->index, name);
 #endif /* DEBUG */