* [lm-sensors] [PATCH] pmbus: Use long variables for register to data
@ 2011-07-11 19:04 Guenter Roeck
2011-07-12 7:00 ` [lm-sensors] [PATCH] pmbus: Use long variables for register to Jean Delvare
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Guenter Roeck @ 2011-07-11 19:04 UTC (permalink / raw)
To: lm-sensors
Using integer variable types for register to data conversions can cause
overflows especially for power calculations, which are in microwatt.
Use long variables instead.
Signed-off-by: Guenter Roeck <guenter.roeck@ericsson.com>
---
drivers/hwmon/pmbus_core.c | 20 ++++++++++----------
1 files changed, 10 insertions(+), 10 deletions(-)
diff --git a/drivers/hwmon/pmbus_core.c b/drivers/hwmon/pmbus_core.c
index 744672c..8e31a8e 100644
--- a/drivers/hwmon/pmbus_core.c
+++ b/drivers/hwmon/pmbus_core.c
@@ -362,8 +362,8 @@ static struct pmbus_data *pmbus_update_device(struct device *dev)
* Convert linear sensor values to milli- or micro-units
* depending on sensor type.
*/
-static int pmbus_reg2data_linear(struct pmbus_data *data,
- struct pmbus_sensor *sensor)
+static long pmbus_reg2data_linear(struct pmbus_data *data,
+ struct pmbus_sensor *sensor)
{
s16 exponent;
s32 mantissa;
@@ -397,15 +397,15 @@ static int pmbus_reg2data_linear(struct pmbus_data *data,
else
val >>= -exponent;
- return (int)val;
+ return val;
}
/*
* Convert direct sensor values to milli- or micro-units
* depending on sensor type.
*/
-static int pmbus_reg2data_direct(struct pmbus_data *data,
- struct pmbus_sensor *sensor)
+static long pmbus_reg2data_direct(struct pmbus_data *data,
+ struct pmbus_sensor *sensor)
{
long val = (s16) sensor->data;
long m, b, R;
@@ -440,12 +440,12 @@ static int pmbus_reg2data_direct(struct pmbus_data *data,
R++;
}
- return (int)((val - b) / m);
+ return (val - b) / m;
}
-static int pmbus_reg2data(struct pmbus_data *data, struct pmbus_sensor *sensor)
+static long pmbus_reg2data(struct pmbus_data *data, struct pmbus_sensor *sensor)
{
- int val;
+ long val;
if (data->info->direct[sensor->class])
val = pmbus_reg2data_direct(data, sensor);
@@ -619,7 +619,7 @@ static int pmbus_get_boolean(struct pmbus_data *data, int index, int *val)
if (!s1 && !s2)
*val = !!regval;
else {
- int v1, v2;
+ long v1, v2;
struct pmbus_sensor *sensor1, *sensor2;
sensor1 = &data->sensors[s1];
@@ -661,7 +661,7 @@ static ssize_t pmbus_show_sensor(struct device *dev,
if (sensor->data < 0)
return sensor->data;
- return snprintf(buf, PAGE_SIZE, "%d\n", pmbus_reg2data(data, sensor));
+ return snprintf(buf, PAGE_SIZE, "%ld\n", pmbus_reg2data(data, sensor));
}
static ssize_t pmbus_set_sensor(struct device *dev,
--
1.7.3.1
_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [lm-sensors] [PATCH] pmbus: Use long variables for register to
2011-07-11 19:04 [lm-sensors] [PATCH] pmbus: Use long variables for register to data Guenter Roeck
@ 2011-07-12 7:00 ` Jean Delvare
2011-07-12 13:40 ` Guenter Roeck
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Jean Delvare @ 2011-07-12 7:00 UTC (permalink / raw)
To: lm-sensors
Hi Guenter,
On Mon, 11 Jul 2011 12:04:24 -0700, Guenter Roeck wrote:
> Using integer variable types for register to data conversions can cause
> overflows especially for power calculations, which are in microwatt.
> Use long variables instead.
I have no objection, using longs for calculations certainly makes
sense, however does it really help in practice? I thought that
sizeof(int) = sizeof(long) for all architectures on Linux?
>
> Signed-off-by: Guenter Roeck <guenter.roeck@ericsson.com>
Either way:
Acked-by: Jean Delvare <khali@linux-fr.org>
> ---
> drivers/hwmon/pmbus_core.c | 20 ++++++++++----------
> 1 files changed, 10 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/hwmon/pmbus_core.c b/drivers/hwmon/pmbus_core.c
> index 744672c..8e31a8e 100644
> --- a/drivers/hwmon/pmbus_core.c
> +++ b/drivers/hwmon/pmbus_core.c
> @@ -362,8 +362,8 @@ static struct pmbus_data *pmbus_update_device(struct device *dev)
> * Convert linear sensor values to milli- or micro-units
> * depending on sensor type.
> */
> -static int pmbus_reg2data_linear(struct pmbus_data *data,
> - struct pmbus_sensor *sensor)
> +static long pmbus_reg2data_linear(struct pmbus_data *data,
> + struct pmbus_sensor *sensor)
> {
> s16 exponent;
> s32 mantissa;
> @@ -397,15 +397,15 @@ static int pmbus_reg2data_linear(struct pmbus_data *data,
> else
> val >>= -exponent;
>
> - return (int)val;
> + return val;
> }
>
> /*
> * Convert direct sensor values to milli- or micro-units
> * depending on sensor type.
> */
> -static int pmbus_reg2data_direct(struct pmbus_data *data,
> - struct pmbus_sensor *sensor)
> +static long pmbus_reg2data_direct(struct pmbus_data *data,
> + struct pmbus_sensor *sensor)
> {
> long val = (s16) sensor->data;
> long m, b, R;
> @@ -440,12 +440,12 @@ static int pmbus_reg2data_direct(struct pmbus_data *data,
> R++;
> }
>
> - return (int)((val - b) / m);
> + return (val - b) / m;
> }
>
> -static int pmbus_reg2data(struct pmbus_data *data, struct pmbus_sensor *sensor)
> +static long pmbus_reg2data(struct pmbus_data *data, struct pmbus_sensor *sensor)
> {
> - int val;
> + long val;
>
> if (data->info->direct[sensor->class])
> val = pmbus_reg2data_direct(data, sensor);
> @@ -619,7 +619,7 @@ static int pmbus_get_boolean(struct pmbus_data *data, int index, int *val)
> if (!s1 && !s2)
> *val = !!regval;
> else {
> - int v1, v2;
> + long v1, v2;
> struct pmbus_sensor *sensor1, *sensor2;
>
> sensor1 = &data->sensors[s1];
> @@ -661,7 +661,7 @@ static ssize_t pmbus_show_sensor(struct device *dev,
> if (sensor->data < 0)
> return sensor->data;
>
> - return snprintf(buf, PAGE_SIZE, "%d\n", pmbus_reg2data(data, sensor));
> + return snprintf(buf, PAGE_SIZE, "%ld\n", pmbus_reg2data(data, sensor));
> }
>
> static ssize_t pmbus_set_sensor(struct device *dev,
--
Jean Delvare
_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [lm-sensors] [PATCH] pmbus: Use long variables for register to
2011-07-11 19:04 [lm-sensors] [PATCH] pmbus: Use long variables for register to data Guenter Roeck
2011-07-12 7:00 ` [lm-sensors] [PATCH] pmbus: Use long variables for register to Jean Delvare
@ 2011-07-12 13:40 ` Guenter Roeck
2011-07-12 16:03 ` Jean Delvare
2011-07-12 16:25 ` Guenter Roeck
3 siblings, 0 replies; 5+ messages in thread
From: Guenter Roeck @ 2011-07-12 13:40 UTC (permalink / raw)
To: lm-sensors
On Tue, Jul 12, 2011 at 03:00:16AM -0400, Jean Delvare wrote:
> Hi Guenter,
>
> On Mon, 11 Jul 2011 12:04:24 -0700, Guenter Roeck wrote:
> > Using integer variable types for register to data conversions can cause
> > overflows especially for power calculations, which are in microwatt.
> > Use long variables instead.
>
> I have no objection, using longs for calculations certainly makes
> sense, however does it really help in practice? I thought that
> sizeof(int) = sizeof(long) for all architectures on Linux?
>
No ... for x86_64 long is 64 bit and int is 32 bit. I'll may have
to switch to "long long" at some point, though, or maybe s64.
Still hesitating to do that.
> >
> > Signed-off-by: Guenter Roeck <guenter.roeck@ericsson.com>
>
> Either way:
>
> Acked-by: Jean Delvare <khali@linux-fr.org>
>
Thanks,
Guenter
_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [lm-sensors] [PATCH] pmbus: Use long variables for register to
2011-07-11 19:04 [lm-sensors] [PATCH] pmbus: Use long variables for register to data Guenter Roeck
2011-07-12 7:00 ` [lm-sensors] [PATCH] pmbus: Use long variables for register to Jean Delvare
2011-07-12 13:40 ` Guenter Roeck
@ 2011-07-12 16:03 ` Jean Delvare
2011-07-12 16:25 ` Guenter Roeck
3 siblings, 0 replies; 5+ messages in thread
From: Jean Delvare @ 2011-07-12 16:03 UTC (permalink / raw)
To: lm-sensors
On Tue, 12 Jul 2011 06:40:57 -0700, Guenter Roeck wrote:
> On Tue, Jul 12, 2011 at 03:00:16AM -0400, Jean Delvare wrote:
> > Hi Guenter,
> >
> > On Mon, 11 Jul 2011 12:04:24 -0700, Guenter Roeck wrote:
> > > Using integer variable types for register to data conversions can cause
> > > overflows especially for power calculations, which are in microwatt.
> > > Use long variables instead.
> >
> > I have no objection, using longs for calculations certainly makes
> > sense, however does it really help in practice? I thought that
> > sizeof(int) = sizeof(long) for all architectures on Linux?
> >
> No ... for x86_64 long is 64 bit and int is 32 bit.
D'oh, you're right. Will I ever remember this...
> I'll may have
> to switch to "long long" at some point, though, or maybe s64.
> Still hesitating to do that.
I'd think twice about it (and how to do it exactly)... I think long
long is relatively expensive on 32-bit x86?
--
Jean Delvare
_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [lm-sensors] [PATCH] pmbus: Use long variables for register to
2011-07-11 19:04 [lm-sensors] [PATCH] pmbus: Use long variables for register to data Guenter Roeck
` (2 preceding siblings ...)
2011-07-12 16:03 ` Jean Delvare
@ 2011-07-12 16:25 ` Guenter Roeck
3 siblings, 0 replies; 5+ messages in thread
From: Guenter Roeck @ 2011-07-12 16:25 UTC (permalink / raw)
To: lm-sensors
On Tue, Jul 12, 2011 at 12:03:25PM -0400, Jean Delvare wrote:
> On Tue, 12 Jul 2011 06:40:57 -0700, Guenter Roeck wrote:
> > On Tue, Jul 12, 2011 at 03:00:16AM -0400, Jean Delvare wrote:
> > > Hi Guenter,
> > >
> > > On Mon, 11 Jul 2011 12:04:24 -0700, Guenter Roeck wrote:
> > > > Using integer variable types for register to data conversions can cause
> > > > overflows especially for power calculations, which are in microwatt.
> > > > Use long variables instead.
> > >
> > > I have no objection, using longs for calculations certainly makes
> > > sense, however does it really help in practice? I thought that
> > > sizeof(int) = sizeof(long) for all architectures on Linux?
> > >
> > No ... for x86_64 long is 64 bit and int is 32 bit.
>
> D'oh, you're right. Will I ever remember this...
>
> > I'll may have
> > to switch to "long long" at some point, though, or maybe s64.
> > Still hesitating to do that.
>
> I'd think twice about it (and how to do it exactly)... I think long
> long is relatively expensive on 32-bit x86?
>
That is my concern ... I think I'll wait with that change until someone
actually needs it.
Guenter
_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2011-07-12 16:25 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-07-11 19:04 [lm-sensors] [PATCH] pmbus: Use long variables for register to data Guenter Roeck
2011-07-12 7:00 ` [lm-sensors] [PATCH] pmbus: Use long variables for register to Jean Delvare
2011-07-12 13:40 ` Guenter Roeck
2011-07-12 16:03 ` Jean Delvare
2011-07-12 16:25 ` Guenter Roeck
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.