From ddc4b9731eabf3b8744985ea4539aeb62cb6c70c Mon Sep 17 00:00:00 2001 From: jsg Date: Fri, 29 Jul 2016 04:41:53 +0000 Subject: [PATCH] Reorder code to avoid a divide by zero when there are no sensors. Tested by and ok mglocker@ --- sys/arch/macppc/dev/thermal.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/sys/arch/macppc/dev/thermal.c b/sys/arch/macppc/dev/thermal.c index a7d7dbd80c0..270b79444ba 100644 --- a/sys/arch/macppc/dev/thermal.c +++ b/sys/arch/macppc/dev/thermal.c @@ -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. -- 2.20.1