Skip to content

Commit

Permalink
TTY: move tty_lookup_driver to switch-cases
Browse files Browse the repository at this point in the history
The labels express more the nature of the decision tree. We returned
from each if with a driver. Now we do this at the end of the function
and the code flow is clear.

While at it, remove an obsolete comment (we already take the
reference).

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Cc: Alan Cox <alan@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
  • Loading branch information
Jiri Slaby authored and Greg Kroah-Hartman committed Nov 15, 2011
1 parent ba5db44 commit 2cd0050
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions drivers/tty/tty_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -1841,32 +1841,35 @@ static struct tty_driver *tty_lookup_driver(dev_t device, struct file *filp,
{
struct tty_driver *driver;

switch (device) {
#ifdef CONFIG_VT
if (device == MKDEV(TTY_MAJOR, 0)) {
case MKDEV(TTY_MAJOR, 0): {
extern struct tty_driver *console_driver;
driver = tty_driver_kref_get(console_driver);
*index = fg_console;
*noctty = 1;
return driver;
break;
}
#endif
if (device == MKDEV(TTYAUX_MAJOR, 1)) {
case MKDEV(TTYAUX_MAJOR, 1): {
struct tty_driver *console_driver = console_device(index);
if (console_driver) {
driver = tty_driver_kref_get(console_driver);
if (driver) {
/* Don't let /dev/console block */
filp->f_flags |= O_NONBLOCK;
*noctty = 1;
return driver;
break;
}
}
return ERR_PTR(-ENODEV);
}

driver = get_tty_driver(device, index);
if (!driver)
return ERR_PTR(-ENODEV);
default:
driver = get_tty_driver(device, index);
if (!driver)
return ERR_PTR(-ENODEV);
break;
}
return driver;
}

Expand Down

0 comments on commit 2cd0050

Please sign in to comment.