Skip to contentSkip to conversation

Fix crash in unregister_console()

PATCH New Benjamin Herrenschmidt 1 participant 1 message Nov 23, 2005

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fix crash in unregister_console()

If unregister_console() is inadvertently called while no consoles are registered, it will crash trying to dereference NULL pointer. It is necessary to fix that because register_console() provides no indication that it actually registered the console passed in. In fact, it may well decide not to register it based on various things...

kernel/printk.c +1 -1
Index: linux-serialfix/kernel/printk.c
===================================================================
@@ -956,7 +956,7 @@ int unregister_console(struct console *c
 	if (console_drivers == console) {
 		console_drivers=console->next;
 		res = 0;
-	} else {
+	} else if (console_drivers) {
 		for (a=console_drivers->next, b=console_drivers ;
 		     a; b=a, a=b->next) {
 			if (a == console) {