diff options
author | Sukadev Bhattiprolu <sukadev@us.ibm.com> | 2008-04-30 03:54:21 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2008-04-30 11:29:48 -0400 |
commit | 718a916338e821a10961e6a7a17430c18e5e58d9 (patch) | |
tree | b261fd36e7a4f642223668596c85da62b60729a4 /drivers | |
parent | 4f8f9d66cdac4845409f7520e4f287a1907a6bf9 (diff) |
devpts: factor out PTY index allocation
Factor out the code used to allocate/free a pts index into new interfaces,
devpts_new_index() and devpts_kill_index(). This localizes the external data
structures used in managing the pts indices.
[akpm@linux-foundation.org: undo accidental mutex2sem conversion]
Signed-off-by: Sukadev Bhattiprolu <sukadev@us.ibm.com>
Signed-off-by: Serge Hallyn <serue@us.ibm.com>
Signed-off-by: Matt Helsley <matthltc@us.ibm.com>
Acked-by: H. Peter Anvin <hpa@zytor.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/char/tty_io.c | 40 |
1 files changed, 6 insertions, 34 deletions
diff --git a/drivers/char/tty_io.c b/drivers/char/tty_io.c index edcb7e471f02..1d298c2cf930 100644 --- a/drivers/char/tty_io.c +++ b/drivers/char/tty_io.c | |||
@@ -91,7 +91,6 @@ | |||
91 | #include <linux/module.h> | 91 | #include <linux/module.h> |
92 | #include <linux/smp_lock.h> | 92 | #include <linux/smp_lock.h> |
93 | #include <linux/device.h> | 93 | #include <linux/device.h> |
94 | #include <linux/idr.h> | ||
95 | #include <linux/wait.h> | 94 | #include <linux/wait.h> |
96 | #include <linux/bitops.h> | 95 | #include <linux/bitops.h> |
97 | #include <linux/delay.h> | 96 | #include <linux/delay.h> |
@@ -137,9 +136,6 @@ EXPORT_SYMBOL(tty_mutex); | |||
137 | 136 | ||
138 | #ifdef CONFIG_UNIX98_PTYS | 137 | #ifdef CONFIG_UNIX98_PTYS |
139 | extern struct tty_driver *ptm_driver; /* Unix98 pty masters; for /dev/ptmx */ | 138 | extern struct tty_driver *ptm_driver; /* Unix98 pty masters; for /dev/ptmx */ |
140 | extern int pty_limit; /* Config limit on Unix98 ptys */ | ||
141 | static DEFINE_IDR(allocated_ptys); | ||
142 | static DEFINE_MUTEX(allocated_ptys_lock); | ||
143 | static int ptmx_open(struct inode *, struct file *); | 139 | static int ptmx_open(struct inode *, struct file *); |
144 | #endif | 140 | #endif |
145 | 141 | ||
@@ -2639,15 +2635,9 @@ static void release_dev(struct file *filp) | |||
2639 | */ | 2635 | */ |
2640 | release_tty(tty, idx); | 2636 | release_tty(tty, idx); |
2641 | 2637 | ||
2642 | #ifdef CONFIG_UNIX98_PTYS | ||
2643 | /* Make this pty number available for reallocation */ | 2638 | /* Make this pty number available for reallocation */ |
2644 | if (devpts) { | 2639 | if (devpts) |
2645 | mutex_lock(&allocated_ptys_lock); | 2640 | devpts_kill_index(idx); |
2646 | idr_remove(&allocated_ptys, idx); | ||
2647 | mutex_unlock(&allocated_ptys_lock); | ||
2648 | } | ||
2649 | #endif | ||
2650 | |||
2651 | } | 2641 | } |
2652 | 2642 | ||
2653 | /** | 2643 | /** |
@@ -2803,29 +2793,13 @@ static int ptmx_open(struct inode *inode, struct file *filp) | |||
2803 | struct tty_struct *tty; | 2793 | struct tty_struct *tty; |
2804 | int retval; | 2794 | int retval; |
2805 | int index; | 2795 | int index; |
2806 | int idr_ret; | ||
2807 | 2796 | ||
2808 | nonseekable_open(inode, filp); | 2797 | nonseekable_open(inode, filp); |
2809 | 2798 | ||
2810 | /* find a device that is not in use. */ | 2799 | /* find a device that is not in use. */ |
2811 | mutex_lock(&allocated_ptys_lock); | 2800 | index = devpts_new_index(); |
2812 | if (!idr_pre_get(&allocated_ptys, GFP_KERNEL)) { | 2801 | if (index < 0) |
2813 | mutex_unlock(&allocated_ptys_lock); | 2802 | return index; |
2814 | return -ENOMEM; | ||
2815 | } | ||
2816 | idr_ret = idr_get_new(&allocated_ptys, NULL, &index); | ||
2817 | if (idr_ret < 0) { | ||
2818 | mutex_unlock(&allocated_ptys_lock); | ||
2819 | if (idr_ret == -EAGAIN) | ||
2820 | return -ENOMEM; | ||
2821 | return -EIO; | ||
2822 | } | ||
2823 | if (index >= pty_limit) { | ||
2824 | idr_remove(&allocated_ptys, index); | ||
2825 | mutex_unlock(&allocated_ptys_lock); | ||
2826 | return -EIO; | ||
2827 | } | ||
2828 | mutex_unlock(&allocated_ptys_lock); | ||
2829 | 2803 | ||
2830 | mutex_lock(&tty_mutex); | 2804 | mutex_lock(&tty_mutex); |
2831 | retval = init_dev(ptm_driver, index, &tty); | 2805 | retval = init_dev(ptm_driver, index, &tty); |
@@ -2850,9 +2824,7 @@ out1: | |||
2850 | release_dev(filp); | 2824 | release_dev(filp); |
2851 | return retval; | 2825 | return retval; |
2852 | out: | 2826 | out: |
2853 | mutex_lock(&allocated_ptys_lock); | 2827 | devpts_kill_index(index); |
2854 | idr_remove(&allocated_ptys, index); | ||
2855 | mutex_unlock(&allocated_ptys_lock); | ||
2856 | return retval; | 2828 | return retval; |
2857 | } | 2829 | } |
2858 | #endif | 2830 | #endif |