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

TTY: devpts, do not set driver_data

The goal is to stop setting and using tty->driver_data in devpts code.
It should be used solely by the driver's code, pty in this case.

Now driver_data are managed only in the pty driver. devpts_pty_new is
switched to accept what we used to dig out of tty_struct, i.e. device
node number and index.

This also removes a note about driver_data being set outside of the
driver.
Signed-off-by: default avatarJiri Slaby <jslaby@suse.cz>
Acked-by: default avatarAlan Cox <alan@linux.intel.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 162b97cf
...@@ -4,9 +4,6 @@ ...@@ -4,9 +4,6 @@
* Added support for a Unix98-style ptmx device. * Added support for a Unix98-style ptmx device.
* -- C. Scott Ananian <cananian@alumni.princeton.edu>, 14-Jan-1998 * -- C. Scott Ananian <cananian@alumni.princeton.edu>, 14-Jan-1998
* *
* When reading this code see also fs/devpts. In particular note that the
* driver_data field is used by the devpts side as a binding to the devpts
* inode.
*/ */
#include <linux/module.h> #include <linux/module.h>
...@@ -59,7 +56,7 @@ static void pty_close(struct tty_struct *tty, struct file *filp) ...@@ -59,7 +56,7 @@ static void pty_close(struct tty_struct *tty, struct file *filp)
#ifdef CONFIG_UNIX98_PTYS #ifdef CONFIG_UNIX98_PTYS
if (tty->driver == ptm_driver) { if (tty->driver == ptm_driver) {
mutex_lock(&devpts_mutex); mutex_lock(&devpts_mutex);
devpts_pty_kill(tty->link); devpts_pty_kill(tty->link->driver_data);
mutex_unlock(&devpts_mutex); mutex_unlock(&devpts_mutex);
} }
#endif #endif
...@@ -651,7 +648,9 @@ static int ptmx_open(struct inode *inode, struct file *filp) ...@@ -651,7 +648,9 @@ static int ptmx_open(struct inode *inode, struct file *filp)
tty_add_file(tty, filp); tty_add_file(tty, filp);
slave_inode = devpts_pty_new(inode, tty->link); slave_inode = devpts_pty_new(inode,
MKDEV(UNIX98_PTY_SLAVE_MAJOR, index), index,
tty->link);
if (IS_ERR(slave_inode)) { if (IS_ERR(slave_inode)) {
retval = PTR_ERR(slave_inode); retval = PTR_ERR(slave_inode);
goto err_release; goto err_release;
...@@ -662,6 +661,7 @@ static int ptmx_open(struct inode *inode, struct file *filp) ...@@ -662,6 +661,7 @@ static int ptmx_open(struct inode *inode, struct file *filp)
goto err_release; goto err_release;
tty_unlock(tty); tty_unlock(tty);
tty->link->driver_data = slave_inode;
return 0; return 0;
err_release: err_release:
tty_unlock(tty); tty_unlock(tty);
......
...@@ -545,12 +545,9 @@ void devpts_kill_index(struct inode *ptmx_inode, int idx) ...@@ -545,12 +545,9 @@ void devpts_kill_index(struct inode *ptmx_inode, int idx)
mutex_unlock(&allocated_ptys_lock); mutex_unlock(&allocated_ptys_lock);
} }
struct inode *devpts_pty_new(struct inode *ptmx_inode, struct tty_struct *tty) struct inode *devpts_pty_new(struct inode *ptmx_inode, dev_t device, int index,
void *priv)
{ {
/* tty layer puts index from devpts_new_index() in here */
int number = tty->index;
struct tty_driver *driver = tty->driver;
dev_t device = MKDEV(driver->major, driver->minor_start+number);
struct dentry *dentry; struct dentry *dentry;
struct super_block *sb = pts_sb_from_inode(ptmx_inode); struct super_block *sb = pts_sb_from_inode(ptmx_inode);
struct inode *inode; struct inode *inode;
...@@ -559,23 +556,18 @@ struct inode *devpts_pty_new(struct inode *ptmx_inode, struct tty_struct *tty) ...@@ -559,23 +556,18 @@ struct inode *devpts_pty_new(struct inode *ptmx_inode, struct tty_struct *tty)
struct pts_mount_opts *opts = &fsi->mount_opts; struct pts_mount_opts *opts = &fsi->mount_opts;
char s[12]; char s[12];
/* We're supposed to be given the slave end of a pty */
BUG_ON(driver->type != TTY_DRIVER_TYPE_PTY);
BUG_ON(driver->subtype != PTY_TYPE_SLAVE);
inode = new_inode(sb); inode = new_inode(sb);
if (!inode) if (!inode)
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
inode->i_ino = number + 3; inode->i_ino = index + 3;
inode->i_uid = opts->setuid ? opts->uid : current_fsuid(); inode->i_uid = opts->setuid ? opts->uid : current_fsuid();
inode->i_gid = opts->setgid ? opts->gid : current_fsgid(); inode->i_gid = opts->setgid ? opts->gid : current_fsgid();
inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME; inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
init_special_inode(inode, S_IFCHR|opts->mode, device); init_special_inode(inode, S_IFCHR|opts->mode, device);
inode->i_private = tty; inode->i_private = priv;
tty->driver_data = inode;
sprintf(s, "%d", number); sprintf(s, "%d", index);
mutex_lock(&root->d_inode->i_mutex); mutex_lock(&root->d_inode->i_mutex);
...@@ -613,9 +605,8 @@ void *devpts_get_priv(struct inode *pts_inode) ...@@ -613,9 +605,8 @@ void *devpts_get_priv(struct inode *pts_inode)
return priv; return priv;
} }
void devpts_pty_kill(struct tty_struct *tty) void devpts_pty_kill(struct inode *inode)
{ {
struct inode *inode = tty->driver_data;
struct super_block *sb = pts_sb_from_inode(inode); struct super_block *sb = pts_sb_from_inode(inode);
struct dentry *root = sb->s_root; struct dentry *root = sb->s_root;
struct dentry *dentry; struct dentry *dentry;
......
...@@ -20,11 +20,12 @@ ...@@ -20,11 +20,12 @@
int devpts_new_index(struct inode *ptmx_inode); int devpts_new_index(struct inode *ptmx_inode);
void devpts_kill_index(struct inode *ptmx_inode, int idx); void devpts_kill_index(struct inode *ptmx_inode, int idx);
/* mknod in devpts */ /* mknod in devpts */
struct inode *devpts_pty_new(struct inode *ptmx_inode, struct tty_struct *tty); struct inode *devpts_pty_new(struct inode *ptmx_inode, dev_t device, int index,
void *priv);
/* get private structure */ /* get private structure */
void *devpts_get_priv(struct inode *pts_inode); void *devpts_get_priv(struct inode *pts_inode);
/* unlink */ /* unlink */
void devpts_pty_kill(struct tty_struct *tty); void devpts_pty_kill(struct inode *inode);
#else #else
...@@ -32,7 +33,7 @@ void devpts_pty_kill(struct tty_struct *tty); ...@@ -32,7 +33,7 @@ void devpts_pty_kill(struct tty_struct *tty);
static inline int devpts_new_index(struct inode *ptmx_inode) { return -EINVAL; } static inline int devpts_new_index(struct inode *ptmx_inode) { return -EINVAL; }
static inline void devpts_kill_index(struct inode *ptmx_inode, int idx) { } static inline void devpts_kill_index(struct inode *ptmx_inode, int idx) { }
static inline struct inode *devpts_pty_new(struct inode *ptmx_inode, static inline struct inode *devpts_pty_new(struct inode *ptmx_inode,
struct tty_struct *tty) dev_t device, int index, void *priv)
{ {
return ERR_PTR(-EINVAL); return ERR_PTR(-EINVAL);
} }
...@@ -40,7 +41,7 @@ static inline void *devpts_get_priv(struct inode *pts_inode) ...@@ -40,7 +41,7 @@ static inline void *devpts_get_priv(struct inode *pts_inode)
{ {
return NULL; return NULL;
} }
static inline void devpts_pty_kill(struct tty_struct *tty) { } static inline void devpts_pty_kill(struct inode *inode) { }
#endif #endif
......
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