NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

kern/49927: [PATCH] Avoid division by zero in auich(4)



>Number:         49927
>Category:       kern
>Synopsis:       [PATCH] Avoid division by zero in auich(4)
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    kern-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sun May 24 14:15:00 +0000 2015
>Originator:     Robert Millan
>Release:        HEAD
>Organization:
>Environment:
RUMP environment (on top of GNU/Linux host)
>Description:
Please consider the following fix for auich(4):

    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.

>How-To-Repeat:

>Fix:
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)



Home | Main Index | Thread Index | Old Index