Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 22 Nov 2008 15:35:21 +0000 (UTC)
From:      Alexander Motin <mav@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r185177 - head/sys/dev/sound/pci/hda
Message-ID:  <200811221535.mAMFZLcZ021568@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: mav
Date: Sat Nov 22 15:35:21 2008
New Revision: 185177
URL: http://svn.freebsd.org/changeset/base/185177

Log:
  Handle device_get_children() errors in more correct way.
  We shouldn't detach until all children are surely destroyed.
  
  Found with:     Coverity Prevent(tm)
  CID:            2137

Modified:
  head/sys/dev/sound/pci/hda/hdac.c

Modified: head/sys/dev/sound/pci/hda/hdac.c
==============================================================================
--- head/sys/dev/sound/pci/hda/hdac.c	Sat Nov 22 14:48:40 2008	(r185176)
+++ head/sys/dev/sound/pci/hda/hdac.c	Sat Nov 22 15:35:21 2008	(r185177)
@@ -7571,17 +7571,20 @@ static int
 hdac_detach(device_t dev)
 {
 	struct hdac_softc *sc;
-	device_t *devlist = NULL;
-	int i, devcount;
+	device_t *devlist;
+	int i, devcount, error;
 
-	sc = device_get_softc(dev);
-
-	device_get_children(dev, &devlist, &devcount);
-	for (i = 0; devlist != NULL && i < devcount; i++)
-		device_delete_child(dev, devlist[i]);
-	if (devlist != NULL)
-		free(devlist, M_TEMP);
+	if ((error = device_get_children(dev, &devlist, &devcount)) != 0)
+		return (error);
+	for (i = 0; i < devcount; i++) {
+		if ((error = device_delete_child(dev, devlist[i])) != 0) {
+			free(devlist, M_TEMP);                                                            
+	                return (error);                                                                   
+	        }                                                                                         
+	}
+	free(devlist, M_TEMP);
 
+	sc = device_get_softc(dev);
 	hdac_release_resources(sc);
 
 	return (0);



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