Commit 0f2721b9 authored by Greg Kroah-Hartman's avatar Greg Kroah-Hartman

TTY: add module reference counting for tty drivers.

Note, there are still races with unloading modules, this patch
does not fix that...
parent 9552d6bc
...@@ -833,6 +833,11 @@ static int init_dev(kdev_t device, struct tty_struct **ret_tty) ...@@ -833,6 +833,11 @@ static int init_dev(kdev_t device, struct tty_struct **ret_tty)
* and locked termios may be retained.) * and locked termios may be retained.)
*/ */
if (!try_module_get(driver->owner)) {
retval = -ENODEV;
goto end_init;
}
o_tty = NULL; o_tty = NULL;
tp = o_tp = NULL; tp = o_tp = NULL;
ltp = o_ltp = NULL; ltp = o_ltp = NULL;
...@@ -991,6 +996,7 @@ static int init_dev(kdev_t device, struct tty_struct **ret_tty) ...@@ -991,6 +996,7 @@ static int init_dev(kdev_t device, struct tty_struct **ret_tty)
free_tty_struct(tty); free_tty_struct(tty);
fail_no_mem: fail_no_mem:
module_put(driver->owner);
retval = -ENOMEM; retval = -ENOMEM;
goto end_init; goto end_init;
...@@ -1033,6 +1039,7 @@ static void release_mem(struct tty_struct *tty, int idx) ...@@ -1033,6 +1039,7 @@ static void release_mem(struct tty_struct *tty, int idx)
tty->magic = 0; tty->magic = 0;
(*tty->driver.refcount)--; (*tty->driver.refcount)--;
list_del(&tty->tty_files); list_del(&tty->tty_files);
module_put(tty->driver.owner);
free_tty_struct(tty); free_tty_struct(tty);
} }
......
...@@ -120,6 +120,7 @@ ...@@ -120,6 +120,7 @@
struct tty_driver { struct tty_driver {
int magic; /* magic number for this structure */ int magic; /* magic number for this structure */
struct module *owner;
const char *driver_name; const char *driver_name;
const char *name; const char *name;
int name_base; /* offset of printed name */ int name_base; /* offset of printed name */
......
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