From nobody@FreeBSD.org  Tue Jan 25 14:47:55 2011
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id EA6B6106566B
	for <freebsd-gnats-submit@FreeBSD.org>; Tue, 25 Jan 2011 14:47:54 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from red.freebsd.org (red.freebsd.org [IPv6:2001:4f8:fff6::22])
	by mx1.freebsd.org (Postfix) with ESMTP id D98E08FC24
	for <freebsd-gnats-submit@FreeBSD.org>; Tue, 25 Jan 2011 14:47:54 +0000 (UTC)
Received: from red.freebsd.org (localhost [127.0.0.1])
	by red.freebsd.org (8.14.4/8.14.4) with ESMTP id p0PEls1o073902
	for <freebsd-gnats-submit@FreeBSD.org>; Tue, 25 Jan 2011 14:47:54 GMT
	(envelope-from nobody@red.freebsd.org)
Received: (from nobody@localhost)
	by red.freebsd.org (8.14.4/8.14.4/Submit) id p0PElsSf073901;
	Tue, 25 Jan 2011 14:47:54 GMT
	(envelope-from nobody)
Message-Id: <201101251447.p0PElsSf073901@red.freebsd.org>
Date: Tue, 25 Jan 2011 14:47:54 GMT
From: Sebastian Huber <sebastian.huber@embedded-brains.de>
To: freebsd-gnats-submit@FreeBSD.org
Subject: Avoid malloc(0) implementation dependency in device_get_children()
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         154287
>Category:       kern
>Synopsis:       [kernel] [patch] Avoid malloc(0) implementation dependency in device_get_children()
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Tue Jan 25 14:50:07 UTC 2011
>Closed-Date:    Sun Jan 29 01:26:10 UTC 2012
>Last-Modified:  Sun Jan 29 01:26:10 UTC 2012
>Originator:     Sebastian Huber
>Release:        9-current
>Organization:
embedded brains GmbH
>Environment:
>Description:
The device_get_children() implementation of the device(9) API depends on a particular malloc(0) behavior.  This makes it less portable to other operating systems.  The following patch avoids a malloc(0).
>How-To-Repeat:

>Fix:
Index: kern/subr_bus.c
===================================================================
--- kern/subr_bus.c     (revision 216297)
+++ kern/subr_bus.c     (working copy)
@@ -2090,14 +2090,19 @@
                count++;
        }
 
