PERFORCE change 146544 for review

Robert Watson rwatson at FreeBSD.org
Sun Aug 3 18:05:29 UTC 2008


On Sun, 3 Aug 2008, Ed Schouten wrote:

> http://perforce.freebsd.org/chv.cgi?CH=146544
>
> Change 146544 by ed at 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:
>


More information about the p4-projects mailing list