Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: Niklas Haas via ffmpeg-devel <ffmpeg-devel@ffmpeg.org>
To: ffmpeg-devel@ffmpeg.org
Cc: Niklas Haas <code@ffmpeg.org>
Subject: [FFmpeg-devel] [PATCH] fftools: silence coverity race condition warning (PR #20638)
Date: Wed, 01 Oct 2025 16:21:05 -0000
Message-ID: <175933566584.69.1489205351262994685@bf249f23a2c8> (raw)

PR #20638 opened by Niklas Haas (haasn)
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20638
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20638.patch

Avoids the following Coverity warning:

> CID 1666425:         Concurrent data access violations  (MISSING_LOCK)
> Accessing "fg->best_input" without holding lock "Scheduler.schedule_lock".
> Elsewhere, "SchFilterGraph.best_input" is written to with
> "Scheduler.schedule_lock" held 2 out of 2 times (2 of these accesses
> strongly imply that it is necessary).

I'm pretty sure this is a false positive, as `fg->best_input` is only ever
written by the filter thread - so there's zero risk of concurrent write with
this read. However, coverity seems to not be aware of this fact. To be honest,
I'm not sure why it didn't trigger before, but possibly because the only
other writing location before was in the same function, so maybe it was
smart enough to understand that it can't race with itself.

A mutex is nowehere near expensive enough that this once-per-frame extra
lock/unlock is going to be in any way measurable.


>From 8248d22720e36edf1fc04269e047c5218526f14d Mon Sep 17 00:00:00 2001
From: Niklas Haas <git@haasn.dev>
Date: Wed, 1 Oct 2025 18:15:48 +0200
Subject: [PATCH] fftools: silence coverity race condition warning

Avoids the following Coverity warning:

> CID 1666425:         Concurrent data access violations  (MISSING_LOCK)
> Accessing "fg->best_input" without holding lock "Scheduler.schedule_lock".
> Elsewhere, "SchFilterGraph.best_input" is written to with
> "Scheduler.schedule_lock" held 2 out of 2 times (2 of these accesses
> strongly imply that it is necessary).

I'm pretty sure this is a false positive, as `fg->best_input` is only ever
written by the filter thread - so there's zero risk of concurrent write with
this read. However, coverity seems to not be aware of this fact. To be honest,
I'm not sure why it didn't trigger before, but possibly because the only
other writing location before was in the same function, so maybe it was
smart enough to understand that it can't race with itself.

A mutex is nowehere near expensive enough that this once-per-frame extra
lock/unlock is going to be in any way measurable.
---
 fftools/ffmpeg_sched.c | 13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)

diff --git a/fftools/ffmpeg_sched.c b/fftools/ffmpeg_sched.c
index d08f4a061d..5c52779588 100644
--- a/fftools/ffmpeg_sched.c
+++ b/fftools/ffmpeg_sched.c
@@ -2445,19 +2445,16 @@ int sch_filter_receive(Scheduler *sch, unsigned fg_idx,
 
     av_assert0(*in_idx <= fg->nb_inputs);
 
-    // update scheduling to account for desired input stream, if it changed
-    //
-    // this check needs no locking because only the filtering thread
-    // updates this value
-    if (*in_idx != fg->best_input) {
-        pthread_mutex_lock(&sch->schedule_lock);
+    pthread_mutex_lock(&sch->schedule_lock);
 
+    // update scheduling to account for desired input stream, if it changed
+    if (*in_idx != fg->best_input) {
         fg->best_input = *in_idx;
         schedule_update_locked(sch);
-
-        pthread_mutex_unlock(&sch->schedule_lock);
     }
 
+    pthread_mutex_unlock(&sch->schedule_lock);
+
     if (*in_idx == fg->nb_inputs) {
         int terminate = waiter_wait(sch, &fg->waiter);
         return terminate ? AVERROR_EOF : AVERROR(EAGAIN);
-- 
2.49.1

_______________________________________________
ffmpeg-devel mailing list -- ffmpeg-devel@ffmpeg.org
To unsubscribe send an email to ffmpeg-devel-leave@ffmpeg.org

                 reply	other threads:[~2025-10-01 16:21 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=175933566584.69.1489205351262994685@bf249f23a2c8 \
    --to=ffmpeg-devel@ffmpeg.org \
    --cc=code@ffmpeg.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror http://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ http://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git