diff options
author | Jiri Slaby <jslaby@suse.cz> | 2012-10-18 16:26:28 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2012-10-22 19:50:12 -0400 |
commit | 162b97cfa21f816f39ede1944f2a4220e3cf8969 (patch) | |
tree | 6cd663b2b17c3013285148efd43a145d6dea9a5e | |
parent | 8fcbaa2b7f5b70dba9ed1c7f91d0a270ce752e2c (diff) |
TTY: devpts, return created inode from devpts_pty_new
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.
For the cleanup of layering, we will need the inode created in
devpts_pty_new to be stored into slave's driver_data. So we convert
devpts_pty_new to return the inode or an ERR_PTR-encoded error in case
of failure.
The move of 'inode = new_inode(sb);' from declarators to the code is
only cosmetical, but it makes the code easier to read.
Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Acked-by: Alan Cox <alan@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r-- | drivers/tty/pty.c | 7 | ||||
-rw-r--r-- | fs/devpts/inode.c | 12 | ||||
-rw-r--r-- | include/linux/devpts_fs.h | 8 |
3 files changed, 15 insertions, 12 deletions
diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c index 65f767154d12..9985b451e937 100644 --- a/drivers/tty/pty.c +++ b/drivers/tty/pty.c | |||
@@ -614,6 +614,7 @@ static const struct tty_operations pty_unix98_ops = { | |||
614 | static int ptmx_open(struct inode *inode, struct file *filp) | 614 | static int ptmx_open(struct inode *inode, struct file *filp) |
615 | { | 615 | { |
616 | struct tty_struct *tty; | 616 | struct tty_struct *tty; |
617 | struct inode *slave_inode; | ||
617 | int retval; | 618 | int retval; |
618 | int index; | 619 | int index; |
619 | 620 | ||
@@ -650,9 +651,11 @@ static int ptmx_open(struct inode *inode, struct file *filp) | |||
650 | 651 | ||
651 | tty_add_file(tty, filp); | 652 | tty_add_file(tty, filp); |
652 | 653 | ||
653 | retval = devpts_pty_new(inode, tty->link); | 654 | slave_inode = devpts_pty_new(inode, tty->link); |
654 | if (retval) | 655 | if (IS_ERR(slave_inode)) { |
656 | retval = PTR_ERR(slave_inode); | ||
655 | goto err_release; | 657 | goto err_release; |
658 | } | ||
656 | 659 | ||
657 | retval = ptm_driver->ops->open(tty, filp); | 660 | retval = ptm_driver->ops->open(tty, filp); |
658 | if (retval) | 661 | if (retval) |
diff --git a/fs/devpts/inode.c b/fs/devpts/inode.c index 47965807884d..ec3bab716c05 100644 --- a/fs/devpts/inode.c +++ b/fs/devpts/inode.c | |||
@@ -545,7 +545,7 @@ void devpts_kill_index(struct inode *ptmx_inode, int idx) | |||
545 | mutex_unlock(&allocated_ptys_lock); | 545 | mutex_unlock(&allocated_ptys_lock); |
546 | } | 546 | } |
547 | 547 | ||
548 | int devpts_pty_new(struct inode *ptmx_inode, struct tty_struct *tty) | 548 | struct inode *devpts_pty_new(struct inode *ptmx_inode, struct tty_struct *tty) |
549 | { | 549 | { |
550 | /* tty layer puts index from devpts_new_index() in here */ | 550 | /* tty layer puts index from devpts_new_index() in here */ |
551 | int number = tty->index; | 551 | int number = tty->index; |
@@ -553,19 +553,19 @@ int devpts_pty_new(struct inode *ptmx_inode, struct tty_struct *tty) | |||
553 | dev_t device = MKDEV(driver->major, driver->minor_start+number); | 553 | dev_t device = MKDEV(driver->major, driver->minor_start+number); |
554 | struct dentry *dentry; | 554 | struct dentry *dentry; |
555 | struct super_block *sb = pts_sb_from_inode(ptmx_inode); | 555 | struct super_block *sb = pts_sb_from_inode(ptmx_inode); |
556 | struct inode *inode = new_inode(sb); | 556 | struct inode *inode; |
557 | struct dentry *root = sb->s_root; | 557 | struct dentry *root = sb->s_root; |
558 | struct pts_fs_info *fsi = DEVPTS_SB(sb); | 558 | struct pts_fs_info *fsi = DEVPTS_SB(sb); |
559 | struct pts_mount_opts *opts = &fsi->mount_opts; | 559 | struct pts_mount_opts *opts = &fsi->mount_opts; |
560 | int ret = 0; | ||
561 | char s[12]; | 560 | char s[12]; |
562 | 561 | ||
563 | /* We're supposed to be given the slave end of a pty */ | 562 | /* We're supposed to be given the slave end of a pty */ |
564 | BUG_ON(driver->type != TTY_DRIVER_TYPE_PTY); | 563 | BUG_ON(driver->type != TTY_DRIVER_TYPE_PTY); |
565 | BUG_ON(driver->subtype != PTY_TYPE_SLAVE); | 564 | BUG_ON(driver->subtype != PTY_TYPE_SLAVE); |
566 | 565 | ||
566 | inode = new_inode(sb); | ||
567 | if (!inode) | 567 | if (!inode) |
568 | return -ENOMEM; | 568 | return ERR_PTR(-ENOMEM); |
569 | 569 | ||
570 | inode->i_ino = number + 3; | 570 | inode->i_ino = number + 3; |
571 | inode->i_uid = opts->setuid ? opts->uid : current_fsuid(); | 571 | inode->i_uid = opts->setuid ? opts->uid : current_fsuid(); |
@@ -585,12 +585,12 @@ int devpts_pty_new(struct inode *ptmx_inode, struct tty_struct *tty) | |||
585 | fsnotify_create(root->d_inode, dentry); | 585 | fsnotify_create(root->d_inode, dentry); |
586 | } else { | 586 | } else { |
587 | iput(inode); | 587 | iput(inode); |
588 | ret = -ENOMEM; | 588 | inode = ERR_PTR(-ENOMEM); |
589 | } | 589 | } |
590 | 590 | ||
591 | mutex_unlock(&root->d_inode->i_mutex); | 591 | mutex_unlock(&root->d_inode->i_mutex); |
592 | 592 | ||
593 | return ret; | 593 | return inode; |
594 | } | 594 | } |
595 | 595 | ||
596 | void *devpts_get_priv(struct inode *pts_inode) | 596 | void *devpts_get_priv(struct inode *pts_inode) |
diff --git a/include/linux/devpts_fs.h b/include/linux/devpts_fs.h index de635a5505ea..4ca846f16fe5 100644 --- a/include/linux/devpts_fs.h +++ b/include/linux/devpts_fs.h | |||
@@ -20,7 +20,7 @@ | |||
20 | int devpts_new_index(struct inode *ptmx_inode); | 20 | int devpts_new_index(struct inode *ptmx_inode); |
21 | void devpts_kill_index(struct inode *ptmx_inode, int idx); | 21 | void devpts_kill_index(struct inode *ptmx_inode, int idx); |
22 | /* mknod in devpts */ | 22 | /* mknod in devpts */ |
23 | int devpts_pty_new(struct inode *ptmx_inode, struct tty_struct *tty); | 23 | struct inode *devpts_pty_new(struct inode *ptmx_inode, struct tty_struct *tty); |
24 | /* get private structure */ | 24 | /* get private structure */ |
25 | void *devpts_get_priv(struct inode *pts_inode); | 25 | void *devpts_get_priv(struct inode *pts_inode); |
26 | /* unlink */ | 26 | /* unlink */ |
@@ -31,10 +31,10 @@ void devpts_pty_kill(struct tty_struct *tty); | |||
31 | /* Dummy stubs in the no-pty case */ | 31 | /* Dummy stubs in the no-pty case */ |
32 | static inline int devpts_new_index(struct inode *ptmx_inode) { return -EINVAL; } | 32 | static inline int devpts_new_index(struct inode *ptmx_inode) { return -EINVAL; } |
33 | static inline void devpts_kill_index(struct inode *ptmx_inode, int idx) { } | 33 | static inline void devpts_kill_index(struct inode *ptmx_inode, int idx) { } |
34 | static inline int devpts_pty_new(struct inode *ptmx_inode, | 34 | static inline struct inode *devpts_pty_new(struct inode *ptmx_inode, |
35 | struct tty_struct *tty) | 35 | struct tty_struct *tty) |
36 | { | 36 | { |
37 | return -EINVAL; | 37 | return ERR_PTR(-EINVAL); |
38 | } | 38 | } |
39 | static inline void *devpts_get_priv(struct inode *pts_inode) | 39 | static inline void *devpts_get_priv(struct inode *pts_inode) |
40 | { | 40 | { |