dm-cache: fix ending a cursor that never began
Mikulas Patocka
maintainerPATCH 1/1 dm-cache: fix ending a cursor that never began
If dm_bitset_cursor_begin fails, dm_array_cursor_end(&cmd->hint_cursor) is called. However, cmd->hint_cursor was only initialized if the variable hints_valid is true. Thus, we must also destroy hint_cursor only if hints_valid is true.
--- drivers/md/dm-cache-metadata.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/md/dm-cache-metadata.c +2 -1
@@ -1433,7 +1433,8 @@ static int __load_mappings(struct dm_cacfrom_cblock (cmd->cache_blocks), &cmd->dirty_cursor);if (r) { -dm_array_cursor_end (&cmd->hint_cursor); +if (hints_valid) +dm_array_cursor_end (&cmd->hint_cursor);dm_array_cursor_end (&cmd->mapping_cursor);return r; }
Quoted 22 lines · Mikulas Patocka
If
dm_bitset_cursor_beginfails,dm_array_cursor_end(&cmd->hint_cursor)is called. However,cmd->hint_cursorwas only initialized if the variablehints_validis true. Thus, we must also destroyhint_cursoronly ifhints_validis true.Signed-off-by Mikulas Patocka <[email protected]>Assisted-by Claude:claude-opus-5Fixes 629d0a8a1a10 ("dm cache metadata: add "metadata2" feature")--- drivers/md/dm-cache-metadata.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)Index:
linux-2.6/drivers/md/dm-cache-metadata.c
===================================================================
drivers/md/dm-cache-metadata.c static int __load_mappings(struct dm_cac · line 1440
Quoted 9 lines
drivers/md/dm-cache-metadata.c +2
-1@@ -1433,7 +1433,8 @@ static int __load_mappings(struct dm_cacfrom_cblock (cmd->cache_blocks), &cmd->dirty_cursor);if (r) { -dm_array_cursor_end (&cmd->hint_cursor); +if (hints_valid) +dm_array_cursor_end (&cmd->hint_cursor);dm_array_cursor_end (&cmd->mapping_cursor);return r; }
This corner case occurs when the metadata is not clean and the dirty bitset gets corrupted. Although calling dm_array_cursor_end() is safe because hint_cursor is zero-initialized during dm_cache_metadata allocation, adding an explicit check is a reasonable safeguard.