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

Missing error check of function sensor_trigger_set() #30189

Closed
Hxinrong opened this issue Nov 23, 2020 · 2 comments · Fixed by #31884
Closed

Missing error check of function sensor_trigger_set() #30189

Hxinrong opened this issue Nov 23, 2020 · 2 comments · Fixed by #31884
Assignees
Labels
area: Samples Samples area: Sensors Sensors bug The issue is a bug, or the PR is fixing a bug priority: low Low impact/importance bug

Comments

@Hxinrong
Copy link
Contributor

Hi,
As described in the project API documentation, function sensor_trigger_set() is used to activate a sensor's trigger and set the trigger handler. It returns 0 if successful, negative errno code if failure. But as shown in the following codes, the return value is not error checked before it is assigned by another function.

if (rc == 0) {
rc = sensor_trigger_set(dev, &trig, trigger_handler);
}
printf("Alert outside %d..%d %%RH got %d\n", lo_thr.val1,
hi_thr.val1, rc);
#endif
while (true) {
struct sensor_value temp, hum;
rc = sensor_sample_fetch(dev);

But, the return values of the function from other call sites are all checked. See the following code,

rc = sensor_trigger_set(sensor, &trig, trigger_handler);
if (rc != 0) {
printf("Failed to set trigger: %d\n", rc);
return;
}

@Hxinrong Hxinrong added the bug The issue is a bug, or the PR is fixing a bug label Nov 23, 2020
@de-nordic de-nordic added the area: Samples Samples label Nov 23, 2020
@carlescufi carlescufi added the area: Sensors Sensors label Nov 25, 2020
@nashif nashif added the priority: low Low impact/importance bug label Dec 1, 2020
Hxinrong added a commit to Hxinrong/zephyr that referenced this issue Dec 22, 2020
Validate that sensor_trigger_set() is on success.

Fixes zephyrproject-rtos#30189

Signed-off-by: Xinrong Han <[email protected]>
@github-actions
Copy link

This issue has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this issue will automatically be closed in 14 days. Note, that you can always re-open a closed issue at any time.

@github-actions github-actions bot added the Stale label Jan 31, 2021
@MaureenHelm
Copy link
Member

@pabigot can you have a look at this? it looks like you originally added this sample application

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Samples Samples area: Sensors Sensors bug The issue is a bug, or the PR is fixing a bug priority: low Low impact/importance bug
Projects
None yet
7 participants