aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJonathan Cameron <jic23@kernel.org>2015-01-31 04:41:14 -0500
committerJonathan Cameron <jic23@kernel.org>2015-01-31 04:41:14 -0500
commit67460e8c9a5c59f66e1d476fd9341086cd792e5a (patch)
tree9e83681f81674d3b0f967dad45399db84d664172
parent40cb761306d6c19d80fe85f9ae52615932f76b71 (diff)
iio:common:ssp_sensors fix warnings due to 32 bit instead of 64 bit passed to do_div
Also change to div64_u64 in one place to avoid loss of precision (was dividing a 32 bit number by a 64 bit number, but casting this to 64 bit divided by 32 bit) Those divide functions certainly have esoteric naming! Fixes warnings with asm-generic/div64.h do_div such as: In file included from drivers/iio/common/ssp_sensors/ssp_iio.c:20:0: drivers/iio/common/ssp_sensors/ssp_iio_sensor.h: In function 'ssp_convert_to_freq': >> drivers/iio/common/ssp_sensors/ssp_iio_sensor.h:56:16: warning: comparison of distinct pointer types lacks a cast [enabled by default] drivers/iio/common/ssp_sensors/ssp_iio_sensor.h:56:2: warning: right shift count >= width of type [enabled by default] >> drivers/iio/common/ssp_sensors/ssp_iio_sensor.h:56:2: warning: passing argument 1 of '__div64_32' from incompatible pointer type [enabled by default] include/asm-generic/div64.h:35:17: note: expected 'uint64_t *' but argument is of type 'int *' drivers/iio/common/ssp_sensors/ssp_iio.c: In function 'ssp_common_process_data': include/linux/iio/buffer.h:142:32: warning: 'calculated_time' may be used uninitialized in this function [-Wuninitialized] drivers/iio/common/ssp_sensors/ssp_iio.c:83:10: note: 'calculated_time' was declared here Fixed by using straight coded version as per the description in the div64.h header, thus ensuring no issue with 32 bit integers. Reported-by: kbuild test robot <fengguang.wu@intel.com> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
-rw-r--r--drivers/iio/common/ssp_sensors/ssp_iio_sensor.h9
1 files changed, 5 insertions, 4 deletions
diff --git a/drivers/iio/common/ssp_sensors/ssp_iio_sensor.h b/drivers/iio/common/ssp_sensors/ssp_iio_sensor.h
index dda267c9bd2a..541c6590d69c 100644
--- a/drivers/iio/common/ssp_sensors/ssp_iio_sensor.h
+++ b/drivers/iio/common/ssp_sensors/ssp_iio_sensor.h
@@ -30,7 +30,7 @@
30} 30}
31 31
32#define SSP_MS_PER_S 1000 32#define SSP_MS_PER_S 1000
33#define SSP_INVERTED_SCALING_FACTOR 1000000ULL 33#define SSP_INVERTED_SCALING_FACTOR 1000000U
34 34
35#define SSP_FACTOR_WITH_MS \ 35#define SSP_FACTOR_WITH_MS \
36 (SSP_INVERTED_SCALING_FACTOR * SSP_MS_PER_S) 36 (SSP_INVERTED_SCALING_FACTOR * SSP_MS_PER_S)
@@ -53,7 +53,8 @@ static inline void ssp_convert_to_freq(u32 time, int *integer_part,
53 } 53 }
54 54
55 *integer_part = SSP_FACTOR_WITH_MS / time; 55 *integer_part = SSP_FACTOR_WITH_MS / time;
56 *fractional = do_div(*integer_part, SSP_INVERTED_SCALING_FACTOR); 56 *fractional = *integer_part % SSP_INVERTED_SCALING_FACTOR;
57 *integer_part = *integer_part / SSP_INVERTED_SCALING_FACTOR;
57} 58}
58 59
59/* Converts frequency to time in ms */ 60/* Converts frequency to time in ms */
@@ -61,10 +62,10 @@ static inline int ssp_convert_to_time(int integer_part, int fractional)
61{ 62{
62 u64 value; 63 u64 value;
63 64
64 value = integer_part * SSP_INVERTED_SCALING_FACTOR + fractional; 65 value = (u64)integer_part * SSP_INVERTED_SCALING_FACTOR + fractional;
65 if (value == 0) 66 if (value == 0)
66 return 0; 67 return 0;
67 68
68 return div_u64(SSP_FACTOR_WITH_MS, value); 69 return div64_u64((u64)SSP_FACTOR_WITH_MS, value);
69} 70}
70#endif /* __SSP_IIO_SENSOR_H__ */ 71#endif /* __SSP_IIO_SENSOR_H__ */