From dan@obluda.cz  Wed Jul  3 11:20:48 2002
Return-Path: <dan@obluda.cz>
Received: from mx1.FreeBSD.org (mx1.FreeBSD.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id 9D05237B400
	for <FreeBSD-gnats-submit@freebsd.org>; Wed,  3 Jul 2002 11:20:48 -0700 (PDT)
Received: from xkulesh.vol.cz (xkulesh.vol.cz [195.250.154.106])
	by mx1.FreeBSD.org (Postfix) with ESMTP id C9E6D43E09
	for <FreeBSD-gnats-submit@freebsd.org>; Wed,  3 Jul 2002 11:20:45 -0700 (PDT)
	(envelope-from dan@obluda.cz)
Received: from xkulesh.vol.cz (localhost [127.0.0.1])
	by xkulesh.vol.cz (8.12.5/8.12.5) with ESMTP id g63IKSP3000343
	for <FreeBSD-gnats-submit@freebsd.org>; Wed, 3 Jul 2002 20:20:28 +0200 (CEST)
	(envelope-from dan@obluda.cz)
Received: (from root@localhost)
	by xkulesh.vol.cz (8.12.5/8.12.2/Submit) id g638FQKX000383;
	Wed, 3 Jul 2002 10:15:26 +0200 (CEST)
Message-Id: <200207030815.g638FQKX000383@xkulesh.vol.cz>
Date: Wed, 3 Jul 2002 10:15:26 +0200 (CEST)
From: Dan Lukes <dan@obluda.cz>
Reply-To: Dan Lukes <dan@obluda.cz>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: early locking in pcm/sound's pcm_chn_add()
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         40157
>Category:       kern
>Synopsis:       [PATCH] early locking in pcm/sound's pcm_chn_add()
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    sound
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Wed Jul 03 11:30:02 PDT 2002
>Closed-Date:    Sun Jul 21 19:39:39 PDT 2002
>Last-Modified:  Sun Jul 21 19:39:39 PDT 2002
>Originator:     Dan Lukes
>Release:        FreeBSD 5.0-CURRENT i386
>Organization:
>Environment:
src/sys/dev/sound/pcm/sound.c,v 1.73 2002/05/19

>Description:
	In the code of pcm_chn_add() we obtain a lock and call
sce = malloc(sizeof(*sce), M_DEVBUF, M_WAITOK | M_ZERO)

	there is no reason to protect initialising of sce nor calling malloc 
by lock on d; malloc is allowed to sleep

	we should avoid sleeping with locked things unless necesarry

>How-To-Repeat:
	N/A
>Fix:
--- sys/dev/sound/pcm/sound.c.ORIG	Sun May 19 08:31:56 2002
+++ sys/dev/sound/pcm/sound.c	Wed Jul  3 09:41:36 2002
@@ -428,13 +428,12 @@
     	struct snddev_channel *sce, *tmp, *after;
     	int unit = device_get_unit(d->dev);
 
-	snd_mtxlock(d->lock);
-
 	sce = malloc(sizeof(*sce), M_DEVBUF, M_WAITOK | M_ZERO);
 	if (!sce) {
-		snd_mtxunlock(d->lock);
 		return ENOMEM;
 	}
+
+	snd_mtxlock(d->lock);
 
 	sce->channel = ch;
 	if (SLIST_EMPTY(&d->channels)) {



>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->sound 
Responsible-Changed-By: dwmalone 
Responsible-Changed-When: Wed Jul 17 10:03:09 PDT 2002 
Responsible-Changed-Why:  


http://www.freebsd.org/cgi/query-pr.cgi?pr=40157 
State-Changed-From-To: open->closed 
State-Changed-By: orion 
State-Changed-When: Sun Jul 21 19:38:54 PDT 2002 
State-Changed-Why:  
Patch applied.  Thanks for pointing this out. 


http://www.freebsd.org/cgi/query-pr.cgi?pr=40157 
>Unformatted:
