Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Static Analysis Issues for Sensor Module for IVI #124

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sensors/2.0/iiohal_mediation_v2.0/Sensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ Result Sensor::flush() {
// Note: If a sensor supports batching, write all of the
// currently batched events for the sensor to the Event
// FMQ prior to writing the flush complete event.
Event ev;
Event ev{};
ev.sensorHandle = mSensorInfo.sensorHandle;
ev.sensorType = SensorType::META_DATA;
ev.u.meta.what = MetaDataEventType::META_DATA_FLUSH_COMPLETE;
Expand Down
12 changes: 7 additions & 5 deletions sensors/2.0/iiohal_mediation_v2.0/Sensors.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ struct Sensors : public ISensorsInterface, public ISensorsEventCallback {
if(mSensors.size() <= 0) {
return Result::BAD_VALUE;
}
for (auto sensor : mSensors) {
for (auto& sensor : mSensors) {
sensor.second->setOperationMode(mode);
}
return Result::OK;
Expand Down Expand Up @@ -134,7 +134,7 @@ struct Sensors : public ISensorsInterface, public ISensorsEventCallback {
Result result = Result::OK;

// Ensure that all sensors are disabled
for (auto sensor : mSensors) {
for (auto& sensor : mSensors) {
sensor.second->activate(false /* enable */);
}

Expand Down Expand Up @@ -247,9 +247,11 @@ struct Sensors : public ISensorsInterface, public ISensorsEventCallback {
* Utility function to delete the Event Flag
*/
void deleteEventFlag() {
status_t status = EventFlag::deleteEventFlag(&mEventQueueFlag);
if (status != OK) {
ALOGI("Failed to delete event flag: %d", status);
if (mEventQueueFlag != nullptr) {
status_t status = EventFlag::deleteEventFlag(&mEventQueueFlag);
if (status != OK) {
ALOGI("Failed to delete event flag: %d", status);
}
}
}

Expand Down
17 changes: 12 additions & 5 deletions sensors/2.0/iiohal_mediation_v2.0/iioClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,16 @@ void iioClient::iioThread(struct iioclient_device *devlist) {
* once before use
*/
iioClient *iioc = iioClient::get_iioClient();

if (iioc == NULL)
return;

while (!iioc->is_iioc_initialized && !iioc->iioInit())
sleep(5);

/* post initialization of iio-devices to align with
* android sensor fwk.*/
for (int id = 1; id <= MAX_SENSOR; id++) {
for (int id = 1; id < MAX_SENSOR; id++) {
if (!devlist[id].is_initialized)
continue;

Expand All @@ -88,7 +92,7 @@ void iioClient::iioThread(struct iioclient_device *devlist) {
* this api is implemented to collect active sensor data from iiod.
*/
while (iioc) {
for (int id = 1; id <= MAX_SENSOR; id++) {
for (int id = 1; id < MAX_SENSOR; id++) {
if (!(devlist[id].is_initialized && devlist[id].is_enabled))
continue;

Expand Down Expand Up @@ -238,7 +242,7 @@ bool iioClient::iioInit(void) {
* enabled set to 1 to enable, or 0 to disable the sensor.
*/
int iioClient::activate(int handle, bool enabled) {
if ((handle < 0) || (handle > MAX_SENSOR)) {
if ((handle < 0) || (handle >= MAX_SENSOR)) {
ALOGE("ERROR: activate(%d) Sensor hadle(%d) is out of range", enabled, handle);
return 0;
}
Expand All @@ -253,7 +257,7 @@ int iioClient::activate(int handle, bool enabled) {
return 0;

active_sensor_count = 0;
for (int id = 1; id <= MAX_SENSOR; id++)
for (int id = 1; id < MAX_SENSOR; id++)
if (devlist[id].is_initialized && devlist[id].is_enabled)
active_sensor_count++;

Expand All @@ -265,6 +269,9 @@ int iioClient::activate(int handle, bool enabled) {
const struct iio_device *device = devlist[handle].dev;
struct iio_channel *channel = iio_device_get_channel(device, index);

if(channel == NULL)
continue;

/* skip output channels */
if (iio_channel_is_output(channel))
continue;
Expand All @@ -287,7 +294,7 @@ int iioClient::activate(int handle, bool enabled) {
* activated.
*/
int iioClient::batch(int handle, int32_t sampling_period_ns) {
if ((handle < 0) || (handle > MAX_SENSOR)) {
if ((handle < 0) || (handle >= MAX_SENSOR)) {
ALOGE("Warning: batch invalid handle sampling_time(%d) sensor hadle(%d) is out of range",
sampling_period_ns, handle);
return 0;
Expand Down
3 changes: 2 additions & 1 deletion sensors/2.0/iiohal_mediation_v2.0/iioClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ class iioClient {
*/
iioClient() {
sensorCount = 0;
active_sensor_count = 0;
ctx = NULL;
is_iioc_initialized = false;
static std::thread thread_object(iioThread, devlist);
Expand Down Expand Up @@ -102,7 +103,7 @@ class iioClient {
bool is_iioc_initialized;
int active_sensor_count;
struct iio_context *ctx;
struct iioclient_device devlist[MAX_SENSOR];
struct iioclient_device devlist[MAX_SENSOR]{};

/* member funcions*/
static void iioThread(struct iioclient_device *devlist);
Expand Down
13 changes: 0 additions & 13 deletions sensors/2.0/iiohal_mediation_v2.0/libiio_client/device.c
Original file line number Diff line number Diff line change
Expand Up @@ -943,10 +943,6 @@ static int read_each_attr(struct iio_device *dev, enum iio_attr_type type,
ret = (int) iio_device_buffer_attr_read(dev,
NULL, buf, 0x100000);
break;
default:
ret = -EINVAL;
count = 0;
break;
}

if (ret < 0)
Expand Down Expand Up @@ -1035,9 +1031,6 @@ static int write_each_attr(struct iio_device *dev, enum iio_attr_type type,
case IIO_ATTR_TYPE_BUFFER:
count = iio_device_get_buffer_attrs_count(dev);
break;
default:
ret = -EINVAL;
goto err_free_buf;
}

for (i = 0; i < count; i++) {
Expand All @@ -1053,9 +1046,6 @@ static int write_each_attr(struct iio_device *dev, enum iio_attr_type type,
case IIO_ATTR_TYPE_BUFFER:
attr = iio_device_get_buffer_attr(dev, i);
break;
default:
attr = NULL;
break;
}

ret = (int) cb(dev, attr, ptr + 4, len - 4, data);
Expand Down Expand Up @@ -1087,9 +1077,6 @@ static int write_each_attr(struct iio_device *dev, enum iio_attr_type type,
ret = (int) iio_device_buffer_attr_write_raw(dev,
NULL, buf, ptr - buf);
break;
default:
ret = -EINVAL;
break;
}

err_free_buf:
Expand Down
13 changes: 10 additions & 3 deletions sensors/2.0/iiohal_mediation_v2.0/libiio_client/iiod-client.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ static ssize_t iiod_client_read_integer(struct iiod_client *client,
void *desc, int *val)
{
unsigned int i;
char buf[1024], *ptr = NULL, *end;
char *ptr = NULL, *end;
char buf[1024] = "";
ssize_t ret;
int value;

Expand Down Expand Up @@ -187,7 +188,8 @@ int iiod_client_get_version(struct iiod_client *client, void *desc,
{
struct iio_context_pdata *pdata = client->pdata;
const struct iiod_client_ops *ops = client->ops;
char buf[256], *ptr = buf, *end;
char buf[256] = "";
char *ptr = buf, *end;
long maj, min;
int ret;

Expand Down Expand Up @@ -266,6 +268,9 @@ int iiod_client_get_trigger(struct iiod_client *client, void *desc,
for (i = 0; i < nb_devices; i++) {
struct iio_device *cur = iio_context_get_device(ctx, i);

if (cur == NULL)
continue;

if (iio_device_is_trigger(cur)) {
const char *name = iio_device_get_name(cur);

Expand Down Expand Up @@ -543,8 +548,10 @@ struct iio_context * iiod_client_create_context(
goto out_free_xml;

ctx = iio_create_xml_context_mem(xml, xml_len);
if (!ctx)
if (!ctx) {
ret = -errno;
goto out_free_xml;
}
if (client_id >= 0)
ctx->client_id = client_id;

Expand Down
2 changes: 1 addition & 1 deletion sensors/2.0/iiohal_mediation_v2.0/libiio_client/network.c
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,7 @@ static int discover_host(AvahiAddress *addr, uint16_t *port)
}
#endif /* HAVE_AVAHI */

// coverity[ -taint_source : arg-1 ]
static ssize_t network_recv(struct iio_network_io_context *io_ctx,
void *data, size_t len, int flags)
{
Expand All @@ -482,7 +483,6 @@ static ssize_t network_recv(struct iio_network_io_context *io_ctx,
ret = wait_cancellable(io_ctx, true);
if (ret < 0)
return ret;

ret = recv(io_ctx->fd, data, (int) len, flags);
if (ret == 0)
return -EPIPE;
Expand Down
Loading