Hello
In NCS 2.6.2 (v3.5.99-ncs1-2), lorawan_register_downlink_callback() directly calls sys_slist_append(&dl_callbacks, &cb->node) with no duplicate check.
My concern is that sys_slist_t is intrusive and each sys_snode_t has only one next pointer: sys_slist_append() first sets node->next = NULL, then does list->tail->next = node; therefore, if the same node is already the tail, appending it again appears to result in node->next = node, creating a self-referencing list and potentially an infinite traversal.
For example, if the list is A -> NULL and A is appended again, the result seems to become A -> A -> ...; if the node is already somewhere inside a longer list, clearing its next before re-appending could also break the existing chain.
I also noticed other Zephyr users of sys_slist_append() explicitly check whether a node is already registered or remove it before re-appending, which seems to support the idea that duplicate insertion is not expected.
Is the intended behavior that a sys_snode_t should never be appended while it is already linked? I started digging into this while investigating a crash in the LorarWAN subsystem. Found that my code in some cases called lorawan_register_downlink_callback() multiple times. That API directly calls sys_slist_append(&dl_callbacks, &cb->node) without checking if the node is already on the list. So the theory is that the crash was caused by traversing a corrupt list. But then the question is,why wasn't this noticed before - sys_slist_append is called throughout the SDK code and I couldn't find anything in the forums regarding this
Thank you
Andy