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:
Gleb Smirnoff 2013-12-20 19:45:51 +00:00
parent 8a46eac536
commit 7276319825
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=259663

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: