Hi!

Please consider attached patch:

    Avoid division by zero

    As wait_us is calculated by polling an I/O register, it is possible
    in certain environments (e.g. emulated hardware) that its value is
    zero. That is, that the I/O poll loop exits in less than 1 μs.

    The check avoids division by zero in such situation.

Thanks

--
Robert Millan
diff --git a/sys/dev/pci/auich.c b/sys/dev/pci/auich.c
index b2adad1..6a52800 100644
--- a/sys/dev/pci/auich.c
+++ b/sys/dev/pci/auich.c
@@ -1723,6 +1723,13 @@ auich_calibrate(struct auich_softc *sc)
 
 	rnd_add_data(NULL, &wait_us, sizeof(wait_us), 1);
 
+	/* avoid division by 0 below */
+	if (wait_us == 0) {
+		printf("%s: abnormal zero delay during calibration\n",
+					 device_xname(sc->sc_dev));
+		return;
+	}
+
 	actual_48k_rate = (bytes * UINT64_C(250000)) / wait_us;
 
 	if (actual_48k_rate < 50000)

Reply via email to