From owner-p4-projects@FreeBSD.ORG Sat Aug 23 02:26:00 2003 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 8F6DB16A4DD; Sat, 23 Aug 2003 02:25:59 -0700 (PDT) Delivered-To: perforce@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 2D0B316A4DF for ; Sat, 23 Aug 2003 02:25:59 -0700 (PDT) Received: from repoman.freebsd.org (repoman.freebsd.org [216.136.204.115]) by mx1.FreeBSD.org (Postfix) with ESMTP id DABC344294 for ; Sat, 23 Aug 2003 00:18:54 -0700 (PDT) (envelope-from marcel@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.12.6/8.12.6) with ESMTP id h7N7Is0U091608 for ; Sat, 23 Aug 2003 00:18:54 -0700 (PDT) (envelope-from marcel@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.12.6/8.12.6/Submit) id h7N7IdP9091604 for perforce@freebsd.org; Sat, 23 Aug 2003 00:18:39 -0700 (PDT) Date: Sat, 23 Aug 2003 00:18:39 -0700 (PDT) Message-Id: <200308230718.h7N7IdP9091604@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to marcel@freebsd.org using -f From: Marcel Moolenaar To: Perforce Change Reviews Subject: PERFORCE change 36743 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 23 Aug 2003 09:26:01 -0000 http://perforce.freebsd.org/chv.cgi?CH=36743 Change 36743 by marcel@marcel_nfs on 2003/08/23 00:17:44 Only allocate a new softc if the derived softc is larger than the generic (base) softc. Why do all the work if the end result is the same. While on the subject, set the softc to NULL on detach and make sure we free the softc if we allocated one. I expect that reattachment is preceeded by probing and that the bus layer will allocate a new softc (especially since there isn't one after detach now). Affected files ... .. //depot/projects/uart/dev/uart/uart_core.c#21 edit Differences ... ==== //depot/projects/uart/dev/uart/uart_core.c#21 (text+ko) ==== @@ -439,9 +439,12 @@ * the device. */ sc0 = device_get_softc(dev); - sc = malloc(sc0->sc_class->size, M_UART, M_WAITOK|M_ZERO); - bcopy(sc0, sc, sizeof(*sc)); - device_set_softc(dev, sc); + if (sc0->sc_class->size > sizeof(*sc)) { + sc = malloc(sc0->sc_class->size, M_UART, M_WAITOK|M_ZERO); + bcopy(sc0, sc, sizeof(*sc)); + device_set_softc(dev, sc); + } else + sc = sc0; /* * Protect ourselves against interrupts while we're not completely @@ -591,6 +594,12 @@ } bus_release_resource(dev, sc->sc_rtype, sc->sc_rrid, sc->sc_rres); + if (sc->sc_class->size > sizeof(*sc)) { + device_set_softc(dev, NULL); + free(sc, M_UART); + } else + device_set_softc(dev, NULL); + return (0); }