]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
dm array: fix unreleased btree blocks on closing a faulty array cursor
authorMing-Hung Tsai <mtsai@redhat.com>
Thu, 5 Dec 2024 11:41:52 +0000 (19:41 +0800)
committerMike Snitzer <snitzer@kernel.org>
Fri, 13 Dec 2024 13:37:39 +0000 (08:37 -0500)
The cached block pointer in dm_array_cursor might be NULL if it reaches
an unreadable array block, or the array is empty. Therefore,
dm_array_cursor_end() should call dm_btree_cursor_end() unconditionally,
to prevent leaving unreleased btree blocks.

This fix can be verified using the "array_cursor/iterate/empty" test
in dm-unit:
  dm-unit run /pdata/array_cursor/iterate/empty --kernel-dir <KERNEL_DIR>

Signed-off-by: Ming-Hung Tsai <mtsai@redhat.com>
Fixes: fdd1315aa5f0 ("dm array: introduce cursor api")
Reviewed-by: Joe Thornber <thornber@redhat.com>
Signed-off-by: Mike Snitzer <snitzer@kernel.org>
drivers/md/persistent-data/dm-array.c

index 4866ff56125f5abca14f00b56083252749a8c6d3..0850dfdffc8cea408f91c89cee0ab6caf2618283 100644 (file)
@@ -960,10 +960,10 @@ EXPORT_SYMBOL_GPL(dm_array_cursor_begin);
 
 void dm_array_cursor_end(struct dm_array_cursor *c)
 {
-       if (c->block) {
+       if (c->block)
                unlock_ablock(c->info, c->block);
-               dm_btree_cursor_end(&c->cursor);
-       }
+
+       dm_btree_cursor_end(&c->cursor);
 }
 EXPORT_SYMBOL_GPL(dm_array_cursor_end);