From: Dan Carpenter <dan.carpenter@oracle.com>
To: kernel-janitors@vger.kernel.org
Subject: Re: [patch] hwmon: prevent some divide by zeros in FAN_TO_REG()
Date: Thu, 05 Dec 2013 12:59:25 +0000 [thread overview]
Message-ID: <20131205125925.GB28413@mwanda> (raw)
In-Reply-To: <20131205105845.GA23161@elgon.mountain>
On Thu, Dec 05, 2013 at 01:06:13PM +0100, Jean Delvare wrote:
> Hi Dan,
>
> On Thu, 5 Dec 2013 13:58:45 +0300, Dan Carpenter wrote:
> > It's not enough to just test if "rpm" is zero, the "rpm * div" operation
> > could overflow and that could also lead to a divide by zero.
>
> If you believe an overflow can happen (and indeed it can) then this
> isn't the way to handle it. Avoiding a divide by zero is certainly nice
> but properly handling the other overflow cases too would be better.
>
> In practice, this means for the vt8231 driver:
>
> if (rpm = 0 || rpm > 1310720)
> return 0;
>
> and for the lm78 and sis5595 drivers:
>
> if (rpm <= 0)
> return 255;
> if (rpm > 1350000)
> return 0;
>
> That way you're certain to never overflow (the maximum value for div is
> 8), and insanely large values are handled properly instead of resulting
> in random register values.
Yes. I will resend.
regards,
dan carpenter
WARNING: multiple messages have this Message-ID (diff)
From: Dan Carpenter <dan.carpenter@oracle.com>
To: kernel-janitors@vger.kernel.org
Subject: Re: [lm-sensors] [patch] hwmon: prevent some divide by zeros in FAN_TO_REG()
Date: Thu, 05 Dec 2013 12:59:25 +0000 [thread overview]
Message-ID: <20131205125925.GB28413@mwanda> (raw)
In-Reply-To: <20131205105845.GA23161@elgon.mountain>
On Thu, Dec 05, 2013 at 01:06:13PM +0100, Jean Delvare wrote:
> Hi Dan,
>
> On Thu, 5 Dec 2013 13:58:45 +0300, Dan Carpenter wrote:
> > It's not enough to just test if "rpm" is zero, the "rpm * div" operation
> > could overflow and that could also lead to a divide by zero.
>
> If you believe an overflow can happen (and indeed it can) then this
> isn't the way to handle it. Avoiding a divide by zero is certainly nice
> but properly handling the other overflow cases too would be better.
>
> In practice, this means for the vt8231 driver:
>
> if (rpm = 0 || rpm > 1310720)
> return 0;
>
> and for the lm78 and sis5595 drivers:
>
> if (rpm <= 0)
> return 255;
> if (rpm > 1350000)
> return 0;
>
> That way you're certain to never overflow (the maximum value for div is
> 8), and insanely large values are handled properly instead of resulting
> in random register values.
Yes. I will resend.
regards,
dan carpenter
_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
next prev parent reply other threads:[~2013-12-05 12:59 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-12-05 10:58 [patch] hwmon: prevent some divide by zeros in FAN_TO_REG() Dan Carpenter
2013-12-05 10:58 ` [lm-sensors] " Dan Carpenter
2013-12-05 12:06 ` Jean Delvare
2013-12-05 12:06 ` [lm-sensors] " Jean Delvare
2013-12-05 12:59 ` Dan Carpenter [this message]
2013-12-05 12:59 ` Dan Carpenter
2013-12-05 13:13 ` Dan Carpenter
2013-12-05 13:13 ` [lm-sensors] " Dan Carpenter
2013-12-05 14:29 ` Jean Delvare
2013-12-05 14:29 ` [lm-sensors] " Jean Delvare
-- strict thread matches above, loose matches on Subject: below --
2013-12-05 11:07 roger
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20131205125925.GB28413@mwanda \
--to=dan.carpenter@oracle.com \
--cc=kernel-janitors@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.