From 211c3d1b8162262bc685d158aa7aca08cacc1d0c Mon Sep 17 00:00:00 2001 From: Mark Kettenis Date: Wed, 25 Jan 2006 17:13:52 +0000 Subject: Prevent division by zero, and make it actually update the fan sensors. --- sys/dev/i2c/gl518sm.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/sys/dev/i2c/gl518sm.c b/sys/dev/i2c/gl518sm.c index f2c556a998b..0a70a8ec316 100644 --- a/sys/dev/i2c/gl518sm.c +++ b/sys/dev/i2c/gl518sm.c @@ -1,4 +1,4 @@ -/* $OpenBSD: gl518sm.c,v 1.1 2006/01/24 21:35:06 kettenis Exp $ */ +/* $OpenBSD: gl518sm.c,v 1.2 2006/01/25 17:13:51 kettenis Exp $ */ /* * Copyright (c) 2006 Mark Kettenis @@ -127,7 +127,7 @@ glenv_attach(struct device *parent, struct device *self, void *aux) return; } if (data & GL518SM_CONFIG_NOFAN2) - sc->sc_fan2_div = -1; + sc->sc_fan2_div = 0; /* Start monitoring and clear interrupt status. */ data = (data | GL518SM_CONFIG_START | GL518SM_CONFIG_CLEARST); @@ -210,12 +210,17 @@ glenv_refresh(void *arg) } else { sc->sc_sensor[GLENV_FAN1].flags &= ~SENSOR_FINVALID; tmp = data2[0] * sc->sc_fan1_div * 2; - sc->sc_sensor[GLENV_TEMP].value = 960000 / tmp; - if (sc->sc_fan2_div != -1) { - sc->sc_sensor[GLENV_FAN2].flags &= ~SENSOR_FINVALID; - tmp = data2[0] * sc->sc_fan2_div * 2; - sc->sc_sensor[GLENV_TEMP].value = 960000 / tmp; - } + if (tmp == 0) + sc->sc_sensor[GLENV_FAN1].flags |= SENSOR_FINVALID; + else + sc->sc_sensor[GLENV_FAN1].value = 960000 / tmp; + + sc->sc_sensor[GLENV_FAN2].flags &= ~SENSOR_FINVALID; + tmp = data2[1] * sc->sc_fan2_div * 2; + if (tmp == 0) + sc->sc_sensor[GLENV_FAN2].flags |= SENSOR_FINVALID; + else + sc->sc_sensor[GLENV_FAN2].value = 960000 / tmp; } iic_release_bus(sc->sc_tag, 0); -- cgit v1.2.3