<p></p>
<p><b>@benpicco</b> commented on this pull request.</p>

<p>CI still has some <a href="https://github.com/RIOT-OS/RIOT/pull/15549/files">style nits</a> so I added my own</p><hr>

<p>In <a href="https://github.com/RIOT-OS/RIOT/pull/15549#discussion_r662327323">sys/net/dsm/dsm.c</a>:</p>
<pre style='color:#555'>> +        if (_sessions[i].state == SESSION_STATE_ESTABLISHED
+                && _sessions[i].sock == sock) {
+            if (session_slot == NULL
+                || session_slot->last_used_sec > _sessions[i].last_used_sec)
+            {
+                session_slot = &_sessions[i];
+            }
+        }
</pre>
<p>style nit: it's possible to reduce the level of nesting here</p>

⬇️ Suggested change
<pre style="color: #555">-        if (_sessions[i].state == SESSION_STATE_ESTABLISHED
-                && _sessions[i].sock == sock) {
-            if (session_slot == NULL
-                || session_slot->last_used_sec > _sessions[i].last_used_sec)
-            {
-                session_slot = &_sessions[i];
-            }
-        }
+        if (_sessions[i].state != SESSION_STATE_ESTABLISHED) {
+            continue;
+        }
+        if (_sessions[i].sock != sock) {
+            continue;
+        }
+
+        if (session_slot == NULL ||
+            session_slot->last_used_sec > _sessions[i].last_used_sec) {
+            session_slot = &_sessions[i];
+        }
</pre>


<hr>

<p>In <a href="https://github.com/RIOT-OS/RIOT/pull/15549#discussion_r662330148">sys/net/dsm/dsm.c</a>:</p>
<pre style='color:#555'>> +void dsm_init(void)
+{
+    mutex_init(&_lock);
+    _available_slots = DTLS_PEER_MAX;
+}
+
+dsm_state_t dsm_store(sock_dtls_t *sock, sock_dtls_session_t *session,
+                      dsm_state_t new_state, bool restore)
+{
+    sock_udp_ep_t ep;
+    dsm_session_t *session_slot = NULL;
+    dsm_state_t prev_state = NO_SPACE;
+    mutex_lock(&_lock);
+
+    ssize_t res = _find_session(sock, session, &session_slot);
+    if (res != -1) {
</pre>

⬇️ Suggested change
<pre style="color: #555">-    if (res != -1) {
+    if (res >= 0) {
</pre>

<p>adds a bit of future-proofing should <code>_find_session</code> ever get refactored to emit more error code</p>
<p>or even better</p>

⬇️ Suggested change
<pre style="color: #555">-    if (res != -1) {
+    if (res < 0) {
+        DEBUG("dsm: no space for session to store\n");
+        goto out;
+    }
</pre>

<p>and we can reduce the level of nesting</p>

<hr>

<p>In <a href="https://github.com/RIOT-OS/RIOT/pull/15549#discussion_r662332097">sys/net/application_layer/gcoap/gcoap.c</a>:</p>
<pre style='color:#555'>> +        if (timeout != SOCK_NO_TIMEOUT) {
+            uint32_t diff = (xtimer_now_usec() - start);
+            timeout = (diff > timeout) ? 0: timeout - diff;
+            is_timed_out = (res < 0) || (timeout == 0);
+        }
</pre>
<p>Can you add a comment about this?<br>
Future readers won't be hunting down the PR comment <g-emoji class="g-emoji" alias="wink" fallback-src="https://github.githubassets.com/images/icons/emoji/unicode/1f609.png">😉</g-emoji></p>

<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">—<br />You are receiving this because you are subscribed to this thread.<br />Reply to this email directly, <a href="https://github.com/RIOT-OS/RIOT/pull/15549#pullrequestreview-697297851">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/ABE7WYHRVRW3POVBG77QV33TVR2WZANCNFSM4UL2PR7Q">unsubscribe</a>.<img src="https://github.com/notifications/beacon/ABE7WYFHCP5NU3KVYTNHY63TVR2WZA5CNFSM4UL2PR72YY3PNVWWK3TUL52HS4DFWFIHK3DMKJSXC5LFON2FEZLWNFSXPKTDN5WW2ZLOORPWSZGOFGH6XOY.gif" height="1" width="1" alt="" /></p>
<script type="application/ld+json">[
{
"@context": "http://schema.org",
"@type": "EmailMessage",
"potentialAction": {
"@type": "ViewAction",
"target": "https://github.com/RIOT-OS/RIOT/pull/15549#pullrequestreview-697297851",
"url": "https://github.com/RIOT-OS/RIOT/pull/15549#pullrequestreview-697297851",
"name": "View Pull Request"
},
"description": "View this Pull Request on GitHub",
"publisher": {
"@type": "Organization",
"name": "GitHub",
"url": "https://github.com"
}
}
]</script>