-       list = malloc(count * sizeof(device_t), M_TEMP, M_NOWAIT|M_ZERO);
-       if (!list)
-               return (ENOMEM);
+       if (count) {
+               list = malloc(count * sizeof(device_t), M_TEMP,
+                   M_NOWAIT|M_ZERO);
+               if (!list)
+                       return (ENOMEM);
 
-       count = 0;
-       TAILQ_FOREACH(child, &dev->children, link) {
-               list[count] = child;
-               count++;
+               count = 0;
+               TAILQ_FOREACH(child, &dev->children, link) {
+                       list[count] = child;
+                       count++;
+               }
+       } else {
+               list = NULL;
        }
 
        *devlistp = list;

>Release-Note:
>Audit-Trail:

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/154287: commit references a PR
Date: Sun,  9 Oct 2011 21:21:47 +0000 (UTC)

 Author: marius
 Date: Sun Oct  9 21:21:37 2011
 New Revision: 226175
 URL: http://svn.freebsd.org/changeset/base/226175
 
 Log:
   In device_get_children() avoid malloc(0) in order to increase portability
   to other operating systems.
   
   PR:     154287
 
 Modified:
   head/sys/kern/subr_bus.c
 
 Modified: head/sys/kern/subr_bus.c
 ==============================================================================
 --- head/sys/kern/subr_bus.c	Sun Oct  9 20:58:02 2011	(r226174)
 +++ head/sys/kern/subr_bus.c	Sun Oct  9 21:21:37 2011	(r226175)
 @@ -2140,6 +2140,11 @@ device_get_children(device_t dev, device
  	TAILQ_FOREACH(child, &dev->children, link) {
  		count++;
  	}
 +	if (count == 0) {
 +		*devlistp = NULL;
 +		*devcountp = 0;
 +		return (0);
 +	}
  
  	list = malloc(count * sizeof(device_t), M_TEMP, M_NOWAIT|M_ZERO);
  	if (!list)
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/154287: commit references a PR
Date: Sun, 29 Jan 2012 00:40:59 +0000 (UTC)

 Author: marius
 Date: Sun Jan 29 00:40:39 2012
 New Revision: 230695
 URL: http://svn.freebsd.org/changeset/base/230695
 
 Log:
   MFC: r226175
   
   In device_get_children() avoid malloc(0) in order to increase portability
   to other operating systems.
   
   PR:	154287
 
 Modified:
   stable/9/sys/kern/subr_bus.c
 Directory Properties:
   stable/9/sys/   (props changed)
   stable/9/sys/amd64/include/xen/   (props changed)
   stable/9/sys/boot/   (props changed)
   stable/9/sys/boot/i386/efi/   (props changed)
   stable/9/sys/boot/ia64/efi/   (props changed)
   stable/9/sys/boot/ia64/ski/   (props changed)
   stable/9/sys/boot/powerpc/boot1.chrp/   (props changed)
   stable/9/sys/boot/powerpc/ofw/   (props changed)
   stable/9/sys/cddl/contrib/opensolaris/   (props changed)
   stable/9/sys/conf/   (props changed)
   stable/9/sys/contrib/dev/acpica/   (props changed)
   stable/9/sys/contrib/octeon-sdk/   (props changed)
   stable/9/sys/contrib/pf/   (props changed)
   stable/9/sys/contrib/x86emu/   (props changed)
 
 Modified: stable/9/sys/kern/subr_bus.c
 ==============================================================================
 --- stable/9/sys/kern/subr_bus.c	Sun Jan 29 00:35:22 2012	(r230694)
 +++ stable/9/sys/kern/subr_bus.c	Sun Jan 29 00:40:39 2012	(r230695)
 @@ -2173,6 +2173,11 @@ device_get_children(device_t dev, device
  	TAILQ_FOREACH(child, &dev->children, link) {
  		count++;
  	}
 +	if (count == 0) {
 +		*devlistp = NULL;
 +		*devcountp = 0;
 +		return (0);
 +	}
  
  	list = malloc(count * sizeof(device_t), M_TEMP, M_NOWAIT|M_ZERO);
  	if (!list)
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/154287: commit references a PR
Date: Sun, 29 Jan 2012 00:41:18 +0000 (UTC)

 Author: marius
 Date: Sun Jan 29 00:41:08 2012
 New Revision: 230696
 URL: http://svn.freebsd.org/changeset/base/230696
 
 Log:
   MFC: r226175
   
   In device_get_children() avoid malloc(0) in order to increase portability
   to other operating systems.
   
   PR:	154287
 
 Modified:
   stable/8/sys/kern/subr_bus.c
 Directory Properties:
   stable/8/sys/   (props changed)
   stable/8/sys/amd64/include/xen/   (props changed)
   stable/8/sys/cddl/contrib/opensolaris/   (props changed)
   stable/8/sys/contrib/dev/acpica/   (props changed)
   stable/8/sys/contrib/pf/   (props changed)
 
 Modified: stable/8/sys/kern/subr_bus.c
 ==============================================================================
 --- stable/8/sys/kern/subr_bus.c	Sun Jan 29 00:40:39 2012	(r230695)
 +++ stable/8/sys/kern/subr_bus.c	Sun Jan 29 00:41:08 2012	(r230696)
 @@ -2176,6 +2176,11 @@ device_get_children(device_t dev, device
  	TAILQ_FOREACH(child, &dev->children, link) {
  		count++;
  	}
 +	if (count == 0) {
 +		*devlistp = NULL;
 +		*devcountp = 0;
 +		return (0);
 +	}
  
  	list = malloc(count * sizeof(device_t), M_TEMP, M_NOWAIT|M_ZERO);
  	if (!list)
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: open->closed 
State-Changed-By: marius 
State-Changed-When: Sun Jan 29 01:25:05 UTC 2012 
State-Changed-Why:  
close 

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