Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 3 Aug 2008 18:46:38 +0100 (BST)
From:      Robert Watson <rwatson@FreeBSD.org>
To:        Ed Schouten <ed@FreeBSD.org>
Cc:        Perforce Change Reviews <perforce@FreeBSD.org>
Subject:   Re: PERFORCE change 146544 for review
Message-ID:  <alpine.BSF.1.10.0808031845230.18760@fledge.watson.org>
In-Reply-To: <200808031737.m73HbJO8065922@repoman.freebsd.org>
References:  <200808031737.m73HbJO8065922@repoman.freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help

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:
>



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?alpine.BSF.1.10.0808031845230.18760>