From owner-freebsd-current@FreeBSD.ORG Thu Nov 27 06:24:57 2003 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 67DD516A4CE for ; Thu, 27 Nov 2003 06:24:57 -0800 (PST) Received: from python.evilrealms.net (evilrealms.demon.co.uk [62.49.12.231]) by mx1.FreeBSD.org (Postfix) with ESMTP id 29B5C43F93 for ; Thu, 27 Nov 2003 06:24:56 -0800 (PST) (envelope-from jay@evilrealms.net) Received: from evilrealms.net (viper.evilrealms.net [192.168.1.2]) by python.evilrealms.net (Postfix) with ESMTP id 694F25CA2; Thu, 27 Nov 2003 14:24:51 +0000 (GMT) Message-ID: <3FC60935.3050604@evilrealms.net> Date: Thu, 27 Nov 2003 14:24:53 +0000 From: Jay Cornwall User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.5) Gecko/20031013 Thunderbird/0.3 X-Accept-Language: en-us, en MIME-Version: 1.0 To: Martin References: <1069874342.704.18.camel@klotz.local> <3FC502B5.5020700@evilrealms.net> <1069888991.2521.7.camel@klotz.local> In-Reply-To: <1069888991.2521.7.camel@klotz.local> Content-Type: multipart/mixed; boundary="------------060501020802060405010502" cc: freebsd-current@freebsd.org Subject: Re: Panic with ugen X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 27 Nov 2003 14:24:57 -0000 This is a multi-part message in MIME format. --------------060501020802060405010502 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Martin wrote: > panic() > destroy_dev() > ugen_destroy_devnodes() > ugen_set_config() Could you try the attached patch, to see if it fixes the panic on the second run of your program? -- Cheers, Jay http://www.evilrealms.net/ - Systems Administrator & Developer http://www.imperial.ac.uk/ - 3rd year CS student --------------060501020802060405010502 Content-Type: text/plain; name="ugen-panic.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="ugen-panic.patch" Index: sys/dev/usb/ugen.c =================================================================== RCS file: /home/ncvs/src/sys/dev/usb/ugen.c,v retrieving revision 1.81 diff -u -3 -p -r1.81 ugen.c --- sys/dev/usb/ugen.c 9 Nov 2003 09:17:22 -0000 1.81 +++ sys/dev/usb/ugen.c 27 Nov 2003 14:06:25 -0000 @@ -1014,8 +1014,8 @@ ugen_set_interface(struct ugen_softc *sc usbd_interface_handle iface; usb_endpoint_descriptor_t *ed; usbd_status err; - struct ugen_endpoint *sce; - u_int8_t niface, nendpt, endptno, endpt; + struct ugen_endpoint *sce, **sce_cache; + u_int8_t niface, nendpt, nendpt_cache, endptno, endpt; int dir; DPRINTFN(15, ("ugen_set_interface %d %d\n", ifaceidx, altno)); @@ -1033,30 +1033,47 @@ ugen_set_interface(struct ugen_softc *sc if (err) return (err); -#if defined(__FreeBSD__) - /* destroy the existing devices, we remake the new ones in a moment */ - ugen_destroy_devnodes(sc); -#endif + /* store an array of endpoint descriptors to destroy if the interface + * change succeeds - these aren't available afterwards */ + sce_cache = malloc(sizeof(struct ugen_endpoint *) * nendpt, M_TEMP, + M_WAITOK); + nendpt_cache = nendpt; - /* XXX should only do this after setting new altno has succeeded */ for (endptno = 0; endptno < nendpt; endptno++) { ed = usbd_interface2endpoint_descriptor(iface,endptno); endpt = ed->bEndpointAddress; dir = UE_GET_DIR(endpt) == UE_DIR_IN ? IN : OUT; - sce = &sc->sc_endpoints[UE_GET_ADDR(endpt)][dir]; - sce->sc = 0; - sce->edesc = 0; - sce->iface = 0; + sce_cache[endptno] = &sc->sc_endpoints[UE_GET_ADDR(endpt)][dir]; } /* change setting */ err = usbd_set_interface(iface, altno); - if (err) + if (err) { + free(sce_cache, M_TEMP); return (err); + } err = usbd_endpoint_count(iface, &nendpt); - if (err) + if (err) { + free(sce_cache, M_TEMP); return (err); + } + +#if defined(__FreeBSD__) + /* destroy the existing devices, we remake the new ones in a moment */ + ugen_destroy_devnodes(sc); +#endif + + /* now we can clear the old interface's ugen_endpoints */ + for (endptno = 0; endptno < nendpt_cache; endptno++) { + sce = sce_cache[endptno]; + sce->sc = 0; + sce->edesc = 0; + sce->iface = 0; + } + free(sce_cache, M_TEMP); + + /* set the new interface's ugen_endpoints */ for (endptno = 0; endptno < nendpt; endptno++) { ed = usbd_interface2endpoint_descriptor(iface,endptno); endpt = ed->bEndpointAddress; --------------060501020802060405010502--