Skip to content

Commit e552a59

Browse files
committed
Squashfs: add missing block release on error condition
squashfs_read_metadata forgets to release the cache block if an error has occurred. Signed-off-by: Phillip Lougher <phillip@squashfs.org.uk>
1 parent 5f0a6e2 commit e552a59

1 file changed

Lines changed: 13 additions & 6 deletions

File tree

‎fs/squashfs/cache.c‎

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -332,17 +332,20 @@ int squashfs_read_metadata(struct super_block *sb, void *buffer,
332332
u64 *block, int *offset, int length)
333333
{
334334
struct squashfs_sb_info *msblk = sb->s_fs_info;
335-
int bytes, copied = length;
335+
int bytes, res = length;
336336
struct squashfs_cache_entry *entry;
337337

338338
TRACE("Entered squashfs_read_metadata [%llx:%x]\n", *block, *offset);
339339

340340
while (length) {
341341
entry = squashfs_cache_get(sb, msblk->block_cache, *block, 0);
342-
if (entry->error)
343-
return entry->error;
344-
else if (*offset >= entry->length)
345-
return -EIO;
342+
if (entry->error) {
343+
res = entry->error;
344+
goto error;
345+
} else if (*offset >= entry->length) {
346+
res = -EIO;
347+
goto error;
348+
}
346349

347350
bytes = squashfs_copy_data(buffer, entry, *offset, length);
348351
if (buffer)
@@ -358,7 +361,11 @@ int squashfs_read_metadata(struct super_block *sb, void *buffer,
358361
squashfs_cache_put(entry);
359362
}
360363

361-
return copied;
364+
return res;
365+
366+
error:
367+
squashfs_cache_put(entry);
368+
return res;
362369
}
363370

364371

0 commit comments

Comments
 (0)