Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 73ec06fc authored by Alan Cox's avatar Alan Cox Committed by Linus Torvalds
Browse files

tty: Finish fixing up the init_dev interface to use ERR_PTR



Original suggestion and proposal from Sukadev Bhattiprolu.

Signed-off-by: default avatarAlan Cox <alan@redhat.com>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 8b0a88d5
Loading
Loading
Loading
Loading
+4 −2
Original line number Original line Diff line number Diff line
@@ -501,11 +501,13 @@ static int __ptmx_open(struct inode *inode, struct file *filp)
		return index;
		return index;


	mutex_lock(&tty_mutex);
	mutex_lock(&tty_mutex);
	retval = tty_init_dev(ptm_driver, index, &tty, 1);
	tty = tty_init_dev(ptm_driver, index, 1);
	mutex_unlock(&tty_mutex);
	mutex_unlock(&tty_mutex);


	if (retval)
	if (IS_ERR(tty)) {
		retval = PTR_ERR(tty);
		goto out;
		goto out;
	}


	set_bit(TTY_PTY_LOCK, &tty->flags); /* LOCK THE SLAVE */
	set_bit(TTY_PTY_LOCK, &tty->flags); /* LOCK THE SLAVE */
	filp->private_data = tty;
	filp->private_data = tty;
+21 −31
Original line number Original line Diff line number Diff line
@@ -1324,35 +1324,32 @@ static int tty_reopen(struct tty_struct *tty)
 * relaxed for the (most common) case of reopening a tty.
 * relaxed for the (most common) case of reopening a tty.
 */
 */


