From owner-p4-projects@FreeBSD.ORG Mon Sep 15 20:46:17 2008 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id D72741065671; Mon, 15 Sep 2008 20:46:16 +0000 (UTC) Delivered-To: perforce@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 9B54E106566B for ; Mon, 15 Sep 2008 20:46:16 +0000 (UTC) (envelope-from thompsa@freebsd.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id 8701F8FC14 for ; Mon, 15 Sep 2008 20:46:16 +0000 (UTC) (envelope-from thompsa@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.3/8.14.3) with ESMTP id m8FKkGJw038160 for ; Mon, 15 Sep 2008 20:46:16 GMT (envelope-from thompsa@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.3/8.14.3/Submit) id m8FKkGsC038151 for perforce@freebsd.org; Mon, 15 Sep 2008 20:46:16 GMT (envelope-from thompsa@freebsd.org) Date: Mon, 15 Sep 2008 20:46:16 GMT Message-Id: <200809152046.m8FKkGsC038151@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to thompsa@freebsd.org using -f From: Andrew Thompson To: Perforce Change Reviews Cc: Subject: PERFORCE change 149824 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 15 Sep 2008 20:46:17 -0000 http://perforce.freebsd.org/chv.cgi?CH=149824 Change 149824 by thompsa@thompsa_burger on 2008/09/15 20:46:13 Wait for the tty to be torn down before freeing the mtx and softc. Suggested by: hps Affected files ... .. //depot/projects/usb/src/sys/dev/usb2/serial/usb2_serial.c#14 edit Differences ... ==== //depot/projects/usb/src/sys/dev/usb2/serial/usb2_serial.c#14 (text+ko) ==== @@ -87,6 +87,7 @@ #include #include #include +#include #include @@ -337,6 +338,7 @@ sc->sc_tty = tp; DPRINTF("ttycreate: %s\n", buf); + usb2_cv_init(&sc->sc_cv, "usb2_com"); done: return (error); @@ -364,6 +366,9 @@ tty_rel_gone(tp); mtx_lock(sc->sc_parent_mtx); + /* Wait for the callback after the TTY is torn down */ + while (sc->sc_ttyfreed == 0) + usb2_cv_wait(&sc->sc_cv, sc->sc_parent_mtx); /* * make sure that read and write transfers are stopped */ @@ -375,6 +380,7 @@ } mtx_unlock(sc->sc_parent_mtx); } + usb2_cv_destroy(&sc->sc_cv); return; } @@ -815,6 +821,8 @@ sc = cc->cc_softc; tp = sc->sc_tty; + mtx_assert(sc->sc_parent_mtx, MA_OWNED); + if (!(sc->sc_flag & UCOM_FLAG_LL_READY)) { return; } @@ -1093,13 +1101,12 @@ } static void -usb2_com_free(void *sc) +usb2_com_free(void *xsc) { - /* - * Our softc gets deallocated earlier on. - * - * XXX: we should make sure the TTY device name doesn't get - * recycled before we end up here! - */ - return; + struct usb2_com_softc *sc = xsc; + + mtx_lock(sc->sc_parent_mtx); + sc->sc_ttyfreed = 1; + usb2_cv_signal(&sc->sc_cv); + mtx_unlock(sc->sc_parent_mtx); }