Skip to content

Commit de72fae

Browse files
jukkarnashif
authored andcommitted
net: tcp2: slist API is not thread safe so use locking
Make sure we lock when accessing the slist, as it is not a thread safe API. Signed-off-by: Jukka Rissanen <[email protected]>
1 parent a5f9520 commit de72fae

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

subsys/net/ip/tcp2.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ static void tcp_send_queue_flush(struct tcp *conn)
339339

340340
k_delayed_work_cancel(&conn->send_timer);
341341

342-
while ((pkt = tcp_slist(&conn->send_queue, get,
342+
while ((pkt = tcp_slist(conn, &conn->send_queue, get,
343343
struct net_pkt, next))) {
344344
tcp_pkt_unref(pkt);
345345
}
@@ -432,7 +432,7 @@ static bool tcp_send_process_no_lock(struct tcp *conn)
432432
bool unref = false;
433433
struct net_pkt *pkt;
434434

435-
pkt = tcp_slist(&conn->send_queue, peek_head,
435+
pkt = tcp_slist(conn, &conn->send_queue, peek_head,
436436
struct net_pkt, next);
437437
if (!pkt) {
438438
goto out;
@@ -458,8 +458,9 @@ static bool tcp_send_process_no_lock(struct tcp *conn)
458458
bool forget = ACK == fl || PSH == fl || (ACK | PSH) == fl ||
459459
RST & fl;
460460

461-
pkt = forget ? tcp_slist(&conn->send_queue, get, struct net_pkt,
462-
next) : tcp_pkt_clone(pkt);
461+
pkt = forget ? tcp_slist(conn, &conn->send_queue, get,
462+
struct net_pkt, next) :
463+
tcp_pkt_clone(pkt);
463464
if (!pkt) {
464465
NET_ERR("net_pkt alloc failure");
465466
goto out;
@@ -507,7 +508,7 @@ static void tcp_send_timer_cancel(struct tcp *conn)
507508
k_delayed_work_cancel(&conn->send_timer);
508509

509510
{
510-
struct net_pkt *pkt = tcp_slist(&conn->send_queue, get,
511+
struct net_pkt *pkt = tcp_slist(conn, &conn->send_queue, get,
511512
struct net_pkt, next);
512513
if (pkt) {
513514
NET_DBG("%s", log_strdup(tcp_th(pkt)));

subsys/net/ip/tcp2_priv.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,16 @@
2020
#define th_flags(_x) UNALIGNED_GET(&(_x)->th_flags)
2121
#define th_win(_x) UNALIGNED_GET(&(_x)->th_win)
2222

23-
#define tcp_slist(_slist, _op, _type, _link) \
23+
#define tcp_slist(_conn, _slist, _op, _type, _link) \
2424
({ \
25+
k_mutex_lock(&conn->lock, K_FOREVER); \
26+
\
2527
sys_snode_t *_node = sys_slist_##_op(_slist); \
2628
\
2729
_type * _x = _node ? CONTAINER_OF(_node, _type, _link) : NULL; \
2830
\
31+
k_mutex_unlock(&conn->lock); \
32+
\
2933
_x; \
3034
})
3135

0 commit comments

Comments
 (0)