From 17fd865ff6c4965cf37f0d7e76e0acc56f8061e9 Mon Sep 17 00:00:00 2001 From: Andy Ross Date: Thu, 26 Sep 2013 12:31:26 -0700 Subject: [PATCH] libsensors: correct read() usage The readEvents() implementation would attempt to read buffer_len (two by default) IIO events from the device, but would only ever process one, leading to dropped events in the case of overflow. It was also not checking the return value from read and would push garbage data on I/O errors (probably would not happen in regular usage, but IIO devices are known to return -EBUSY or -EINVAL if there are other users or if the sysfs parameters are set incorrectly). Change-Id: I7f66f530c9fce0540f1596456b3ca191406bbd27 For: AXIA-3287 Signed-off-by: Andy Ross Reviewed-on: https://otc-android.intel.com/gerrit/22150 Reviewed-by: Daniel Leung Reviewed-by: Russell Webb Tested-by: jenkins autobuilder --- common/libsensors/SensorIIODev.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/common/libsensors/SensorIIODev.cpp b/common/libsensors/SensorIIODev.cpp index 9259b14..faf7fdd 100644 --- a/common/libsensors/SensorIIODev.cpp +++ b/common/libsensors/SensorIIODev.cpp @@ -623,13 +623,16 @@ int SensorIIODev::readEvents(sensors_event_t *data, int count){ *data = mPendingEvent; return 1; } - read_size = read(mFd, raw_buffer, datum_size * buffer_len); + read_size = read(mFd, raw_buffer, datum_size); numEventReceived = 0; - if (processEvent(raw_buffer, datum_size) >= 0){ - mPendingEvent.timestamp = getTimestamp(); - mPendingEvent.timestamp = getTimestamp(); - *data = mPendingEvent; - numEventReceived++; + if(read_size != datum_size) { + ALOGE("read() error (or short count) from IIO device: %d\n", errno); + } else { + if (processEvent(raw_buffer, datum_size) >= 0) { + mPendingEvent.timestamp = getTimestamp(); + *data = mPendingEvent; + numEventReceived++; + } } return numEventReceived; } -- 2.11.0