[PATCH] bcachefs: Fix missing assignment of minimum element before min_heap_pop()

From: Kuan-Wei Chiu
Date: Sun Jun 02 2024 - 13:48:42 EST


When replacing the heap_pop() macro with min_heap_pop(), the original
heap_pop() macro would store the minimum element into 'ret'. However,
after replacing it with min_heap_pop(), the code incorrectly failed to
store the minimum element into 'ret' before deleting it.

Fix the issue by using min_heap_peek() to assign the minimum element to
'ret' before calling min_heap_pop() to remove the minimum element.

Reported-by: kernel test robot <lkp@xxxxxxxxx>
Closes: https://lore.kernel.org/oe-kbuild-all/202406030001.jwsq6DZp-lkp@xxxxxxxxx/
Signed-off-by: Kuan-Wei Chiu <visitorckw@xxxxxxxxx>
---
fs/bcachefs/clock.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/fs/bcachefs/clock.c b/fs/bcachefs/clock.c
index 3ec64fe6a064..18fab9c44b1b 100644
--- a/fs/bcachefs/clock.c
+++ b/fs/bcachefs/clock.c
@@ -156,8 +156,10 @@ static struct io_timer *get_expired_timer(struct io_clock *clock,
spin_lock(&clock->timer_lock);

if (clock->timers.nr &&
- time_after_eq(now, clock->timers.data[0]->expire))
+ time_after_eq(now, clock->timers.data[0]->expire)) {
+ ret = *min_heap_peek(&clock->timers);
min_heap_pop(&clock->timers, &callbacks, NULL);
+ }

spin_unlock(&clock->timer_lock);

--
2.34.1