Move list of ttys handling from the allocating procedures, to the

device creation stage. A device creation can fail, and in that case
an entry already on the list will be freed.

Sponsored by:	Nginx, Inc.
This commit is contained in:
glebius 2013-12-20 19:45:51 +00:00
parent 303df467d6
commit 63a068a718

View File

@ -1007,11 +1007,6 @@ tty_alloc_mutex(struct ttydevsw *tsw, void *sc, struct mtx *mutex)
knlist_init_mtx(&tp->t_inpoll.si_note, tp->t_mtx);
knlist_init_mtx(&tp->t_outpoll.si_note, tp->t_mtx);
sx_xlock(&tty_list_sx);
TAILQ_INSERT_TAIL(&tty_list, tp, t_list);
tty_list_count++;
sx_xunlock(&tty_list_sx);
return (tp);
}
@ -1020,11 +1015,6 @@ tty_dealloc(void *arg)
{
struct tty *tp = arg;
sx_xlock(&tty_list_sx);
TAILQ_REMOVE(&tty_list, tp, t_list);
tty_list_count--;
sx_xunlock(&tty_list_sx);
/* Make sure we haven't leaked buffers. */
MPASS(ttyinq_getsize(&tp->t_inq) == 0);
MPASS(ttyoutq_getsize(&tp->t_outq) == 0);
@ -1065,6 +1055,11 @@ tty_rel_free(struct tty *tp)
tp->t_dev = NULL;
tty_unlock(tp);
sx_xlock(&tty_list_sx);
TAILQ_REMOVE(&tty_list, tp, t_list);
tty_list_count--;
sx_xunlock(&tty_list_sx);
if (dev != NULL)
destroy_dev_sched_cb(dev, tty_dealloc, tp);
}
@ -1279,6 +1274,11 @@ tty_makedevf(struct tty *tp, struct ucred *cred, int flags,
}
}
sx_xlock(&tty_list_sx);
TAILQ_INSERT_TAIL(&tty_list, tp, t_list);
tty_list_count++;
sx_xunlock(&tty_list_sx);
return (0);
fail: