summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDheeraj CVR <cvr.dheeraj@gmail.com>2015-06-11 16:44:25 +0400
committerforkbomb <keepcalm444@gmail.com>2015-11-25 08:34:55 +1100
commitfc862f3a4c433c67605f12ad2d9addc6fc1bc831 (patch)
treea753c448934c1ef459b302d5d60d46a07f694d6b
parentea6c7d9c8609022e19200d888f449139139d9173 (diff)
downloaddevice_samsung_i9300-fc862f3a4c433c67605f12ad2d9addc6fc1bc831.zip
device_samsung_i9300-fc862f3a4c433c67605f12ad2d9addc6fc1bc831.tar.gz
device_samsung_i9300-fc862f3a4c433c67605f12ad2d9addc6fc1bc831.tar.bz2
libsensors: switch to portable typedefs to match callbacks
Using a strict basetype only coding style is not a good idea especially when we are dealing with callbacks which use portable typedef like int64_t. This kind of coding style would most likely end up in overflows at various places especially when dealing with timestamps and sensor delays which are caused when typecasting datatypes of different size. Switch to portable typedefs and get rid of "long". Change-Id: I75b9cace7602345dba9095f046292e6d4db07df4
-rw-r--r--libsensors/akm8975.c8
-rw-r--r--libsensors/cm36651_light.c6
-rw-r--r--libsensors/cm36651_proximity.c4
-rw-r--r--libsensors/input.c4
-rw-r--r--libsensors/lps331ap.c11
-rw-r--r--libsensors/lsm330dlc_acceleration.c8
-rw-r--r--libsensors/lsm330dlc_gyroscope.c6
-rw-r--r--libsensors/smdk4x12_sensors.c4
-rw-r--r--libsensors/smdk4x12_sensors.h8
9 files changed, 30 insertions, 29 deletions
diff --git a/libsensors/akm8975.c b/libsensors/akm8975.c
index 00f69ff..47771fb 100644
--- a/libsensors/akm8975.c
+++ b/libsensors/akm8975.c
@@ -42,7 +42,7 @@ struct akm8975_data {
AK8975PRMS akfs_params;
sensors_vec_t magnetic;
- long int delay;
+ int64_t delay;
int device_fd;
int uinput_fd;
@@ -166,7 +166,7 @@ void *akm8975_thread(void *thread_data)
char i2c_data[SENSOR_DATA_SIZE] = { 0 };
short magnetic_data[3];
short mode;
- long long int before, after;
+ int64_t before, after;
int diff;
int device_fd;
int uinput_fd;
@@ -520,11 +520,11 @@ int akm8975_deactivate(struct smdk4x12_sensors_handlers *handlers)
return 0;
}
-int akm8975_set_delay(struct smdk4x12_sensors_handlers *handlers, long int delay)
+int akm8975_set_delay(struct smdk4x12_sensors_handlers *handlers, int64_t delay)
{
struct akm8975_data *data;
- ALOGD("%s(%p, %ld)", __func__, handlers, delay);
+ ALOGD("%s(%p, %" PRId64 ")", __func__, handlers, delay);
if (handlers == NULL || handlers->data == NULL)
return -EINVAL;
diff --git a/libsensors/cm36651_light.c b/libsensors/cm36651_light.c
index bd7617b..6781797 100644
--- a/libsensors/cm36651_light.c
+++ b/libsensors/cm36651_light.c
@@ -150,19 +150,19 @@ int cm36651_light_deactivate(struct smdk4x12_sensors_handlers *handlers)
return 0;
}
-int cm36651_light_set_delay(struct smdk4x12_sensors_handlers *handlers, long int delay)
+int cm36651_light_set_delay(struct smdk4x12_sensors_handlers *handlers, int64_t delay)
{
struct cm36651_light_data *data;
int rc;
- ALOGD("%s(%p, %ld)", __func__, handlers, delay);
+ ALOGD("%s(%p, %" PRId64 ")", __func__, handlers, delay);
if (handlers == NULL || handlers->data == NULL)
return -EINVAL;
data = (struct cm36651_light_data *) handlers->data;
- rc = sysfs_value_write(data->path_delay, (int) delay);
+ rc = sysfs_value_write(data->path_delay, delay);
if (rc < 0) {
ALOGE("%s: Unable to write sysfs value", __func__);
return -1;
diff --git a/libsensors/cm36651_proximity.c b/libsensors/cm36651_proximity.c
index b102f9a..6529543 100644
--- a/libsensors/cm36651_proximity.c
+++ b/libsensors/cm36651_proximity.c
@@ -147,9 +147,9 @@ int cm36651_proximity_deactivate(struct smdk4x12_sensors_handlers *handlers)
return 0;
}
-int cm36651_proximity_set_delay(struct smdk4x12_sensors_handlers *handlers, long int delay)
+int cm36651_proximity_set_delay(struct smdk4x12_sensors_handlers *handlers, int64_t delay)
{
- ALOGD("%s(%p, %ld)", __func__, handlers, delay);
+ ALOGD("%s(%p, %" PRId64 ")", __func__, handlers, delay);
return 0;
}
diff --git a/libsensors/input.c b/libsensors/input.c
index d78dc64..eef2a8d 100644
--- a/libsensors/input.c
+++ b/libsensors/input.c
@@ -44,7 +44,7 @@ void input_event_set(struct input_event *event, int type, int code, int value)
gettimeofday(&event->time, NULL);
}
-long long int timestamp(struct timeval *time)
+int64_t timestamp(struct timeval *time)
{
if (time == NULL)
return -1;
@@ -52,7 +52,7 @@ long long int timestamp(struct timeval *time)
return time->tv_sec * 1000000000LL + time->tv_usec * 1000;
}
-long long int input_timestamp(struct input_event *event)
+int64_t input_timestamp(struct input_event *event)
{
if (event == NULL)
return -1;
diff --git a/libsensors/lps331ap.c b/libsensors/lps331ap.c
index 5c3007b..a8ef55a 100644
--- a/libsensors/lps331ap.c
+++ b/libsensors/lps331ap.c
@@ -150,13 +150,12 @@ int lps331ap_deactivate(struct smdk4x12_sensors_handlers *handlers)
return 0;
}
-int lps331ap_set_delay(struct smdk4x12_sensors_handlers *handlers, long int delay)
+int lps331ap_set_delay(struct smdk4x12_sensors_handlers *handlers, int64_t delay)
{
struct lps331ap_data *data;
- int d;
int rc;
- ALOGD("%s(%p, %ld)", __func__, handlers, delay);
+ ALOGD("%s(%p, %" PRId64 ")", __func__, handlers, delay);
if (handlers == NULL || handlers->data == NULL)
return -EINVAL;
@@ -164,11 +163,11 @@ int lps331ap_set_delay(struct smdk4x12_sensors_handlers *handlers, long int dela
data = (struct lps331ap_data *) handlers->data;
if (delay < 10000000)
- d = 10;
+ delay = 10;
else
- d = delay / 1000000;
+ delay = delay / 1000000;
- rc = sysfs_value_write(data->path_delay, d);
+ rc = sysfs_value_write(data->path_delay, delay);
if (rc < 0) {
ALOGE("%s: Unable to write sysfs value", __func__);
return -1;
diff --git a/libsensors/lsm330dlc_acceleration.c b/libsensors/lsm330dlc_acceleration.c
index cd22cdf..7f6985b 100644
--- a/libsensors/lsm330dlc_acceleration.c
+++ b/libsensors/lsm330dlc_acceleration.c
@@ -31,7 +31,7 @@
#include "lsm330dlc_accel.h"
struct lsm330dlc_acceleration_data {
- long int delay;
+ int64_t delay;
int device_fd;
int uinput_fd;
@@ -47,7 +47,7 @@ void *lsm330dlc_acceleration_thread(void *thread_data)
struct input_event event;
struct timeval time;
struct lsm330dlc_acc acceleration_data;
- long long int before, after;
+ int64_t before, after;
int diff;
int device_fd;
int uinput_fd;
@@ -285,14 +285,14 @@ int lsm330dlc_acceleration_deactivate(struct smdk4x12_sensors_handlers *handlers
return 0;
}
-int lsm330dlc_acceleration_set_delay(struct smdk4x12_sensors_handlers *handlers, long int delay)
+int lsm330dlc_acceleration_set_delay(struct smdk4x12_sensors_handlers *handlers, int64_t delay)
{
struct lsm330dlc_acceleration_data *data;
int64_t d;
int device_fd;
int rc;
- ALOGD("%s(%p, %ld)", __func__, handlers, delay);
+ ALOGD("%s(%p, %" PRId64 ")", __func__, handlers, delay);
if (handlers == NULL || handlers->data == NULL)
return -EINVAL;
diff --git a/libsensors/lsm330dlc_gyroscope.c b/libsensors/lsm330dlc_gyroscope.c
index 9c36790..b91b433 100644
--- a/libsensors/lsm330dlc_gyroscope.c
+++ b/libsensors/lsm330dlc_gyroscope.c
@@ -152,19 +152,19 @@ int lsm330dlc_gyroscope_deactivate(struct smdk4x12_sensors_handlers *handlers)
return 0;
}
-int lsm330dlc_gyroscope_set_delay(struct smdk4x12_sensors_handlers *handlers, long int delay)
+int lsm330dlc_gyroscope_set_delay(struct smdk4x12_sensors_handlers *handlers, int64_t delay)
{
struct lsm330dlc_gyroscope_data *data;
int rc;
- ALOGD("%s(%p, %ld)", __func__, handlers, delay);
+ ALOGD("%s(%p, %" PRId64 ")", __func__, handlers, delay);
if (handlers == NULL || handlers->data == NULL)
return -EINVAL;
data = (struct lsm330dlc_gyroscope_data *) handlers->data;
- rc = sysfs_value_write(data->path_delay, (int) delay);
+ rc = sysfs_value_write(data->path_delay, delay);
if (rc < 0) {
ALOGE("%s: Unable to write sysfs value", __func__);
return -1;
diff --git a/libsensors/smdk4x12_sensors.c b/libsensors/smdk4x12_sensors.c
index 353fe09..bd79a48 100644
--- a/libsensors/smdk4x12_sensors.c
+++ b/libsensors/smdk4x12_sensors.c
@@ -119,7 +119,7 @@ int smdk4x12_sensors_set_delay(struct sensors_poll_device_t *dev, int handle,
struct smdk4x12_sensors_device *device;
int i;
- ALOGD("%s(%p, %d, %ld)", __func__, dev, handle, (long int) ns);
+ ALOGD("%s(%p, %d, %" PRId64 ")", __func__, dev, handle, ns);
if (dev == NULL)
return -EINVAL;
@@ -134,7 +134,7 @@ int smdk4x12_sensors_set_delay(struct sensors_poll_device_t *dev, int handle,
continue;
if (device->handlers[i]->handle == handle && device->handlers[i]->set_delay != NULL)
- return device->handlers[i]->set_delay(device->handlers[i], (long int) ns);
+ return device->handlers[i]->set_delay(device->handlers[i], ns);
}
return 0;
diff --git a/libsensors/smdk4x12_sensors.h b/libsensors/smdk4x12_sensors.h
index 45ccbc8..da3d173 100644
--- a/libsensors/smdk4x12_sensors.h
+++ b/libsensors/smdk4x12_sensors.h
@@ -18,6 +18,8 @@
#include <stdint.h>
#include <poll.h>
#include <linux/input.h>
+#define __STDC_FORMAT_MACROS
+#include <inttypes.h>
#include <hardware/sensors.h>
#include <hardware/hardware.h>
@@ -39,7 +41,7 @@ struct smdk4x12_sensors_handlers {
int (*activate)(struct smdk4x12_sensors_handlers *handlers);
int (*deactivate)(struct smdk4x12_sensors_handlers *handlers);
int (*set_delay)(struct smdk4x12_sensors_handlers *handlers,
- long int delay);
+ int64_t delay);
int (*get_data)(struct smdk4x12_sensors_handlers *handlers,
struct sensors_event_t *event);
@@ -75,8 +77,8 @@ int smdk4x12_sensors_poll(struct sensors_poll_device_t *dev,
*/
void input_event_set(struct input_event *event, int type, int code, int value);
-long long int timestamp(struct timeval *time);
-long long int input_timestamp(struct input_event *event);
+int64_t timestamp(struct timeval *time);
+int64_t input_timestamp(struct input_event *event);
int uinput_rel_create(const char *name);
void uinput_destroy(int uinput_fd);
int input_open(char *name);