Commit d070a434 authored by Russell King's avatar Russell King Committed by Linus Torvalds

[PATCH] Provide console_device()

[This patch series has also been separately sent to the architecture
 maintainers]

Add console_device() to return the console tty driver structure and the
index.  Acquire the console lock while scanning the list of console drivers
to protect us against console driver list manipulations.
Signed-off-by: default avatarRussell King <rmk@arm.linux.org.uk>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent f8bd2a5f
...@@ -1363,13 +1363,8 @@ static int tty_open(struct inode * inode, struct file * filp) ...@@ -1363,13 +1363,8 @@ static int tty_open(struct inode * inode, struct file * filp)
} }
#endif #endif
if (device == MKDEV(TTYAUX_MAJOR,1)) { if (device == MKDEV(TTYAUX_MAJOR,1)) {
struct console *c = console_drivers; driver = console_device(&index);
for (c = console_drivers; c; c = c->next) { if (driver) {
if (!c->device)
continue;
driver = c->device(c, &index);
if (!driver)
continue;
/* Don't let /dev/console block */ /* Don't let /dev/console block */
filp->f_flags |= O_NONBLOCK; filp->f_flags |= O_NONBLOCK;
noctty = 1; noctty = 1;
......
...@@ -104,6 +104,7 @@ extern void acquire_console_sem(void); ...@@ -104,6 +104,7 @@ extern void acquire_console_sem(void);
extern void release_console_sem(void); extern void release_console_sem(void);
extern void console_conditional_schedule(void); extern void console_conditional_schedule(void);
extern void console_unblank(void); extern void console_unblank(void);
extern struct tty_driver *console_device(int *);
extern int is_console_locked(void); extern int is_console_locked(void);
/* Some debug stub to catch some of the obvious races in the VT code */ /* Some debug stub to catch some of the obvious races in the VT code */
......
...@@ -683,6 +683,26 @@ void console_unblank(void) ...@@ -683,6 +683,26 @@ void console_unblank(void)
} }
EXPORT_SYMBOL(console_unblank); EXPORT_SYMBOL(console_unblank);
/*
* Return the console tty driver structure and its associated index
*/
struct tty_driver *console_device(int *index)
{
struct console *c;
struct tty_driver *driver = NULL;
acquire_console_sem();
for (c = console_drivers; c != NULL; c = c->next) {
if (!c->device)
continue;
driver = c->device(c, index);
if (driver)
break;
}
release_console_sem();
return driver;
}
/* /*
* The console driver calls this routine during kernel initialization * The console driver calls this routine during kernel initialization
* to register the console printing procedure with printk() and to * to register the console printing procedure with printk() and to
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment