Since the dawn of umass(4) in OpenBSD, KASSERTs have been disabled in
the driver. These were ported from NetBSD, but never enabled. I think
it is a good idea to have them to spot potential coding mistakes.

While there, convert some KASSERTs to CTASSERTs that can be catched
during compile-time. This also avoids fixing format-string errors in
their messages.

Since these assertions have never been enabled before, please test that
patch extensively. I have not had any issues with it, but I was doing
some light testing only.
---
 sys/dev/usb/umass.c | 21 +++++++--------------
 1 file changed, 7 insertions(+), 14 deletions(-)

diff --git a/sys/dev/usb/umass.c b/sys/dev/usb/umass.c
index 0fc1782..e158e70 100644
--- a/sys/dev/usb/umass.c
+++ b/sys/dev/usb/umass.c
@@ -131,8 +131,6 @@
 #include <sys/buf.h>
 #include <sys/device.h>
 #include <sys/timeout.h>
-#undef KASSERT
-#define KASSERT(cond, msg)
 #include <machine/bus.h>
 
 #include <scsi/scsi_all.h>
@@ -146,6 +144,10 @@
 #include <dev/usb/umass_quirks.h>
 #include <dev/usb/umass_scsi.h>
 
+#ifdef DIAGNOSTIC
+#undef KASSERT
+#define KASSERT(cond, complaint) if (!(cond)) panic complaint
+#endif
 
 #ifdef UMASS_DEBUG
 int umassdebug = 0;
@@ -982,14 +984,8 @@ umass_bbb_transfer(struct umass_softc *sc, int lun, void 
*cmd, int cmdlen,
        KASSERT(datalen == 0 || dir != DIR_NONE,
                ("%s: direction is NONE while datalen is not zero\n",
                        sc->sc_dev.dv_xname));
-       KASSERT(sizeof(struct umass_bbb_cbw) == UMASS_BBB_CBW_SIZE,
-               ("%s: CBW struct does not have the right size (%d vs. %d)\n",
-                       sc->sc_dev.dv_xname,
-                       sizeof(struct umass_bbb_cbw), UMASS_BBB_CBW_SIZE));
-       KASSERT(sizeof(struct umass_bbb_csw) == UMASS_BBB_CSW_SIZE,
-               ("%s: CSW struct does not have the right size (%d vs. %d)\n",
-                       sc->sc_dev.dv_xname,
-                       sizeof(struct umass_bbb_csw), UMASS_BBB_CSW_SIZE));
+       CTASSERT(sizeof(struct umass_bbb_cbw) == UMASS_BBB_CBW_SIZE);
+       CTASSERT(sizeof(struct umass_bbb_csw) == UMASS_BBB_CSW_SIZE);
 
        /*
         * Determine the direction of the data transfer and the length.
@@ -1409,10 +1405,7 @@ umass_cbi_reset(struct umass_softc *sc, int status)
        DPRINTF(UDMASS_CBI, ("%s: CBI Reset\n",
                sc->sc_dev.dv_xname));
 
-       KASSERT(sizeof(sc->cbl) >= SEND_DIAGNOSTIC_CMDLEN,
-               ("%s: CBL struct is too small (%d < %d)\n",
-                       sc->sc_dev.dv_xname,
-                       sizeof(sc->cbl), SEND_DIAGNOSTIC_CMDLEN));
+       CTASSERT(sizeof(sc->cbl) >= SEND_DIAGNOSTIC_CMDLEN);
 
        sc->transfer_state = TSTATE_CBI_RESET1;
        sc->transfer_status = status;
-- 
2.1.4

Reply via email to