drivers/char/tty_io.c: Avoid panic when no console is configured.

When no console is configured tty_open tries to call kref_get on a NULL
pointer, return ENODEV instead.

Signed-off-by: Will Newton <will.newton@gmail.com>
Signed-off-by: Alan Cox <alan@redhat.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by Will Newton and committed by Linus Torvalds 296fa7f6 b4dcfbee

+9 -6
+9 -6
drivers/char/tty_io.c
··· 1795 } 1796 #endif 1797 if (device == MKDEV(TTYAUX_MAJOR, 1)) { 1798 - driver = tty_driver_kref_get(console_device(&index)); 1799 - if (driver) { 1800 - /* Don't let /dev/console block */ 1801 - filp->f_flags |= O_NONBLOCK; 1802 - noctty = 1; 1803 - goto got_driver; 1804 } 1805 mutex_unlock(&tty_mutex); 1806 return -ENODEV;
··· 1795 } 1796 #endif 1797 if (device == MKDEV(TTYAUX_MAJOR, 1)) { 1798 + struct tty_driver *console_driver = console_device(&index); 1799 + if (console_driver) { 1800 + driver = tty_driver_kref_get(console_driver); 1801 + if (driver) { 1802 + /* Don't let /dev/console block */ 1803 + filp->f_flags |= O_NONBLOCK; 1804 + noctty = 1; 1805 + goto got_driver; 1806 + } 1807 } 1808 mutex_unlock(&tty_mutex); 1809 return -ENODEV;