mirror of
https://github.com/opnsense/src.git
synced 2026-06-08 16:22:46 -04:00
Fix a race when detaching the cbb worker thread. There were a couple
of cases where we didn't take out the lock before setting or clearing a bit. This apparently can lead to a race at kldunload time (at least on my Turion64 laptop, never saw it on my Sony Vaio).
This commit is contained in:
parent
03d9e830c1
commit
1b2ec08c94
1 changed files with 7 additions and 1 deletions
|
|
@ -330,7 +330,8 @@ cbb_detach(device_t brdev)
|
|||
mtx_lock(&sc->mtx);
|
||||
bus_teardown_intr(brdev, sc->irq_res, sc->intrhand);
|
||||
sc->flags |= CBB_KTHREAD_DONE;
|
||||
if (sc->flags & CBB_KTHREAD_RUNNING) {
|
||||
while (sc->flags & CBB_KTHREAD_RUNNING) {
|
||||
DEVPRINTF((sc->dev, "Waiting for thread to die\n"));
|
||||
cv_broadcast(&sc->cv);
|
||||
msleep(sc->event_thread, &sc->mtx, PWAIT, "cbbun", 0);
|
||||
}
|
||||
|
|
@ -481,7 +482,9 @@ cbb_event_thread(void *arg)
|
|||
int err;
|
||||
int not_a_card = 0;
|
||||
|
||||
mtx_lock(&sc->mtx);
|
||||
sc->flags |= CBB_KTHREAD_RUNNING;
|
||||
mtx_unlock(&sc->mtx);
|
||||
while ((sc->flags & CBB_KTHREAD_DONE) == 0) {
|
||||
/*
|
||||
* We take out Giant here because we need it deep,
|
||||
|
|
@ -538,7 +541,10 @@ cbb_event_thread(void *arg)
|
|||
err = cv_timedwait(&sc->cv, &sc->mtx, 1 * hz);
|
||||
mtx_unlock(&sc->mtx);
|
||||
}
|
||||
DEVPRINTF((sc->dev, "Thread terminating\n"));
|
||||
mtx_lock(&sc->mtx);
|
||||
sc->flags &= ~CBB_KTHREAD_RUNNING;
|
||||
mtx_unlock(&sc->mtx);
|
||||
kthread_exit(0);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue