mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Guenter Roeck <linux@roeck-us.net>
To: linux-kernel@vger.kernel.org
Cc: Andrew Morton <akpm@linux-foundation.org>,
	Pekka Enberg <penberg@kernel.org>, Ingo Molnar <mingo@kernel.org>,
	"H. Peter Anvin" <hpa@zytor.com>,
	Jean Delvare <khali@linux-fr.org>,
	lm-sensors@lm-sensors.org, Guenter Roeck <linux@roeck-us.net>,
	Dirk Eibach <eibach@gdsys.de>,
	Steve Glendinning <steve.glendinning@shawell.net>
Subject: [PATCH 2/2] hwmon: Use IDIV_ROUND_CLOSEST if the dividend can be negative
Date: Tue, 28 Aug 2012 09:30:56 -0700	[thread overview]
Message-ID: <1346171456-29255-2-git-send-email-linux@roeck-us.net> (raw)
In-Reply-To: <1346171456-29255-1-git-send-email-linux@roeck-us.net>

DIV_ROUND_CLOSEST returns bad values for negative dividends.
Replace with IDIV_ROUND_CLOSEST where this can happen.

Cc: Jean Delvare <khali@linux-fr.org>
Cc: Dirk Eibach <eibach@gdsys.de>
Cc: Steve Glendinning <steve.glendinning@shawell.net>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 drivers/hwmon/ad7314.c           |    2 +-
 drivers/hwmon/ads1015.c          |    2 +-
 drivers/hwmon/adt7410.c          |    6 +++---
 drivers/hwmon/emc2103.c          |    4 ++--
 drivers/hwmon/pmbus/pmbus_core.c |    4 ++--
 drivers/hwmon/w83627ehf.c        |    2 +-
 6 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/drivers/hwmon/ad7314.c b/drivers/hwmon/ad7314.c
index 455294f..6fb3013 100644
--- a/drivers/hwmon/ad7314.c
+++ b/drivers/hwmon/ad7314.c
@@ -81,7 +81,7 @@ static ssize_t ad7314_show_temperature(struct device *dev,
 		data = (data << 2) >> 2;
 
 		return sprintf(buf, "%d\n",
-			       DIV_ROUND_CLOSEST(data * 3125, 100));
+			       IDIV_ROUND_CLOSEST(data * 3125, 100));
 	default:
 		return -EINVAL;
 	}
diff --git a/drivers/hwmon/ads1015.c b/drivers/hwmon/ads1015.c
index 2798246..ab12c7f 100644
--- a/drivers/hwmon/ads1015.c
+++ b/drivers/hwmon/ads1015.c
@@ -114,7 +114,7 @@ static int ads1015_reg_to_mv(struct i2c_client *client, unsigned int channel,
 	unsigned int pga = data->channel_data[channel].pga;
 	int fullscale = fullscale_table[pga];
 
-	return DIV_ROUND_CLOSEST(reg * fullscale, 0x7ff0);
+	return IDIV_ROUND_CLOSEST(reg * fullscale, 0x7ff0);
 }
 
 /* sysfs callback function */
diff --git a/drivers/hwmon/adt7410.c b/drivers/hwmon/adt7410.c
index 030c8d7..0acc887 100644
--- a/drivers/hwmon/adt7410.c
+++ b/drivers/hwmon/adt7410.c
@@ -173,8 +173,8 @@ abort:
 
 static s16 ADT7410_TEMP_TO_REG(long temp)
 {
-	return DIV_ROUND_CLOSEST(SENSORS_LIMIT(temp, ADT7410_TEMP_MIN,
-					       ADT7410_TEMP_MAX) * 128, 1000);
+	return IDIV_ROUND_CLOSEST(SENSORS_LIMIT(temp, ADT7410_TEMP_MIN,
+						ADT7410_TEMP_MAX) * 128, 1000);
 }
 
 static int ADT7410_REG_TO_TEMP(struct adt7410_data *data, s16 reg)
@@ -186,7 +186,7 @@ static int ADT7410_REG_TO_TEMP(struct adt7410_data *data, s16 reg)
 	 * temperature is stored in twos complement format, in steps of
 	 * 1/128°C
 	 */
-	return DIV_ROUND_CLOSEST(reg * 1000, 128);
+	return IDIV_ROUND_CLOSEST(reg * 1000, 128);
 }
 
 /*-----------------------------------------------------------------------*/
diff --git a/drivers/hwmon/emc2103.c b/drivers/hwmon/emc2103.c
index 77f434c..161343d 100644
--- a/drivers/hwmon/emc2103.c
+++ b/drivers/hwmon/emc2103.c
@@ -250,7 +250,7 @@ static ssize_t set_temp_min(struct device *dev, struct device_attribute *da,
 	if (result < 0)
 		return -EINVAL;
 
-	val = DIV_ROUND_CLOSEST(val, 1000);
+	val = IDIV_ROUND_CLOSEST(val, 1000);
 	if ((val < -63) || (val > 127))
 		return -EINVAL;
 
@@ -274,7 +274,7 @@ static ssize_t set_temp_max(struct device *dev, struct device_attribute *da,
 	if (result < 0)
 		return -EINVAL;
 
-	val = DIV_ROUND_CLOSEST(val, 1000);
+	val = IDIV_ROUND_CLOSEST(val, 1000);
 	if ((val < -63) || (val > 127))
 		return -EINVAL;
 
diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
index 29b319d..58ddf57 100644
--- a/drivers/hwmon/pmbus/pmbus_core.c
+++ b/drivers/hwmon/pmbus/pmbus_core.c
@@ -507,7 +507,7 @@ static long pmbus_reg2data_direct(struct pmbus_data *data,
 		R--;
 	}
 	while (R < 0) {
-		val = DIV_ROUND_CLOSEST(val, 10);
+		val = IDIV_ROUND_CLOSEST(val, 10);
 		R++;
 	}
 
@@ -647,7 +647,7 @@ static u16 pmbus_data2reg_direct(struct pmbus_data *data,
 		R--;
 	}
 	while (R < 0) {
-		val = DIV_ROUND_CLOSEST(val, 10);
+		val = IDIV_ROUND_CLOSEST(val, 10);
 		R++;
 	}
 
diff --git a/drivers/hwmon/w83627ehf.c b/drivers/hwmon/w83627ehf.c
index 1821b74..f500fa9 100644
--- a/drivers/hwmon/w83627ehf.c
+++ b/drivers/hwmon/w83627ehf.c
@@ -1258,7 +1258,7 @@ store_temp_offset(struct device *dev, struct device_attribute *attr,
 	if (err < 0)
 		return err;
 
-	val = SENSORS_LIMIT(DIV_ROUND_CLOSEST(val, 1000), -128, 127);
+	val = SENSORS_LIMIT(IDIV_ROUND_CLOSEST(val, 1000), -128, 127);
 
 	mutex_lock(&data->update_lock);
 	data->temp_offset[nr] = val;
-- 
1.7.9.7


  reply	other threads:[~2012-08-28 16:30 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-08-28 16:30 [PATCH v2 1/2] linux/kernel.h: Introduce IDIV_ROUND_CLOSEST Guenter Roeck
2012-08-28 16:30 ` Guenter Roeck [this message]
2012-08-30 23:15 ` Andrew Morton
2012-08-30 23:50   ` Guenter Roeck

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=1346171456-29255-2-git-send-email-linux@roeck-us.net \
    --to=linux@roeck-us.net \
    --cc=akpm@linux-foundation.org \
    --cc=eibach@gdsys.de \
    --cc=hpa@zytor.com \
    --cc=khali@linux-fr.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lm-sensors@lm-sensors.org \
    --cc=mingo@kernel.org \
    --cc=penberg@kernel.org \
    --cc=steve.glendinning@shawell.net \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome