Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PATCH] fftools: silence coverity race condition warning (PR #20638)
@ 2025-10-01 16:21 Niklas Haas via ffmpeg-devel
  0 siblings, 0 replies; only message in thread
From: Niklas Haas via ffmpeg-devel @ 2025-10-01 16:21 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Niklas Haas

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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2025-10-01 16:21 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-10-01 16:21 [FFmpeg-devel] [PATCH] fftools: silence coverity race condition warning (PR #20638) Niklas Haas via ffmpeg-devel

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