Skip to content

Missing error check of function sensor_sample_fetch() and sensor_channel_get() #29945

@Hxinrong

Description

@Hxinrong

Hi,
As described in the API documentation, function sensor_sample_fetch() fetches a sample from the sensor and stores it in an internal driver buffer, returns 0 if successful, and returns negative errno code if failure. And the return value of function sensor_channel_get() has the same format. However, as shown in the following code, two missing error checks take place, sensor_sample_fetch() and sensor_channel_get().

sensor_sample_fetch(dev);
sensor_channel_get(dev, SENSOR_CHAN_AMBIENT_TEMP, &temp);

And, I see, in the same file, the return values of the two functions are checked. See the following code, for example.

rc = sensor_sample_fetch(dev);
if (rc != 0) {
printf("sensor_sample_fetch error: %d\n", rc);
break;
}
rc = sensor_channel_get(dev, SENSOR_CHAN_AMBIENT_TEMP, &temp);
if (rc != 0) {
printf("sensor_channel_get error: %d\n", rc);
break;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    StalebugThe issue is a bug, or the PR is fixing a bugpriority: lowLow impact/importance bug

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions