Index: sys/kern/subr_autoconf.c =================================================================== RCS file: /cvsroot/src/sys/kern/subr_autoconf.c,v retrieving revision 1.247 diff -p -u -r1.247 subr_autoconf.c --- sys/kern/subr_autoconf.c 19 Jul 2016 07:44:03 -0000 1.247 +++ sys/kern/subr_autoconf.c 20 Mar 2017 00:15:54 -0000 @@ -2781,17 +2855,15 @@ deviter_init(deviter_t *di, deviter_flag memset(di, 0, sizeof(*di)); - mutex_enter(&alldevs_mtx); if ((flags & DEVITER_F_SHUTDOWN) != 0) flags |= DEVITER_F_RW; + mutex_enter(&alldevs_mtx); if ((flags & DEVITER_F_RW) != 0) alldevs_nwrite++; else alldevs_nread++; di->di_gen = alldevs_gen++; - mutex_exit(&alldevs_mtx); - di->di_flags = flags; switch (di->di_flags & (DEVITER_F_LEAVES_FIRST|DEVITER_F_ROOT_FIRST)) { @@ -2814,11 +2886,14 @@ deviter_init(deviter_t *di, deviter_flag } deviter_reinit(di); + mutex_exit(&alldevs_mtx); } static void deviter_reinit(deviter_t *di) { + + KASSERT(mutex_owned(&alldevs_mtx)); if ((di->di_flags & DEVITER_F_RW) != 0) di->di_prev = TAILQ_LAST(&alldevs, devicelist); else @@ -2828,6 +2903,7 @@ deviter_reinit(deviter_t *di) device_t deviter_first(deviter_t *di, deviter_flags_t flags) { + deviter_init(di, flags); return deviter_next(di); } @@ -2837,6 +2913,8 @@ deviter_next2(deviter_t *di) { device_t dv; + KASSERT(mutex_owned(&alldevs_mtx)); + dv = di->di_prev; if (dv == NULL) @@ -2855,6 +2933,8 @@ deviter_next1(deviter_t *di) { device_t dv; + KASSERT(mutex_owned(&alldevs_mtx)); + do { dv = deviter_next2(di); } while (dv != NULL && !deviter_visits(di, dv)); @@ -2867,9 +2947,11 @@ deviter_next(deviter_t *di) { device_t dv = NULL; + mutex_enter(&alldevs_mtx); switch (di->di_flags & (DEVITER_F_LEAVES_FIRST|DEVITER_F_ROOT_FIRST)) { case 0: - return deviter_next1(di); + dv = deviter_next1(di); + break; case DEVITER_F_LEAVES_FIRST: while (di->di_curdepth >= 0) { if ((dv = deviter_next1(di)) == NULL) { @@ -2878,7 +2960,7 @@ deviter_next(deviter_t *di) } else if (dv->dv_depth == di->di_curdepth) break; } - return dv; + break; case DEVITER_F_ROOT_FIRST: while (di->di_curdepth <= di->di_maxdepth) { if ((dv = deviter_next1(di)) == NULL) { @@ -2887,10 +2969,13 @@ deviter_next(deviter_t *di) } else if (dv->dv_depth == di->di_curdepth) break; } - return dv; + break; default: - return NULL; + break; } + mutex_exit(&alldevs_mtx); + + return dv; } void