Reorder code to avoid a divide by zero when there are no sensors.
authorjsg <jsg@openbsd.org>
Fri, 29 Jul 2016 04:41:53 +0000 (04:41 +0000)
committerjsg <jsg@openbsd.org>
Fri, 29 Jul 2016 04:41:53 +0000 (04:41 +0000)
Tested by and ok mglocker@

sys/arch/macppc/dev/thermal.c

index a7d7dbd..270b794 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: thermal.c,v 1.4 2016/05/23 11:28:57 mglocker Exp $ */
+/*     $OpenBSD: thermal.c,v 1.5 2016/07/29 04:41:53 jsg Exp $ */
 
 /*-
  * Copyright (c) 2009-2011 Nathan Whitehorn
@@ -157,17 +157,19 @@ thermal_manage_fans(void)
                        average_excess += frac_excess;
                        nsens++;
                }
-               average_excess /= nsens;
 
-               /* If there are no sensors in this zone, use the average */
-               if (nsens_zone == 0)
-                       max_excess_zone = average_excess;
                /* No sensors at all? Use default */
                if (nsens == 0) {
                        fan->fan->set(fan->fan, fan->fan->default_rpm);
                        continue;
                }
 
+               average_excess /= nsens;
+
+               /* If there are no sensors in this zone, use the average */
+               if (nsens_zone == 0)
+                       max_excess_zone = average_excess;
+
                /*
                 * Scale the fan linearly in the max temperature in its
                 * thermal zone.