diff options
author | Phillip Lougher <phillip@lougher.demon.co.uk> | 2011-05-19 21:26:43 -0400 |
---|---|---|
committer | Phillip Lougher <phillip@lougher.demon.co.uk> | 2011-05-25 13:21:31 -0400 |
commit | 82de647e1f81fd89afc48608d889dd3b33cb8983 (patch) | |
tree | 847b7b40ed273eaa755c27bef6b1a20d201273c2 /fs/squashfs/cache.c | |
parent | 117a91e0f25fd7698e20ac3dfa62086be3dc82a3 (diff) |
Squashfs: move table allocation into squashfs_read_table()
This eliminates a lot of duplicate code.
Signed-off-by: Phillip Lougher <phillip@lougher.demon.co.uk>
Diffstat (limited to 'fs/squashfs/cache.c')
-rw-r--r-- | fs/squashfs/cache.c | 29 |
1 files changed, 23 insertions, 6 deletions
diff --git a/fs/squashfs/cache.c b/fs/squashfs/cache.c index 26b15ae34d6f..20c8df1b7efc 100644 --- a/fs/squashfs/cache.c +++ b/fs/squashfs/cache.c | |||
@@ -393,19 +393,36 @@ struct squashfs_cache_entry *squashfs_get_datablock(struct super_block *sb, | |||
393 | /* | 393 | /* |
394 | * Read a filesystem table (uncompressed sequence of bytes) from disk | 394 | * Read a filesystem table (uncompressed sequence of bytes) from disk |
395 | */ | 395 | */ |
396 | int squashfs_read_table(struct super_block *sb, void *buffer, u64 block, | 396 | void *squashfs_read_table(struct super_block *sb, u64 block, int length) |
397 | int length) | ||
398 | { | 397 | { |
399 | int pages = (length + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT; | 398 | int pages = (length + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT; |
400 | int i, res; | 399 | int i, res; |
401 | void **data = kcalloc(pages, sizeof(void *), GFP_KERNEL); | 400 | void *table, *buffer, **data; |
402 | if (data == NULL) | 401 | |
403 | return -ENOMEM; | 402 | table = buffer = kmalloc(length, GFP_KERNEL); |
403 | if (table == NULL) | ||
404 | return ERR_PTR(-ENOMEM); | ||
405 | |||
406 | data = kcalloc(pages, sizeof(void *), GFP_KERNEL); | ||
407 | if (data == NULL) { | ||
408 | res = -ENOMEM; | ||
409 | goto failed; | ||
410 | } | ||
404 | 411 | ||
405 | for (i = 0; i < pages; i++, buffer += PAGE_CACHE_SIZE) | 412 | for (i = 0; i < pages; i++, buffer += PAGE_CACHE_SIZE) |
406 | data[i] = buffer; | 413 | data[i] = buffer; |
414 | |||
407 | res = squashfs_read_data(sb, data, block, length | | 415 | res = squashfs_read_data(sb, data, block, length | |
408 | SQUASHFS_COMPRESSED_BIT_BLOCK, NULL, length, pages); | 416 | SQUASHFS_COMPRESSED_BIT_BLOCK, NULL, length, pages); |
417 | |||
409 | kfree(data); | 418 | kfree(data); |
410 | return res; | 419 | |
420 | if (res < 0) | ||
421 | goto failed; | ||
422 | |||
423 | return table; | ||
424 | |||
425 | failed: | ||
426 | kfree(table); | ||
427 | return ERR_PTR(res); | ||
411 | } | 428 | } |