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
This commit is contained in:
Ruslan Bukin 2016-11-17 16:06:53 +00:00
parent 8e621af540
commit 5515b0cb39

View File

@ -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);
}