-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Description
I found that there is a bug in the poll source code, the code as below:
static inline int register_events()
{
int events_registered = 0;
for (int ii = 0; ii < num_events; ii++) {
k_spinlock_key_t key;
uint32_t state;
key = k_spin_lock(&lock);
if (is_condition_met(&events[ii], &state)) {
set_event_ready(&events[ii], state);
poller->is_polling = false;
} else if (!just_check && poller->is_polling) {
int rc = register_event(&events[ii], poller);
**if (rc == 0) {
events_registered += 1;
} else {
__ASSERT(false, "unexpected return code\n");
}**
}
k_spin_unlock(&lock, key);
}
return events_registered;
}
register_event function code as below:
static inline int register_event()
{
switch (event->type) {
case K_POLL_TYPE_SEM_AVAILABLE:
__ASSERT(event->sem != NULL, "invalid semaphore\n");
add_event(&event->sem->poll_events, event, poller);
break;
case K_POLL_TYPE_DATA_AVAILABLE:
__ASSERT(event->queue != NULL, "invalid queue\n");
add_event(&event->queue->poll_events, event, poller);
break;
case K_POLL_TYPE_SIGNAL:
__ASSERT(event->signal != NULL, "invalid poll signal\n");
add_event(&event->signal->poll_events, event, poller);
break;
case K_POLL_TYPE_IGNORE:
/* nothing to do */
break;
default:
__ASSERT(false, "invalid event type\n");
break;
}
event->poller = poller;
**return 0;**
}
As you can see, rc is the return value of the function register_event. The judgment condition is whether rc is equal to 0. Analysis of the function register_event code shows that the function has only one return value 0, so if the function runs without an ASSERT error, the return value must be 0, so I think logic of this code is a bug and needs to be fixed.