Sun Sep 9 20:23:38 2012 UTC ()
In uhub_childdet, do not free the array of sub-devices if there is none.
This prevents a kernel panic at shutdown on my laptop.


(gsutre)
diff -r1.117 -r1.118 src/sys/dev/usb/uhub.c

cvs diff -r1.117 -r1.118 src/sys/dev/usb/uhub.c (expand / switch to unified diff)

--- src/sys/dev/usb/uhub.c 2012/03/12 02:44:17 1.117
+++ src/sys/dev/usb/uhub.c 2012/09/09 20:23:38 1.118
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: uhub.c,v 1.117 2012/03/12 02:44:17 mrg Exp $ */ 1/* $NetBSD: uhub.c,v 1.118 2012/09/09 20:23:38 gsutre Exp $ */
2/* $FreeBSD: src/sys/dev/usb/uhub.c,v 1.18 1999/11/17 22:33:43 n_hibma Exp $ */ 2/* $FreeBSD: src/sys/dev/usb/uhub.c,v 1.18 1999/11/17 22:33:43 n_hibma Exp $ */
3 3
4/* 4/*
5 * Copyright (c) 1998, 2004 The NetBSD Foundation, Inc. 5 * Copyright (c) 1998, 2004 The NetBSD Foundation, Inc.
6 * All rights reserved. 6 * All rights reserved.
7 * 7 *
8 * This code is derived from software contributed to The NetBSD Foundation 8 * This code is derived from software contributed to The NetBSD Foundation
9 * by Lennart Augustsson (lennart@augustsson.net) at 9 * by Lennart Augustsson (lennart@augustsson.net) at
10 * Carlstedt Research & Technology. 10 * Carlstedt Research & Technology.
11 * 11 *
12 * Redistribution and use in source and binary forms, with or without 12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions 13 * modification, are permitted provided that the following conditions
14 * are met: 14 * are met:
@@ -26,27 +26,27 @@ @@ -26,27 +26,27 @@
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 * POSSIBILITY OF SUCH DAMAGE. 31 * POSSIBILITY OF SUCH DAMAGE.
32 */ 32 */
33 33
34/* 34/*
35 * USB spec: http://www.usb.org/developers/docs/usbspec.zip 35 * USB spec: http://www.usb.org/developers/docs/usbspec.zip
36 */ 36 */
37 37
38#include <sys/cdefs.h> 38#include <sys/cdefs.h>
39__KERNEL_RCSID(0, "$NetBSD: uhub.c,v 1.117 2012/03/12 02:44:17 mrg Exp $"); 39__KERNEL_RCSID(0, "$NetBSD: uhub.c,v 1.118 2012/09/09 20:23:38 gsutre Exp $");
40 40
41#include "opt_usb.h" 41#include "opt_usb.h"
42 42
43#include <sys/param.h> 43#include <sys/param.h>
44#include <sys/systm.h> 44#include <sys/systm.h>
45#include <sys/kernel.h> 45#include <sys/kernel.h>
46#include <sys/malloc.h> 46#include <sys/malloc.h>
47#include <sys/device.h> 47#include <sys/device.h>
48#include <sys/proc.h> 48#include <sys/proc.h>
49 49
50#include <sys/bus.h> 50#include <sys/bus.h>
51 51
52#include <dev/usb/usb.h> 52#include <dev/usb/usb.h>
@@ -661,27 +661,27 @@ uhub_childdet(device_t self, device_t ch @@ -661,27 +661,27 @@ uhub_childdet(device_t self, device_t ch
661 usbd_device_handle devhub = sc->sc_hub; 661 usbd_device_handle devhub = sc->sc_hub;
662 usbd_device_handle dev; 662 usbd_device_handle dev;
663 int nports; 663 int nports;
664 int port; 664 int port;
665 int i; 665 int i;
666 666
667 if (!devhub->hub) 667 if (!devhub->hub)
668 /* should never happen; children are only created after init */ 668 /* should never happen; children are only created after init */
669 panic("hub not fully initialised, but child deleted?"); 669 panic("hub not fully initialised, but child deleted?");
670 670
671 nports = devhub->hub->hubdesc.bNbrPorts; 671 nports = devhub->hub->hubdesc.bNbrPorts;
672 for (port = 0; port < nports; port++) { 672 for (port = 0; port < nports; port++) {
673 dev = devhub->hub->ports[port].device; 673 dev = devhub->hub->ports[port].device;
674 if (!dev) 674 if (!dev || dev->subdevlen == 0)
675 continue; 675 continue;
676 for (i = 0; i < dev->subdevlen; i++) { 676 for (i = 0; i < dev->subdevlen; i++) {
677 if (dev->subdevs[i] == child) { 677 if (dev->subdevs[i] == child) {
678 dev->subdevs[i] = NULL; 678 dev->subdevs[i] = NULL;
679 dev->nifaces_claimed--; 679 dev->nifaces_claimed--;
680 } 680 }
681 } 681 }
682 if (dev->nifaces_claimed == 0) { 682 if (dev->nifaces_claimed == 0) {
683 free(dev->subdevs, M_USB); 683 free(dev->subdevs, M_USB);
684 dev->subdevs = NULL; 684 dev->subdevs = NULL;
685 dev->subdevlen = 0; 685 dev->subdevlen = 0;
686 } 686 }
687 } 687 }