Skip to content

Commit a6f37da

Browse files
Sukadev Bhattiprolutorvalds
authored andcommitted
Simplify devpts_pty_kill
When creating a new pty, save the pty's inode in the tty->driver_data. Use this inode in pty_kill() to identify the devpts instance. Since we now have the inode for the pty, we can skip get_node() lookup and remove the unused get_node(). TODO: - check if the mutex_lock is needed in pty_kill(). Signed-off-by: Sukadev Bhattiprolu <sukadev@us.ibm.com> Signed-off-by: Alan Cox <alan@redhat.com> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 89a52e1 commit a6f37da

1 file changed

Lines changed: 12 additions & 17 deletions

File tree

‎fs/devpts/inode.c‎

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -170,14 +170,6 @@ static struct file_system_type devpts_fs_type = {
170170
* to the System V naming convention
171171
*/
172172

173-
static struct dentry *get_node(int num)
174-
{
175-
char s[12];
176-
struct dentry *root = devpts_root;
177-
mutex_lock(&root->d_inode->i_mutex);
178-
return lookup_one_len(s, root, sprintf(s, "%d", num));
179-
}
180-
181173
int devpts_new_index(struct inode *ptmx_inode)
182174
{
183175
int index;
@@ -235,6 +227,7 @@ int devpts_pty_new(struct inode *ptmx_inode, struct tty_struct *tty)
235227
inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
236228
init_special_inode(inode, S_IFCHR|config.mode, device);
237229
inode->i_private = tty;
230+
tty->driver_data = inode;
238231

239232
sprintf(s, "%d", number);
240233

@@ -262,18 +255,20 @@ struct tty_struct *devpts_get_tty(struct inode *pts_inode, int number)
262255

263256
void devpts_pty_kill(struct tty_struct *tty)
264257
{
265-
int number = tty->index;
266-
struct dentry *dentry = get_node(number);
258+
struct inode *inode = tty->driver_data;
259+
struct dentry *dentry;
267260

268-
if (!IS_ERR(dentry)) {
269-
struct inode *inode = dentry->d_inode;
270-
if (inode) {
271-
inode->i_nlink--;
272-
d_delete(dentry);
273-
dput(dentry);
274-
}
261+
BUG_ON(inode->i_rdev == MKDEV(TTYAUX_MAJOR, PTMX_MINOR));
262+
263+
mutex_lock(&devpts_root->d_inode->i_mutex);
264+
265+
dentry = d_find_alias(inode);
266+
if (dentry && !IS_ERR(dentry)) {
267+
inode->i_nlink--;
268+
d_delete(dentry);
275269
dput(dentry);
276270
}
271+
277272
mutex_unlock(&devpts_root->d_inode->i_mutex);
278273
}
279274

0 commit comments

Comments
 (0)