]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
bcachefs: Fix racy use of jiffies
authorKent Overstreet <kent.overstreet@linux.dev>
Wed, 9 Oct 2024 20:53:59 +0000 (16:53 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Sat, 21 Dec 2024 06:36:13 +0000 (01:36 -0500)
Calculate the timeout, then check if it's positive before calling
schedule_timeout().

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/journal_reclaim.c

index ace291f175dd6b0f45d6fcabd3a30391b7a47911..3d8fc2642425ec8461e703646ac417a4dd4377c6 100644 (file)
@@ -758,10 +758,12 @@ static int bch2_journal_reclaim_thread(void *arg)
                        journal_empty = fifo_empty(&j->pin);
                        spin_unlock(&j->lock);
 
+                       long timeout = j->next_reclaim - jiffies;
+
                        if (journal_empty)
                                schedule();
-                       else if (time_after(j->next_reclaim, jiffies))
-                               schedule_timeout(j->next_reclaim - jiffies);
+                       else if (timeout > 0)
+                               schedule_timeout(timeout);
                        else
                                break;
                }