Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 17 Nov 2016 16:06:53 +0000 (UTC)
From:      Ruslan Bukin <br@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r308768 - head/sys/dev/uart
Message-ID:  <201611171606.uAHG6rvg093027@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: br
Date: Thu Nov 17 16:06:53 2016
New Revision: 308768
URL: https://svnweb.freebsd.org/changeset/base/308768

Log:
  Do not reallocate driver softc for uart unnecessarily.
  
  Do not assume that all uart drivers use uart_softc structure as is.
  Some do a sensible thing and do declare their uart class and driver
  properly and arrive into uart_bus_attach with suitably sized softc.
  
  Submitted by:	kan
  Sponsored by:	DARPA, AFRL

Modified:
  head/sys/dev/uart/uart_core.c

Modified: head/sys/dev/uart/uart_core.c
==============================================================================
--- head/sys/dev/uart/uart_core.c	Thu Nov 17 15:37:44 2016	(r308767)
+++ head/sys/dev/uart/uart_core.c	Thu Nov 17 16:06:53 2016	(r308768)
@@ -573,7 +573,7 @@ uart_bus_attach(device_t dev)
 	 * the device.
 	 */
 	sc0 = device_get_softc(dev);
-	if (sc0->sc_class->size > sizeof(*sc)) {
+	if (sc0->sc_class->size > device_get_driver(dev)->size) {
 		sc = malloc(sc0->sc_class->size, M_UART, M_WAITOK|M_ZERO);
 		bcopy(sc0, sc, sizeof(*sc));
 		device_set_softc(dev, sc);
@@ -781,11 +781,10 @@ uart_bus_detach(device_t dev)
 
 	mtx_destroy(&sc->sc_hwmtx_s);
 
-	if (sc->sc_class->size > sizeof(*sc)) {
+	if (sc->sc_class->size > device_get_driver(dev)->size) {
 		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?201611171606.uAHG6rvg093027>