TTY cleanup patches

tytso@mit.edu
Wed, 11 Mar 1998 20:33:15 -0500


Hi Linus,

Could you apply the following patches to the 2.1 tree? They
clean up a long-standing non-retrant code path in the TTY code, and more
importantly, adds a printk message warning that the /dev/cua* devices
are deprecated, and that people really should be using more modern
application software that doesn't require callout devices, as that sort
of locking should be happening in userspace, and not in the kernel. I'd
really like that warning to go into 2.2, so that we can remove callout
device support sometime during the 2.3 development cycle. Thanks!!

- Ted

Patch generated: on Wed Mar 11 20:30:10 EST 1998 by tytso@rsts-11
against Linux version 2.1.89

===================================================================
RCS file: drivers/char/RCS/ChangeLog,v
retrieving revision 1.1
diff -u -r1.1 drivers/char/ChangeLog
--- drivers/char/ChangeLog 1998/03/07 17:32:31 1.1
+++ drivers/char/ChangeLog 1998/03/07 17:32:37
@@ -1,3 +1,11 @@
+Thu Feb 19 14:24:08 1998 Theodore Ts'o <tytso@rsts-11.mit.edu>
+
+ * tty_io.c (tty_name): Remove the non-reentrant (and non-SMP safe)
+ version of tty_name, and rename the reentrant _tty_name
+ function to be tty_name.
+ (tty_open): Add a warning message stating callout devices
+ are deprecated.
+
Mon Dec 1 08:24:15 1997 Theodore Ts'o <tytso@rsts-11.mit.edu>

* tty_io.c (tty_get_baud_rate): Print a warning syslog if the
===================================================================
RCS file: include/linux/RCS/tty.h,v
retrieving revision 1.1
diff -u -r1.1 include/linux/tty.h
--- include/linux/tty.h 1998/03/07 17:32:31 1.1
+++ include/linux/tty.h 1998/03/07 17:34:30
@@ -314,8 +314,7 @@

extern int tty_paranoia_check(struct tty_struct *tty, kdev_t device,
const char *routine);
-extern char *_tty_name(struct tty_struct *tty, char *buf);
-extern char *tty_name(struct tty_struct *tty);
+extern char *tty_name(struct tty_struct *tty, char *buf);
extern void tty_wait_until_sent(struct tty_struct * tty, int timeout);
extern int tty_check_change(struct tty_struct * tty);
extern void stop_tty(struct tty_struct * tty);
===================================================================
RCS file: drivers/char/RCS/tty_io.c,v
retrieving revision 1.1
diff -u -r1.1 drivers/char/tty_io.c
--- drivers/char/tty_io.c 1998/03/07 17:32:31 1.1
+++ drivers/char/tty_io.c 1998/03/07 17:32:37
@@ -127,11 +127,9 @@
#endif

/*
- * These two routines return the name of tty. tty_name() should NOT
- * be used in interrupt drivers, since it's not re-entrant. Use
- * _tty_name() instead.
+ * This routine returns the name of tty.
*/
-char *_tty_name(struct tty_struct *tty, char *buf)
+char *tty_name(struct tty_struct *tty, char *buf)
{
if (tty)
sprintf(buf, "%s%d", tty->driver.name,
@@ -142,13 +140,6 @@
return buf;
}

-char *tty_name(struct tty_struct *tty)
-{
- static char buf[64];
-
- return(_tty_name(tty, buf));
-}
-
inline int tty_paranoia_check(struct tty_struct *tty, kdev_t device,
const char *routine)
{
@@ -213,6 +204,7 @@
{
int retval = 0;
struct tty_ldisc o_ldisc;
+ char buf[64];

if ((ldisc < N_TTY) || (ldisc >= NR_LDISCS))
return -EINVAL;
@@ -254,7 +246,7 @@
if (r < 0)
panic("Couldn't open N_TTY ldisc for "
"%s --- error %d.",
- tty_name(tty), r);
+ tty_name(tty, buf), r);
}
}
}
@@ -455,7 +447,9 @@
void tty_hangup(struct tty_struct * tty)
{
#ifdef TTY_DEBUG_HANGUP
- printk("%s hangup...\n", tty_name(tty));
+ char buf[64];
+
+ printk("%s hangup...\n", tty_name(tty, buf));
#endif
queue_task(&tty->tq_hangup, &tq_timer);
}
@@ -463,7 +457,9 @@
void tty_vhangup(struct tty_struct * tty)
{
#ifdef TTY_DEBUG_HANGUP
- printk("%s vhangup...\n", tty_name(tty));
+ char buf[64];
+
+ printk("%s vhangup...\n", tty_name(tty, buf));
#endif
do_tty_hangup((void *) tty);
}
@@ -950,6 +946,7 @@
struct tty_struct *tty, *o_tty;
int pty_master, tty_closing, o_tty_closing, do_sleep;
int idx;
+ char buf[64];

