PERFORCE change 36743 for review
    Marcel Moolenaar 
    marcel at FreeBSD.org
       
    Sat Aug 23 02:26:01 PDT 2003
    
    
  
http://perforce.freebsd.org/chv.cgi?CH=36743
Change 36743 by marcel at 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);
 }
 
    
    
More information about the p4-projects
mailing list