Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 3 Jul 2002 10:15:26 +0200 (CEST)
From:      Dan Lukes <dan@obluda.cz>
To:        FreeBSD-gnats-submit@FreeBSD.org
Subject:   kern/40157: early locking in pcm/sound's pcm_chn_add()
Message-ID:  <200207030815.g638FQKX000383@xkulesh.vol.cz>

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

>Number:         40157
>Category:       kern
>Synopsis:       [PATCH] early locking in pcm/sound's pcm_chn_add()
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Wed Jul 03 11:30:02 PDT 2002
>Closed-Date:
>Last-Modified:
>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:
>Unformatted:

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message




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