diff options
author | Ruslan Bukin <br@FreeBSD.org> | 2016-11-17 16:06:53 +0000 |
---|---|---|
committer | Ruslan Bukin <br@FreeBSD.org> | 2016-11-17 16:06:53 +0000 |
commit | 5515b0cb39fae7d2951b779b64a7e56823ac44c2 (patch) | |
tree | 29be2e079fa7d1498c768af8d6c0ff7e518e7f5b /sys/dev/uart/uart_core.c | |
parent | 8e621af540634969322307bbfac640d07e0b5b17 (diff) | |
download | src-5515b0cb39fae7d2951b779b64a7e56823ac44c2.tar.gz src-5515b0cb39fae7d2951b779b64a7e56823ac44c2.zip |
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
Notes
Notes:
svn path=/head/; revision=308768
Diffstat (limited to 'sys/dev/uart/uart_core.c')
-rw-r--r-- | sys/dev/uart/uart_core.c | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/sys/dev/uart/uart_core.c b/sys/dev/uart/uart_core.c index f4dbcfc2dcc7..6c9d7aa23a06 100644 --- a/sys/dev/uart/uart_core.c +++ b/sys/dev/uart/uart_core.c @@ -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); } |