From: "Mark M. Hoffman" Date: Thu, 31 Jan 2008 13:32:09 +0000 Subject: Re: [lm-sensors] [PATCH] hwmon/dme1737: fix divide-by-0 Message-Id: <20080131133209.GF8290@jupiter.solarsys.private> List-Id: References: <191fb4ca0801240911m79bdc87p72b734df3427ee4b@mail.gmail.com> In-Reply-To: <191fb4ca0801240911m79bdc87p72b734df3427ee4b@mail.gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: lm-sensors@vger.kernel.org Hi Juerg, Jean: * Jean Delvare [2008-01-28 10:21:16 +0100]: > Hi Juerg, > > On Sun, 27 Jan 2008 16:39:46 -0800, Juerg Haefliger wrote: > > This patch fixes a possible divide-by-0 and a minor bug in the > > FAN_FROM_REG macro (in TPC mode). > > > > Signed-off-by: Juerg Haefliger > > > > Index: linux/drivers/hwmon/dme1737.c > > =================================> > --- linux.orig/drivers/hwmon/dme1737.c 2008-01-24 09:04:24.000000000 -0800 > > +++ linux/drivers/hwmon/dme1737.c 2008-01-27 16:33:47.000000000 -0800 > > @@ -279,14 +279,21 @@ > > /* Fan input RPM */ > > static inline int FAN_FROM_REG(int reg, int tpc) > > { > > - return (reg = 0 || reg = 0xffff) ? 0 : > > - (tpc = 0) ? 90000 * 60 / reg : tpc * reg; > > + if (tpc) { > > + return tpc * reg; > > + } else { > > + return (reg = 0 || reg = 0xffff) ? 0 : 90000 * 60 / reg; > > + } > > } > > > > static inline int FAN_TO_REG(int val, int tpc) > > { > > - return SENSORS_LIMIT((tpc = 0) ? 90000 * 60 / val : val / tpc, > > - 0, 0xffff); > > + if (tpc) { > > + return SENSORS_LIMIT(val / tpc, 0, 0xffff); > > + } else { > > + return (val <= 0) ? 0xffff : > > + SENSORS_LIMIT(90000 * 60 / val, 0, 0xfffe); > > + } > > } > > > > /* Fan TPC (tach pulse count) > > Looks good to me this time. > > Acked-by: Jean Delvare Applied to hwmon-2.6.git/testing, thanks. -- Mark M. Hoffman mhoffman@lightlink.com _______________________________________________ lm-sensors mailing list lm-sensors@lm-sensors.org http://lists.lm-sensors.org/mailman/listinfo/lm-sensors