All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@oracle.com>
To: kernel-janitors@vger.kernel.org
Subject: [patch] hwmon: prevent some divide by zeros in FAN_TO_REG()
Date: Thu, 05 Dec 2013 10:58:45 +0000	[thread overview]
Message-ID: <20131205105845.GA23161@elgon.mountain> (raw)

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.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

diff --git a/drivers/hwmon/vt8231.c b/drivers/hwmon/vt8231.c
index 0e7017841f7d..923c18034a5f 100644
--- a/drivers/hwmon/vt8231.c
+++ b/drivers/hwmon/vt8231.c
@@ -145,7 +145,7 @@ static const u8 regtempmin[] = { 0x3a, 0x3e, 0x2c, 0x2e, 0x30, 0x32 };
  */
 static inline u8 FAN_TO_REG(long rpm, int div)
 {
-	if (rpm = 0)
+	if (rpm * div = 0)
 		return 0;
 	return clamp_val(1310720 / (rpm * div), 1, 255);
 }
diff --git a/drivers/hwmon/lm78.c b/drivers/hwmon/lm78.c
index 6cf6bff79003..fc4578195674 100644
--- a/drivers/hwmon/lm78.c
+++ b/drivers/hwmon/lm78.c
@@ -92,7 +92,7 @@ static inline u8 IN_TO_REG(unsigned long val)
 
 static inline u8 FAN_TO_REG(long rpm, int div)
 {
-	if (rpm <= 0)
+	if (rpm <= 0 || rpm * div = 0)
 		return 255;
 	return clamp_val((1350000 + rpm * div / 2) / (rpm * div), 1, 254);
 }
diff --git a/drivers/hwmon/sis5595.c b/drivers/hwmon/sis5595.c
index 1404e6319deb..811620fe63b4 100644
--- a/drivers/hwmon/sis5595.c
+++ b/drivers/hwmon/sis5595.c
@@ -139,7 +139,7 @@ static inline u8 IN_TO_REG(unsigned long val)
 
 static inline u8 FAN_TO_REG(long rpm, int div)
 {
-	if (rpm <= 0)
+	if (rpm <= 0 || rpm * div = 0)
 		return 255;
 	return clamp_val((1350000 + rpm * div / 2) / (rpm * div), 1, 254);
 }

WARNING: multiple messages have this Message-ID (diff)
From: Dan Carpenter <dan.carpenter@oracle.com>
To: kernel-janitors@vger.kernel.org
Subject: [lm-sensors] [patch] hwmon: prevent some divide by zeros in FAN_TO_REG()
Date: Thu, 05 Dec 2013 10:58:45 +0000	[thread overview]
Message-ID: <20131205105845.GA23161@elgon.mountain> (raw)

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.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

diff --git a/drivers/hwmon/vt8231.c b/drivers/hwmon/vt8231.c
index 0e7017841f7d..923c18034a5f 100644
--- a/drivers/hwmon/vt8231.c
+++ b/drivers/hwmon/vt8231.c
@@ -145,7 +145,7 @@ static const u8 regtempmin[] = { 0x3a, 0x3e, 0x2c, 0x2e, 0x30, 0x32 };
  */
 static inline u8 FAN_TO_REG(long rpm, int div)
 {
-	if (rpm = 0)
+	if (rpm * div = 0)
 		return 0;
 	return clamp_val(1310720 / (rpm * div), 1, 255);
 }
diff --git a/drivers/hwmon/lm78.c b/drivers/hwmon/lm78.c
index 6cf6bff79003..fc4578195674 100644
--- a/drivers/hwmon/lm78.c
+++ b/drivers/hwmon/lm78.c
@@ -92,7 +92,7 @@ static inline u8 IN_TO_REG(unsigned long val)
 
 static inline u8 FAN_TO_REG(long rpm, int div)
 {
-	if (rpm <= 0)
+	if (rpm <= 0 || rpm * div = 0)
 		return 255;
 	return clamp_val((1350000 + rpm * div / 2) / (rpm * div), 1, 254);
 }
diff --git a/drivers/hwmon/sis5595.c b/drivers/hwmon/sis5595.c
index 1404e6319deb..811620fe63b4 100644
--- a/drivers/hwmon/sis5595.c
+++ b/drivers/hwmon/sis5595.c
@@ -139,7 +139,7 @@ static inline u8 IN_TO_REG(unsigned long val)
 
 static inline u8 FAN_TO_REG(long rpm, int div)
 {
-	if (rpm <= 0)
+	if (rpm <= 0 || rpm * div = 0)
 		return 255;
 	return clamp_val((1350000 + rpm * div / 2) / (rpm * div), 1, 254);
 }

_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

             reply	other threads:[~2013-12-05 10:58 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-12-05 10:58 Dan Carpenter [this message]
2013-12-05 10:58 ` [lm-sensors] [patch] hwmon: prevent some divide by zeros in FAN_TO_REG() 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
2013-12-05 12:59   ` [lm-sensors] " 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=20131205105845.GA23161@elgon.mountain \
    --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.