#include <linux/bitfield.h>
#include <linux/hwmon.h>
+#include <linux/math64.h>
#include <linux/mfd/macsmc.h>
#include <linux/module.h>
#include <linux/of.h>
if (ret < 0)
return ret;
- *p = mult_frac(val, scale, 65536);
+ *p = mul_u64_u32_div(val, scale, 65536);
return 0;
}
* them.
*/
static int macsmc_hwmon_read_f32_scaled(struct apple_smc *smc, smc_key key,
- int *p, int scale)
+ long *p, int scale)
{
u32 fval;
u64 val;
val = 0;
else if (exp < 0)
val >>= -exp;
- else if (exp != 0 && (val & ~((1UL << (64 - exp)) - 1))) /* overflow */
+ else if (exp != 0 && (val & ~((1ULL << (64 - exp)) - 1))) /* overflow */
val = U64_MAX;
else
val <<= exp;
if (fval & FLT_SIGN_MASK) {
- if (val > (-(s64)INT_MIN))
- *p = INT_MIN;
+ if (val > (u64)LONG_MAX + 1)
+ *p = LONG_MIN;
else
- *p = -val;
+ *p = -(long)val;
} else {
- if (val > INT_MAX)
- *p = INT_MAX;
+ if (val > (u64)LONG_MAX)
+ *p = LONG_MAX;
else
- *p = val;
+ *p = (long)val;
}
return 0;
switch (sensor->info.type_code) {
/* 32-bit IEEE 754 float */
case __SMC_KEY('f', 'l', 't', ' '): {
- u32 flt_ = 0;
+ long flt_ = 0;
ret = macsmc_hwmon_read_f32_scaled(smc, sensor->macsmc_key,
&flt_, scale);
if (ret)
return ret;
- *val = (long)ioft;
+ if (ioft > LONG_MAX)
+ *val = LONG_MAX;
+ else
+ *val = (long)ioft;
break;
}
default:
return 0;
}
-static int macsmc_hwmon_write_f32(struct apple_smc *smc, smc_key key, int value)
+static int macsmc_hwmon_write_f32(struct apple_smc *smc, smc_key key, long value)
{
u64 val;
u32 fval = 0;