tty = (struct tty_struct *)filp->private_data;
if (tty_paranoia_check(tty, filp->f_dentry->d_inode->i_rdev, "release_dev"))
@@ -990,7 +987,7 @@
#endif

#ifdef TTY_DEBUG_HANGUP
- printk("release_dev of %s (tty count=%d)...", tty_name(tty),
+ printk("release_dev of %s (tty count=%d)...", tty_name(tty, buf),
tty->count);
#endif

@@ -1068,7 +1065,7 @@
break;

printk("release_dev: %s: read/write wait queue active!\n",
- tty_name(tty));
+ tty_name(tty, buf));
schedule();
}

@@ -1084,13 +1081,13 @@
if (pty_master) {
if (--o_tty->count < 0) {
printk("release_dev: bad pty slave count (%d) for %s\n",
- o_tty->count, tty_name(o_tty));
+ o_tty->count, tty_name(o_tty, buf));
o_tty->count = 0;
}
}
if (--tty->count < 0) {
printk("release_dev: bad tty->count (%d) for %s\n",
- tty->count, tty_name(tty));
+ tty->count, tty_name(tty, buf));
tty->count = 0;
}

@@ -1178,6 +1175,7 @@
int noctty, retval;
kdev_t device;
unsigned short saved_flags;
+ char buf[64];

saved_flags = filp->f_flags;
retry_open:
@@ -1245,7 +1243,7 @@
tty->driver.subtype == PTY_TYPE_MASTER)
noctty = 1;
#ifdef TTY_DEBUG_HANGUP
- printk("opening %s...", tty_name(tty));
+ printk("opening %s...", tty_name(tty, buf));
#endif
if (tty->driver.open)
retval = tty->driver.open(tty, filp);
@@ -1258,7 +1256,8 @@

if (retval) {
#ifdef TTY_DEBUG_HANGUP
- printk("error %d in opening %s...", retval, tty_name(tty));
+ printk("error %d in opening %s...", retval,
+ tty_name(tty, buf));
#endif

release_dev(filp);
@@ -1281,6 +1280,11 @@
current->tty_old_pgrp = 0;
tty->session = current->session;
tty->pgrp = current->pgrp;
+ }
+ if ((tty->driver.type == TTY_DRIVER_TYPE_SERIAL) &&
+ (tty->driver.subtype == SERIAL_TYPE_CALLOUT)) {
+ printk("Warning, %s opened, is a deprecated tty "
+ "callout device\n", tty_name(tty, buf));
}
return 0;
}
===================================================================
RCS file: drivers/char/RCS/tty_ioctl.c,v
retrieving revision 1.1
diff -u -r1.1 drivers/char/tty_ioctl.c
--- drivers/char/tty_ioctl.c 1998/03/07 17:32:31 1.1
+++ drivers/char/tty_ioctl.c 1998/03/07 17:32:37
@@ -45,7 +45,9 @@
struct wait_queue wait = { current, NULL };

