From 1b077c300aa27ca88cc7bc1c5b5671761a7d4d85 Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Thu, 17 Jul 2025 14:36:02 -0400 Subject: [PATCH] MT#55283 use auto lock in a few more places Change-Id: Ibf34fa6e8cdcbf122e548475ba086101a6757a66 --- daemon/call.c | 8 +++----- daemon/media_socket.c | 30 ++++++++++-------------------- 2 files changed, 13 insertions(+), 25 deletions(-) diff --git a/daemon/call.c b/daemon/call.c index b2d9a3bae..c9b63b55e 100644 --- a/daemon/call.c +++ b/daemon/call.c @@ -185,7 +185,8 @@ static void call_timer_iterator(call_t *c, struct iterator_helper *hlp) { timestamp = packet_stream_last_packet(ps); if (!ps->media) - goto next; + continue; + sfd = ps->selected_sfd; if (!sfd) goto no_sfd; @@ -215,7 +216,7 @@ static void call_timer_iterator(call_t *c, struct iterator_helper *hlp) { no_sfd: if (good) - goto next; + continue; check = atomic_get_na(&rtpe_config.timeout_us); tmp_t_reason = TIMEOUT; @@ -230,9 +231,6 @@ no_sfd: if (timestamp > rtpe_now || rtpe_now - timestamp < check) good = true; - -next: - ; } for (__auto_type it = c->medias.head; it; it = it->next) { diff --git a/daemon/media_socket.c b/daemon/media_socket.c index 1beff5541..c4a2411de 100644 --- a/daemon/media_socket.c +++ b/daemon/media_socket.c @@ -2190,7 +2190,7 @@ static int media_demux_protocols(struct packet_handler_ctx *phc) { #if RTP_LOOP_PROTECT // returns: 0 = ok, proceed; -1 = duplicate detected, drop packet static int media_loop_detect(struct packet_handler_ctx *phc) { - mutex_lock(&phc->mp.stream->in_lock); + LOCK(&phc->mp.stream->in_lock); for (int i = 0; i < RTP_LOOP_PACKETS; i++) { if (phc->mp.stream->lp_buf[i].len != phc->s.len) @@ -2204,12 +2204,11 @@ static int media_loop_detect(struct packet_handler_ctx *phc) { "to avoid potential loop", RTP_LOOP_MAX_COUNT, FMT_M(endpoint_print_buf(&phc->mp.fsin))); - mutex_unlock(&phc->mp.stream->in_lock); return -1; } phc->mp.stream->lp_count++; - goto loop_ok; + return 0; } /* not a dupe */ @@ -2217,8 +2216,6 @@ static int media_loop_detect(struct packet_handler_ctx *phc) { phc->mp.stream->lp_buf[phc->mp.stream->lp_idx].len = phc->s.len; memcpy(phc->mp.stream->lp_buf[phc->mp.stream->lp_idx].buf, phc->s.s, MIN(phc->s.len, RTP_LOOP_PROTECT)); phc->mp.stream->lp_idx = (phc->mp.stream->lp_idx + 1) % RTP_LOOP_PACKETS; -loop_ok: - mutex_unlock(&phc->mp.stream->in_lock); return 0; } @@ -2331,7 +2328,7 @@ static void media_packet_rtp_out(struct packet_handler_ctx *phc, struct sink_han static int media_packet_decrypt(struct packet_handler_ctx *phc) { - mutex_lock(&phc->in_srtp->in_lock); + LOCK(&phc->in_srtp->in_lock); struct sink_handler *first_sh = phc->sinks->length ? phc->sinks->head->data : NULL; const struct streamhandler *sh = __determine_handler(phc->in_srtp, first_sh); @@ -2352,8 +2349,6 @@ static int media_packet_decrypt(struct packet_handler_ctx *phc) phc->mp.payload.len -= ori_s.len - phc->s.len; } - mutex_unlock(&phc->in_srtp->in_lock); - if (ret == 1) { phc->update = true; ret = 0; @@ -2362,7 +2357,7 @@ static int media_packet_decrypt(struct packet_handler_ctx *phc) } static void media_packet_set_encrypt(struct packet_handler_ctx *phc, struct sink_handler *sh) { - mutex_lock(&phc->in_srtp->in_lock); + LOCK(&phc->in_srtp->in_lock); __determine_handler(phc->in_srtp, sh); // XXX use an array with index instead of if/else @@ -2372,7 +2367,6 @@ static void media_packet_set_encrypt(struct packet_handler_ctx *phc, struct sink phc->encrypt_func = sh->handler->out->rtcp_crypt; phc->rtcp_filter = sh->handler->in->rtcp_filter; } - mutex_unlock(&phc->in_srtp->in_lock); } int media_packet_encrypt(rewrite_func encrypt_func, struct packet_stream *out, struct media_packet *mp) { @@ -2417,7 +2411,7 @@ static bool media_packet_address_check(struct packet_handler_ctx *phc) { bool ret = false; - mutex_lock(&phc->mp.stream->in_lock); + LOCK(&phc->mp.stream->in_lock); /* we're OK to (potentially) use the source address of this packet as destination * in the other direction. */ @@ -2425,11 +2419,11 @@ static bool media_packet_address_check(struct packet_handler_ctx *phc) if (!PS_ISSET(phc->mp.stream, FILLED)) { __C_DBG("stream %s:%d not FILLED", sockaddr_print_buf(&phc->mp.stream->endpoint.address), phc->mp.stream->endpoint.port); - goto out; + return false; } if (!MEDIA_ISSET(phc->mp.media, PUBLIC)) { __C_DBG("media not answered"); - goto out; + return false; } // GH #697 - apparent Asterisk bug where it sends stray RTCP to the RTP port. @@ -2441,7 +2435,7 @@ static bool media_packet_address_check(struct packet_handler_ctx *phc) ilog(LOG_DEBUG | LOG_FLAG_LIMIT, "Ignoring stray RTCP packet from %s%s%s for " "peer address confirmation purposes", FMT_M(endpoint_print_buf(&phc->mp.fsin))); - goto out; + return false; } } @@ -2496,7 +2490,7 @@ static bool media_packet_address_check(struct packet_handler_ctx *phc) } } phc->kernelize = true; - goto out; + return ret; } /* wait at least 3 seconds after last signal before committing to a particular @@ -2553,8 +2547,7 @@ static bool media_packet_address_check(struct packet_handler_ctx *phc) FMT_M(endpoint_print_buf(use_endpoint_confirm))); atomic64_inc_na(&phc->mp.stream->stats_in->errors); atomic64_inc_na(&phc->mp.sfd->local_intf->stats->in.errors); - ret = true; - goto out; + return true; } } @@ -2613,9 +2606,6 @@ update_addr: } } -out: - mutex_unlock(&phc->mp.stream->in_lock); - return ret; }