From owner-p4-projects@FreeBSD.ORG Sun Aug 3 18:05:29 2008 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 69AAE106566B; Sun, 3 Aug 2008 18:05:29 +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 2C7A01065676; Sun, 3 Aug 2008 18:05:29 +0000 (UTC) (envelope-from rwatson@FreeBSD.org) Received: from cyrus.watson.org (cyrus.watson.org [209.31.154.42]) by mx1.freebsd.org (Postfix) with ESMTP id BEF338FC1C; Sun, 3 Aug 2008 18:05:28 +0000 (UTC) (envelope-from rwatson@FreeBSD.org) Received: from fledge.watson.org (fledge.watson.org [209.31.154.41]) by cyrus.watson.org (Postfix) with ESMTP id 157CA46B46; Sun, 3 Aug 2008 13:46:38 -0400 (EDT) Date: Sun, 3 Aug 2008 18:46:38 +0100 (BST) From: Robert Watson X-X-Sender: robert@fledge.watson.org To: Ed Schouten In-Reply-To: <200808031737.m73HbJO8065922@repoman.freebsd.org> Message-ID: References: <200808031737.m73HbJO8065922@repoman.freebsd.org> User-Agent: Alpine 1.10 (BSF 962 2008-03-14) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed Cc: Perforce Change Reviews Subject: Re: PERFORCE change 146544 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: Sun, 03 Aug 2008 18:05:29 -0000 On Sun, 3 Aug 2008, Ed Schouten wrote: > http://perforce.freebsd.org/chv.cgi?CH=146544 > > Change 146544 by ed@ed_flippo on 2008/08/03 17:36:53 > > Add a counter to store the number of null modem devices. I've seen similar constructs in lots of drivers, and it's basically an unsafe construct because the deregister is non-atomic with respect to the busy check. I wonder if, instead, we should use a mutex to protect the count, and set it to some value to deny future allocations, such as -1, once the ebusy check is past... Even that is unideal, though. Robert N M Watson Computer Laboratory University of Cambridge > > Affected files ... > > .. //depot/projects/mpsafetty/sys/dev/nmdm/nmdm.c#4 edit > > Differences ... > > ==== //depot/projects/mpsafetty/sys/dev/nmdm/nmdm.c#4 (text+ko) ==== > > @@ -93,12 +93,16 @@ > struct mtx ns_mtx; > }; > > +static int nmdm_count = 0; > + > static struct nmdmsoftc * > nmdm_alloc(unsigned long unit, struct ucred *cr) > { > struct nmdmsoftc *ns; > struct tty *tp; > > + atomic_add_acq_int(&nmdm_count, 1); > + > ns = malloc(sizeof(*ns), M_NMDM, M_WAITOK|M_ZERO); > mtx_init(&ns->ns_mtx, "nmdm", NULL, MTX_DEF); > > @@ -344,8 +348,9 @@ > break; > > case MOD_UNLOAD: > + if (nmdm_count != 0) > + return (EBUSY); > EVENTHANDLER_DEREGISTER(dev_clone, tag); > - /* XXX: track counter! */ > break; > > default: >