int tty_init_dev(struct tty_driver *driver, int idx,
struct tty_struct *tty_init_dev(struct tty_driver *driver, int idx,
	struct tty_struct **ret_tty, int first_ok)
								int first_ok)
{
{
	struct tty_struct *tty, *o_tty;
	struct tty_struct *tty, *o_tty;
	struct ktermios *tp, **tp_loc, *o_tp, **o_tp_loc;
	struct ktermios *tp, **tp_loc, *o_tp, **o_tp_loc;
	struct ktermios *ltp, **ltp_loc, *o_ltp, **o_ltp_loc;
	struct ktermios *ltp, **ltp_loc, *o_ltp, **o_ltp_loc;
	int retval = 0;
	int retval;


	/* check whether we're reopening an existing tty */
	/* check whether we're reopening an existing tty */
	tty = tty_driver_lookup_tty(driver, idx);
	tty = tty_driver_lookup_tty(driver, idx);
	if (IS_ERR(tty)) {

		retval = PTR_ERR(tty);
	if (IS_ERR(tty))
		goto end_init;
		return tty;
	}


	if (tty) {
	if (tty) {
		retval = tty_reopen(tty);
		retval = tty_reopen(tty);
		if (retval)
		if (retval)
			return retval;
			return ERR_PTR(retval);
		*ret_tty = tty;
		return tty;
		return 0;
	}
	}


	/* Check if pty master is being opened multiple times */
	/* Check if pty master is being opened multiple times */
	if (driver->subtype == PTY_TYPE_MASTER &&
	if (driver->subtype == PTY_TYPE_MASTER &&
		(driver->flags & TTY_DRIVER_DEVPTS_MEM) && !first_ok) {
		(driver->flags & TTY_DRIVER_DEVPTS_MEM) && !first_ok)
		retval = -EIO;
		return ERR_PTR(-EIO);
		goto end_init;

	}
	/*
	/*
	 * First time open is complex, especially for PTY devices.
	 * First time open is complex, especially for PTY devices.
	 * This code guarantees that either everything succeeds and the
	 * This code guarantees that either everything succeeds and the
@@ -1361,10 +1358,8 @@ int tty_init_dev(struct tty_driver *driver, int idx,
	 * and locked termios may be retained.)
	 * and locked termios may be retained.)
	 */
	 */


	if (!try_module_get(driver->owner)) {
	if (!try_module_get(driver->owner))
		retval = -ENODEV;
		return ERR_PTR(-ENODEV);
		goto end_init;
	}


	o_tty = NULL;
	o_tty = NULL;
	tp = o_tp = NULL;
	tp = o_tp = NULL;
@@ -1475,7 +1470,8 @@ int tty_init_dev(struct tty_driver *driver, int idx,
	tty_driver_kref_get(driver);
	tty_driver_kref_get(driver);
	tty->count++;
	tty->count++;


	if (tty_driver_install_tty(driver, tty) < 0)
	retval = tty_driver_install_tty(driver, tty);
	if (retval < 0)
		goto release_mem_out;
		goto release_mem_out;


	/*
	/*
@@ -1485,14 +1481,9 @@ int tty_init_dev(struct tty_driver *driver, int idx,
	 */
	 */


	retval = tty_ldisc_setup(tty, o_tty);
	retval = tty_ldisc_setup(tty, o_tty);

	if (retval)
	if (retval)
		goto release_mem_out;
		goto release_mem_out;

	return tty;
	*ret_tty = tty;
	/* All paths come through here to release the mutex */
end_init:
	return retval;


	/* Release locally allocated memory ... nothing placed in slots */
	/* Release locally allocated memory ... nothing placed in slots */
free_mem_out:
free_mem_out:
@@ -1507,8 +1498,7 @@ int tty_init_dev(struct tty_driver *driver, int idx,


fail_no_mem:
fail_no_mem:
	module_put(driver->owner);
	module_put(driver->owner);
	retval = -ENOMEM;
	return ERR_PTR(-ENOMEM);
	goto end_init;


	/* call the tty release_tty routine to clean out this slot */
	/* call the tty release_tty routine to clean out this slot */
release_mem_out:
release_mem_out:
@@ -1516,7 +1506,7 @@ int tty_init_dev(struct tty_driver *driver, int idx,
		printk(KERN_INFO "tty_init_dev: ldisc open failed, "
		printk(KERN_INFO "tty_init_dev: ldisc open failed, "
				 "clearing slot %d\n", idx);
				 "clearing slot %d\n", idx);
	release_tty(tty, idx);
	release_tty(tty, idx);
	goto end_init;
	return ERR_PTR(retval);
}
}


void tty_free_termios(struct tty_struct *tty)
void tty_free_termios(struct tty_struct *tty)
@@ -1925,11 +1915,11 @@ static int __tty_open(struct inode *inode, struct file *filp)
		return -ENODEV;
		return -ENODEV;
	}
	}
got_driver:
got_driver:
	retval = tty_init_dev(driver, index, &tty, 0);
	tty = tty_init_dev(driver, index, 0);
	mutex_unlock(&tty_mutex);
	mutex_unlock(&tty_mutex);
	tty_driver_kref_put(driver);
	tty_driver_kref_put(driver);
	if (retval)
	if (IS_ERR(tty))
		return retval;
		return PTR_ERR(tty);


	filp->private_data = tty;
	filp->private_data = tty;
	file_move(filp, &tty->tty_files);
	file_move(filp, &tty->tty_files);
+2 −2
Original line number Original line Diff line number Diff line
@@ -401,8 +401,8 @@ extern dev_t tty_devnum(struct tty_struct *tty);
extern void proc_clear_tty(struct task_struct *p);
extern void proc_clear_tty(struct task_struct *p);
extern struct tty_struct *get_current_tty(void);
extern struct tty_struct *get_current_tty(void);
extern void tty_default_fops(struct file_operations *fops);
extern void tty_default_fops(struct file_operations *fops);
extern int tty_init_dev(struct tty_driver *driver, int idx,
extern struct tty_struct *tty_init_dev(struct tty_driver *driver, int idx,
			struct tty_struct **ret_tty, int first_ok);
								int first_ok);
extern void tty_release_dev(struct file *filp);
extern void tty_release_dev(struct file *filp);


extern struct mutex tty_mutex;
extern struct mutex tty_mutex;