Date: Sat, 23 Aug 2003 00:18:39 -0700 (PDT) From: Marcel Moolenaar <marcel@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 36743 for review Message-ID: <200308230718.h7N7IdP9091604@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
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); }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200308230718.h7N7IdP9091604>