Remove pty_ops_bsd and pty_bsd_ioctl() as they're not used
PATCH 1/1 Remove pty_ops_bsd and pty_bsd_ioctl() as they're not used
Remove pty_ops_bsd as nothing appears to use it anymore. It results in the following warning:
drivers/char/pty.c:344: warning: unused variable `pty_ops_bsd'
if CONFIG_LEGACY_PTYS=y.
Also remove pty_bsd_ioctl() as that's only referred to by pty_ops_bsd.
Possibly legacy_pty_init() should be passing this to tty_set_operations() rather than pty_ops.
---
drivers/char/pty.c | 23 ----------------------- 1 files changed, 0 insertions(+), 23 deletions(-)
drivers/char/pty.c +0 -23
@@ -328,32 +328,9 @@ static const struct tty_operations pty_ops = {#ifdef CONFIG_LEGACY_PTYS static struct tty_driver *pty_driver, *pty_slave_driver; -static int pty_bsd_ioctl (struct tty_struct *tty,struct file *file, -unsigned int cmd,unsigned long arg) -{ -switch (cmd) { -case TIOCSPTLCK :/* Set PT Lock (disallow slave open) */ -return pty_set_lock (tty, (int __user *) arg); - } -return -ENOIOCTLCMD ; -} -static int legacy_count =CONFIG_LEGACY_PTY_COUNT ;module_param (legacy_count, int,0 ); -static const struct tty_operations pty_ops_bsd = { - .open = pty_open, - .close = pty_close, - .write = pty_write, - .write_room = pty_write_room, - .flush_buffer = pty_flush_buffer, - .chars_in_buffer = pty_chars_in_buffer, - .unthrottle = pty_unthrottle, - .set_termios = pty_set_termios, - .ioctl = pty_bsd_ioctl, - .resize = pty_resize -}; -static void __init legacy_pty_init (void ) {if (legacy_count <=0 )
Quoted 11 lines · On Mon, 28 Sep 2009 14:53:32 +0100 David Howells <[email protected]> wrote:
Remove
pty_ops_bsdas nothing appears to use it anymore. It results in the following warning:
drivers/char/pty.c:344: warning: unused variable `pty_ops_bsd'if
CONFIG_LEGACY_PTYS=y.Also remove
pty_bsd_ioctl()as that's only referred to bypty_ops_bsd.Possibly
legacy_pty_init()should be passing this totty_set_operations()rather thanpty_ops.
It should indeed, otherwise the BSD pty locking ioctl fails.
Quoted 7 lines · Alan Cox
Quoted 3 lines · On Mon, 28 Sep 2009 14:53:32 +0100 David Howells <[email protected]> wrote:
Possibly
legacy_pty_init()should be passing this totty_set_operations()rather thanpty_ops.It should indeed, otherwise the BSD pty locking ioctl fails.
Hmm. The pty_ops_bsd thing is missing the .install handler. And looking at it, I'm not immediately seeing the difference between the pty_install handler and the pty_unix98_install one. There's some differences in termios initialization, and there is that
driver->other->ttys[idx] = o_tty; driver->ttys[idx] = tty
thing, but it's not entirely clear to me why the legacy pty's don't use the 'lookup()' logic instead (like the unix98 ones). Oh well.
Does anybody want to test this patch?
And is there any situation where this can be actually noticed? You obviously need to have an old distro that actually uses the old static pty setup.
Linus
--- drivers/char/pty.c | 24 ++++++------------------ 1 files changed, 6 insertions(+), 18 deletions(-)
drivers/char/pty.c +6 -18
@@ -261,6 +261,9 @@ done:return 0 ; } +/* Traditional BSD devices */ +#ifdef CONFIG_LEGACY_PTYS +static int pty_install (struct tty_driver *driver,struct tty_struct *tty) {struct tty_struct *o_tty;
@@ -310,22 +313,6 @@ free_mem_out:return -ENOMEM ; } - -static const struct tty_operations pty_ops = { - .install = pty_install, - .open = pty_open, - .close = pty_close, - .write = pty_write, - .write_room = pty_write_room, - .flush_buffer = pty_flush_buffer, - .chars_in_buffer = pty_chars_in_buffer, - .unthrottle = pty_unthrottle, - .set_termios = pty_set_termios, - .resize = pty_resize -}; - -/* Traditional BSD devices */ -#ifdef CONFIG_LEGACY_PTYS static struct tty_driver *pty_driver, *pty_slave_driver; static int pty_bsd_ioctl(struct tty_struct *tty, struct file *file,
@@ -342,6 +329,7 @@ static int legacy_count = CONFIG_LEGACY_PTY_COUNT;module_param (legacy_count, int,0 );static const struct tty_operations pty_ops_bsd = { + .install = pty_install, .open = pty_open, .close = pty_close, .write = pty_write,
@@ -383,7 +371,7 @@ static void __init legacy_pty_init(void) pty_driver->init_termios.c_ospeed =38400 ; pty_driver->flags =TTY_DRIVER_RESET_TERMIOS |TTY_DRIVER_REAL_RAW ; pty_driver->other = pty_slave_driver; -tty_set_operations (pty_driver, &pty_ops); +tty_set_operations (pty_driver, &pty_ops_bsd); pty_slave_driver->owner =THIS_MODULE ; pty_slave_driver->driver_name ="pty_slave" ;
@@ -399,7 +387,7 @@ static void __init legacy_pty_init(void) pty_slave_driver->flags =TTY_DRIVER_RESET_TERMIOS |TTY_DRIVER_REAL_RAW ; pty_slave_driver->other = pty_driver; -tty_set_operations (pty_slave_driver, &pty_ops); +tty_set_operations (pty_slave_driver, &pty_ops_bsd);if (tty_register_driver (pty_driver))panic ("Couldn't register pty driver" );
drivers/char/pty.c static void __init legacy_pty_init(void) · line 393
Quoted 13 lines · Linus Torvalds
drivers/char/pty.c +1
-1pty_slave_driver->owner =THIS_MODULE ; pty_slave_driver->driver_name ="pty_slave" ;@@ -399,7 +387,7 @@ static void __init legacy_pty_init(void) pty_slave_driver->flags =TTY_DRIVER_RESET_TERMIOS |TTY_DRIVER_REAL_RAW ; pty_slave_driver->other = pty_driver; -tty_set_operations (pty_slave_driver, &pty_ops); +tty_set_operations (pty_slave_driver, &pty_ops_bsd);if (tty_register_driver (pty_driver))panic ("Couldn't register pty driver" );
Is it right to use pty_ops_bsd in _both_ places? Looking at the code in linux-2.6.0, the BSD ioctl only applies to the master and doesn't apply to the slave.
David
Quoted 4 lines · David Howells
Is it right to use
pty_ops_bsdin _both_ places? Looking at the code in linux-2.6.0, the BSD ioctl only applies to the master and doesn't apply to the slave.
Right you are, good catch.
That said, I have to say that this whole pty lock thing seems to have been broken since 2.6.26, and even now, nobody actually _complained_. You found the problem due to a compiler warning rather than due to somebody noticing that pty_bsd_ioctl() is no longer hooked up.
Because as far as I can tell, the bug was introduced by commit 3e8e88ca053150efdbecb45d8f481cf560ec808d ("pty: prepare for tty->ops changes") back in April of 2008. That added the whole 'pty_ops_bsd' structure, but it has never actually been used.
So I do wonder whether the right thing to do would not be to simple remove the whole pty_ops_bsd code entirely. Or maybe mode the trivial TIOCSPTLCK into the generic tty ioctl handling, and just make it test for "driver->subtype == PTY_TYPE_MASTER" - and at least get rid of this subtle thing that was broken for over a year without anybody noticing..
Linus
Quoted 9 lines · Linus Torvalds
Quoted 4 lines · David Howells
Is it right to use
pty_ops_bsdin _both_ places? Looking at the code in linux-2.6.0, the BSD ioctl only applies to the master and doesn't apply to the slave.Right you are, good catch.
Anyway, here's an updated patch to just fix this part. Whether we need to have that crazy locking at all, considering that it was broken for 18 months, is still an interesting question. But this patch just tries to fix the long-time bug.
Comments?
Linus
--- drivers/char/pty.c | 43 ++++++++++++++++++++++++------------------- 1 files changed, 24 insertions(+), 19 deletions(-)
drivers/char/pty.c +24 -19
@@ -261,6 +261,9 @@ done:return 0 ; } +/* Traditional BSD devices */ +#ifdef CONFIG_LEGACY_PTYS +static int pty_install (struct tty_driver *driver,struct tty_struct *tty) {struct tty_struct *o_tty;
@@ -310,22 +313,6 @@ free_mem_out:return -ENOMEM ; } - -static const struct tty_operations pty_ops = { - .install = pty_install, - .open = pty_open, - .close = pty_close, - .write = pty_write, - .write_room = pty_write_room, - .flush_buffer = pty_flush_buffer, - .chars_in_buffer = pty_chars_in_buffer, - .unthrottle = pty_unthrottle, - .set_termios = pty_set_termios, - .resize = pty_resize -}; - -/* Traditional BSD devices */ -#ifdef CONFIG_LEGACY_PTYS static struct tty_driver *pty_driver, *pty_slave_driver; static int pty_bsd_ioctl(struct tty_struct *tty, struct file *file,
@@ -341,7 +328,12 @@ static int pty_bsd_ioctl(struct tty_struct *tty, struct file *file,static int legacy_count =CONFIG_LEGACY_PTY_COUNT ;module_param (legacy_count, int,0 ); -static const struct tty_operations pty_ops_bsd = { +/* +* The master side of a pty can do TIOCSPTLCK and thus +* has pty_bsd_ioctl. +*/ +static const struct tty_operations master_pty_ops_bsd = { + .install = pty_install, .open = pty_open, .close = pty_close, .write = pty_write,
@@ -354,6 +346,19 @@ static const struct tty_operations pty_ops_bsd = { .resize = pty_resize }; +static const struct tty_operations slave_pty_ops_bsd = { + .install = pty_install, + .open = pty_open, + .close = pty_close, + .write = pty_write, + .write_room = pty_write_room, + .flush_buffer = pty_flush_buffer, + .chars_in_buffer = pty_chars_in_buffer, + .unthrottle = pty_unthrottle, + .set_termios = pty_set_termios, + .resize = pty_resize +}; +static void __init legacy_pty_init (void ) {if (legacy_count <=0 )
@@ -383,7 +388,7 @@ static void __init legacy_pty_init(void) pty_driver->init_termios.c_ospeed =38400 ; pty_driver->flags =TTY_DRIVER_RESET_TERMIOS |TTY_DRIVER_REAL_RAW ; pty_driver->other = pty_slave_driver; -tty_set_operations (pty_driver, &pty_ops); +tty_set_operations (pty_driver, &master_pty_ops_bsd); pty_slave_driver->owner =THIS_MODULE ; pty_slave_driver->driver_name ="pty_slave" ;
@@ -399,7 +404,7 @@ static void __init legacy_pty_init(void) pty_slave_driver->flags =TTY_DRIVER_RESET_TERMIOS |TTY_DRIVER_REAL_RAW ; pty_slave_driver->other = pty_driver; -tty_set_operations (pty_slave_driver, &pty_ops); +tty_set_operations (pty_slave_driver, &slave_pty_ops_bsd);if (tty_register_driver (pty_driver))panic ("Couldn't register pty driver" );
David Howells
Acked-byQuoted 1 line · Linus Torvalds
Comments?
Perhaps add legacy pty support to the list of features to be removed and see who howls.
Quoted 1 line
static struct
tty_driver*pty_driver,*pty_slave_driver;
These shouldn't be global variables. They're only used within legacy_pty_init(). That's a side issue, however.
Apart from that, it looks reasonable.
Quoted 6 lines · On Tue, 29 Sep 2009 19:40:10 +0100 David Howells <[email protected]> wrote:
Quoted 1 line · Linus Torvalds
Comments?
Perhaps add legacy pty support to the list of features to be removed and see who howls.
You do break stuff still and they are part of the API, ABI and namespace so you break compatibility.
Quoted 4 lines
Quoted 1 line
static struct
tty_driver*pty_driver,*pty_slave_driver;These shouldn't be global variables. They're only used within
legacy_pty_init(). That's a side issue, however.
Agreed
Quoted 5 lines · Linus Torvalds
So I do wonder whether the right thing to do would not be to simple remove the whole
pty_ops_bsdcode entirely. Or maybe mode the trivial TIOCSPTLCK into the generic tty ioctl handling, and just make it test for "driver->subtype==PTY_TYPE_MASTER" - and at least get rid of this subtle thing that was broken for over a year without anybody noticing..
Also, does it matter if someone issues TIOCGPTN on a legacy pty master? There is a number in tty->index that can be returned. If it can, then pty_bsd_ioctl() can be merged with pty_unix98_ioctl(), and possibly both ioctls can be given to the generic tty ioctl handling with the condition that driver->subtype == PTY_TYPE_MASTER.
David
O> Also, does it matter if someone issues TIOCGPTN on a legacy pty master? There
Quoted 1 line
is a number in
tty->indexthat can be returned. If it can, then
Not a lot - providing someone isn't using it as a way to tell pty types apart (which I have seen done in example code)
Quoted 2 lines
pty_bsd_ioctl()can be merged withpty_unix98_ioctl(), and possibly both ioctls can be given to the generic tty ioctl handling
I would keep
if (type == FOO)
as far away from the generic tty ioctl code as possible. It's already convoluted and complex with zillions of ioctl calls. Separating out lots of the console and other ioctls properly cleaned it up no end and going backwards would be a bad mistake.
Quoted 4 lines · Alan Cox
Quoted 2 lines
Possibly
legacy_pty_init()should be passing this totty_set_operations()rather thanpty_ops.It should indeed, otherwise the BSD pty locking ioctl fails.
In that case, what should be using pty_ops? If CONFIG_LEGACY_PTYS=n, then I see:
drivers/char/pty.c:314: warning: unused variable `pty_ops'
David
Quoted 11 lines · On Mon, 28 Sep 2009 15:55:44 +0100 David Howells <[email protected]> wrote:
Quoted 4 lines · Alan Cox
Quoted 2 lines
Possibly
legacy_pty_init()should be passing this totty_set_operations()rather thanpty_ops.It should indeed, otherwise the BSD pty locking ioctl fails.
In that case, what should be using
pty_ops? IfCONFIG_LEGACY_PTYS=n, then I see:
drivers/char/pty.c:314: warning: unused variable `pty_ops'
You'd have to go and check the old code but I believe one side of the BSD pair uses pty_ops the other pty_bsd ops, and unix98 uses different ops again.
All it does is make sure the right ioctls appear on the right devices. Quite why the can't all use one and a simple if in the ioctl handler I'm not sure