/* Locking: takes tty_ldisc_lock to guard against ldisc races  */
int tty_unregister_ldisc(int disc)
/* Locking: takes tty_ldisc_lock to guard against ldisc races  */
int tty_unregister_ldisc(int disc)
{
	unsigned long flags;
	int ret = 0;
	if (disc < N_TTY || disc >= NR_LDISCS)
		return -EINVAL;
	spin_lock_irqsave(&tty_ldisc_lock, flags);
	if (tty_ldiscs[disc]->refcount)
		ret = -EBUSY;
	else
		tty_ldiscs[disc] = NULL;
	spin_unlock_irqrestore(&tty_ldisc_lock, flags);
	return ret;
}