#ifdef TTY_DEBUG_WAIT_UNTIL_SENT
- printk("%s wait until sent...\n", tty_name(tty));
+ char buf[64];
+
+ printk("%s wait until sent...\n", tty_name(tty, buf));
#endif
if (!tty->driver.chars_in_buffer)
return;
@@ -57,7 +59,8 @@
current->timeout = (unsigned) -1;
do {
#ifdef TTY_DEBUG_WAIT_UNTIL_SENT
- printk("waiting %s...(%d)\n", tty_name(tty), tty->driver.chars_in_buffer(tty));
+ printk("waiting %s...(%d)\n", tty_name(tty, buf),
+ tty->driver.chars_in_buffer(tty));
#endif
current->state = TASK_INTERRUPTIBLE;
if (signal_pending(current))
===================================================================
RCS file: drivers/char/RCS/n_tty.c,v
retrieving revision 1.1
diff -u -r1.1 drivers/char/n_tty.c
--- drivers/char/n_tty.c 1998/03/07 17:32:31 1.1
+++ drivers/char/n_tty.c 1998/03/07 17:32:37
@@ -420,7 +420,7 @@

tty->num_overrun++;
if (tty->overrun_time < (jiffies - HZ)) {
- printk("%s: %d input overrun(s)\n", _tty_name(tty, buf),
+ printk("%s: %d input overrun(s)\n", tty_name(tty, buf),
tty->num_overrun);
tty->overrun_time = jiffies;
tty->num_overrun = 0;
@@ -656,6 +656,7 @@
const unsigned char *p;
char *f, flags = TTY_NORMAL;
int i;
+ char buf[64];

if (!tty->read_buf)
return;
@@ -693,8 +694,8 @@
n_tty_receive_overrun(tty);
break;
default:
- printk("%s: unknown flag %d\n", tty_name(tty),
- flags);
+ printk("%s: unknown flag %d\n",
+ tty_name(tty, buf), flags);
break;
}
}
===================================================================
RCS file: drivers/char/RCS/serial.c,v
retrieving revision 1.1
diff -u -r1.1 drivers/char/serial.c
--- drivers/char/serial.c 1998/03/07 17:32:31 1.1
+++ drivers/char/serial.c 1998/03/07 17:32:37
@@ -1652,7 +1652,7 @@
#ifdef SERIAL_DEBUG_THROTTLE
char buf[64];

- printk("throttle %s: %d....\n", _tty_name(tty, buf),
+ printk("throttle %s: %d....\n", tty_name(tty, buf),
tty->ldisc.chars_in_buffer(tty));
#endif

@@ -1676,7 +1676,7 @@
#ifdef SERIAL_DEBUG_THROTTLE
char buf[64];

- printk("unthrottle %s: %d....\n", _tty_name(tty, buf),
+ printk("unthrottle %s: %d....\n", tty_name(tty, buf),
tty->ldisc.chars_in_buffer(tty));
#endif

===================================================================
RCS file: drivers/char/RCS/esp.c,v
retrieving revision 1.1
diff -u -r1.1 drivers/char/esp.c
--- drivers/char/esp.c 1998/03/07 17:32:32 1.1
+++ drivers/char/esp.c 1998/03/07 17:32:37
@@ -1384,7 +1384,7 @@
#ifdef SERIAL_DEBUG_THROTTLE
char buf[64];

- printk("throttle %s: %d....\n", _tty_name(tty, buf),
+ printk("throttle %s: %d....\n", tty_name(tty, buf),
tty->ldisc.chars_in_buffer(tty));
#endif

@@ -1406,7 +1406,7 @@
#ifdef SERIAL_DEBUG_THROTTLE
char buf[64];

- printk("unthrottle %s: %d....\n", _tty_name(tty, buf),
+ printk("unthrottle %s: %d....\n", tty_name(tty, buf),
tty->ldisc.chars_in_buffer(tty));
#endif

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu