Commit 484af54d authored by Jiri Slaby's avatar Jiri Slaby Committed by Greg Kroah-Hartman

TTY: pty, cleanup the pty counting

Instead of the hackish way of counting ptys, let's define a specific
->remove hook both from slave and master. And decrease the count only
for master.
Signed-off-by: default avatarJiri Slaby <jslaby@suse.cz>
Cc: Alan Cox <alan@linux.intel.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent c0d92be6
...@@ -446,19 +446,8 @@ static inline void legacy_pty_init(void) { } ...@@ -446,19 +446,8 @@ static inline void legacy_pty_init(void) { }
int pty_limit = NR_UNIX98_PTY_DEFAULT; int pty_limit = NR_UNIX98_PTY_DEFAULT;
static int pty_limit_min; static int pty_limit_min;
static int pty_limit_max = NR_UNIX98_PTY_MAX; static int pty_limit_max = NR_UNIX98_PTY_MAX;
static int tty_count;
static int pty_count; static int pty_count;
static inline void pty_inc_count(void)
{
pty_count = (++tty_count) / 2;
}
static inline void pty_dec_count(void)
{
pty_count = (--tty_count) / 2;
}
static struct cdev ptmx_cdev; static struct cdev ptmx_cdev;
static struct ctl_table pty_table[] = { static struct ctl_table pty_table[] = {
...@@ -600,8 +589,7 @@ static int pty_unix98_install(struct tty_driver *driver, struct tty_struct *tty) ...@@ -600,8 +589,7 @@ static int pty_unix98_install(struct tty_driver *driver, struct tty_struct *tty)
*/ */
tty_driver_kref_get(driver); tty_driver_kref_get(driver);
tty->count++; tty->count++;
pty_inc_count(); /* tty */ pty_count++;
pty_inc_count(); /* tty->link */
return 0; return 0;
err_free_mem: err_free_mem:
deinitialize_tty_struct(o_tty); deinitialize_tty_struct(o_tty);
...@@ -613,15 +601,19 @@ static int pty_unix98_install(struct tty_driver *driver, struct tty_struct *tty) ...@@ -613,15 +601,19 @@ static int pty_unix98_install(struct tty_driver *driver, struct tty_struct *tty)
return -ENOMEM; return -ENOMEM;
} }
static void pty_unix98_remove(struct tty_driver *driver, struct tty_struct *tty) static void ptm_unix98_remove(struct tty_driver *driver, struct tty_struct *tty)
{
pty_count--;
}
static void pts_unix98_remove(struct tty_driver *driver, struct tty_struct *tty)
{ {
pty_dec_count();
} }
static const struct tty_operations ptm_unix98_ops = { static const struct tty_operations ptm_unix98_ops = {
.lookup = ptm_unix98_lookup, .lookup = ptm_unix98_lookup,
.install = pty_unix98_install, .install = pty_unix98_install,
.remove = pty_unix98_remove, .remove = ptm_unix98_remove,
.open = pty_open, .open = pty_open,
.close = pty_close, .close = pty_close,
.write = pty_write, .write = pty_write,
...@@ -638,7 +630,7 @@ static const struct tty_operations ptm_unix98_ops = { ...@@ -638,7 +630,7 @@ static const struct tty_operations ptm_unix98_ops = {
static const struct tty_operations pty_unix98_ops = { static const struct tty_operations pty_unix98_ops = {
.lookup = pts_unix98_lookup, .lookup = pts_unix98_lookup,
.install = pty_unix98_install, .install = pty_unix98_install,
.remove = pty_unix98_remove, .remove = pts_unix98_remove,
.open = pty_open, .open = pty_open,
.close = pty_close, .close = pty_close,
.write = pty_write, .write = pty_write,
......
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