Re: PATCH: tty locking for 2.6.9rc2

Paul Fulghum
2004-09-15T20:26:48Z

Alan:

Here is a patch against your last patch that clears
up both the per tty refcount initialization and
the remove_dev() global refcount leak.

I've tested it and it seems to work.

The patch is not meant to be applied and
is just for your information in deciding
how you want the final code to look.

--- linux-2.6.9/drivers/char/tty_io.c 2004-09-15 15:19:58.044611590 -0500
+++ linux-2.6.9-mg/drivers/char/tty_io.c 2004-09-15 15:19:34.690680997 -0500
@@ -288,6 +288,7 @@
}
else
ld = NULL;
+ if (ld) printk("tty_ldisc_get ld=%p refcount=%d\n", ld, ld->refcount);
spin_unlock_irqrestore(&tty_ldisc_lock, flags);
return ld;
}
@@ -307,6 +308,7 @@
if(ld->refcount == 0)
BUG();
ld->refcount --;
+ printk("tty_ldisc_put ld=%p refcount=%d\n", ld, ld->refcount);
module_put(ld->owner);
spin_unlock_irqrestore(&tty_ldisc_lock, flags);
}
@@ -497,6 +499,7 @@

/* Now set up the new line discipline. */
tty->ldisc = *ld;
+ tty->ldisc.refcount = 0;
tty->termios->c_line = ldisc;
if (tty->ldisc.open)
retval = (tty->ldisc.open)(tty);
@@ -504,11 +507,13 @@
tty_ldisc_put(ldisc);
/* There is an outstanding reference here so this is safe */
tty->ldisc = *tty_ldisc_get(o_ldisc.num);
+ tty->ldisc.refcount = 0;
tty->termios->c_line = tty->ldisc.num;
if (tty->ldisc.open && (tty->ldisc.open(tty) < 0)) {
tty_ldisc_put(o_ldisc.num);
/* This driver is always present */
tty->ldisc = *tty_ldisc_get(N_TTY);
+ tty->ldisc.refcount = 0;
tty->termios->c_line = N_TTY;
if (tty->ldisc.open) {
int r = tty->ldisc.open(tty);
@@ -1567,15 +1572,15 @@
/*
* Switch the line discipline back
*/
- tty->ldisc = *tty_ldisc_get(N_TTY);
- tty->termios->c_line = N_TTY;
+// tty->ldisc = *tty_ldisc_get(N_TTY);
+// tty->termios->c_line = N_TTY;
if (o_tty) {
/* FIXME: could o_tty be in setldisc here ? */
clear_bit(TTY_LDISC, &o_tty->flags);
if (o_tty->ldisc.close)
(o_tty->ldisc.close)(o_tty);
tty_ldisc_put(o_tty->ldisc.num);
- o_tty->ldisc = *tty_ldisc_get(N_TTY);
+// o_tty->ldisc = *tty_ldisc_get(N_TTY);
}

/*
@@ -2466,6 +2471,7 @@
memset(tty, 0, sizeof(struct tty_struct));
tty->magic = TTY_MAGIC;
tty->ldisc = *tty_ldisc_get(N_TTY);
+ tty->ldisc.refcount = 0;
tty->pgrp = -1;
tty->flip.char_buf_ptr = tty->flip.char_buf;
tty->flip.flag_buf_ptr = tty->flip.flag_buf;

Thanks,
Paul

--
Paul Fulghum
paulkf@microgate.com