]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
zloop: fix write pointer calculation in zloop_forget_cache
authorChristoph Hellwig <hch@lst.de>
Tue, 14 Apr 2026 08:17:46 +0000 (10:17 +0200)
committerJens Axboe <axboe@kernel.dk>
Wed, 15 Apr 2026 19:58:36 +0000 (13:58 -0600)
The write pointer is absolute and in sector units, so we need to
convert it to a relative byte address first.

Fixes: c505448748f7 ("zloop: forget write cache on force removal")
Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Damien Le Moal <dlemoal@kernel.org>
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Link: https://patch.msgid.link/20260414081811.549755-2-hch@lst.de
Signed-off-by: Jens Axboe <axboe@kernel.dk>
drivers/block/zloop.c

index 8baf642037fd825dfe391e9abcbbf9bc5a4f3822..672948d3653e3f1fd5abf7cb8f9e69a0d72d65b9 100644 (file)
@@ -1401,8 +1401,17 @@ static void zloop_forget_cache(struct zloop_device *zlo)
                                zlo->disk->part0, ret);
                        continue;
                }
-               if (old_wp < zone->wp)
-                       zloop_truncate(file, old_wp);
+
+               if (old_wp > zone->wp)
+                       continue;
+               /*
+                * This should not happen, if we recored a full zone, it can't
+                * be active.
+                */
+               if (WARN_ON_ONCE(old_wp == ULLONG_MAX))
+                       continue;
+
+               zloop_truncate(file, (old_wp - zone->start) << SECTOR_SHIFT);
        }
 }