From a5910414d4f76ddcfcb2a5a4aee93eb18d19da00 Mon Sep 17 00:00:00 2001 From: Ian Lepore Date: Wed, 8 Jan 2020 22:48:14 +0000 Subject: [PATCH] Change some KASSERT to device_printf + return EINVAL. There's no need to bring the whole kernel down due to a configuration error detected when a module is loaded, it suffices to just not attach the device. --- sys/dev/iicbus/mux/iicmux.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/sys/dev/iicbus/mux/iicmux.c b/sys/dev/iicbus/mux/iicmux.c index d53e8350837..f71fc7f8cb5 100644 --- a/sys/dev/iicbus/mux/iicmux.c +++ b/sys/dev/iicbus/mux/iicmux.c @@ -222,10 +222,16 @@ iicmux_add_child(device_t dev, device_t child, int busidx) { struct iicmux_softc *sc = device_get_softc(dev); - KASSERT(busidx < sc->numbuses, - ("iicmux_add_child: bus idx %d too big", busidx)); - KASSERT(sc->childdevs[busidx] == NULL, - ("iicmux_add_child: bus idx %d already added", busidx)); + if (busidx >= sc->numbuses) { + device_printf(dev, + "iicmux_add_child: bus idx %d too big", busidx); + return (EINVAL); + } + if (sc->childdevs[busidx] != NULL) { + device_printf(dev, "iicmux_add_child: bus idx %d already added", + busidx); + return (EINVAL); + } sc->childdevs[busidx] = child; if (sc->maxbus < busidx) @@ -240,12 +246,11 @@ iicmux_attach(device_t dev, device_t busdev, int numbuses) struct iicmux_softc *sc = device_get_softc(dev); int i, numadded; - /* - * Init the softc... - */ - KASSERT(numbuses <= IICMUX_MAX_BUSES, - ("iicmux_attach: numbuses %d exceeds max %d\n", - numbuses, IICMUX_MAX_BUSES)); + if (numbuses >= IICMUX_MAX_BUSES) { + device_printf(dev, "iicmux_attach: numbuses %d > max %d\n", + numbuses, IICMUX_MAX_BUSES); + return (EINVAL); + } sc->dev = dev; sc->busdev = busdev; -- 2.45.0