Squashfs: allocate entries with cache
PATCH 1/1 Squashfs: allocate entries with cache
Use a flexible array member with kzalloc_flex to combine allocations and simplify code slightly.
Moved struct as flexible array members require full definitions.
Signed-off-by Rosen Penev <[email protected]>
--- fs/squashfs/cache.c | 13 +++---------- fs/squashfs/squashfs_fs_sb.h | 28 ++++++++++++++-------------- 2 files changed, 17 insertions(+), 24 deletions(-)
fs/squashfs/cache.c +3 -10
@@ -210,7 +210,6 @@ void squashfs_cache_delete(struct squashfs_cache *cache)kfree (cache->entry[i].actor); } -kfree (cache->entry);kfree (cache); }
@@ -229,22 +228,16 @@ struct squashfs_cache *squashfs_cache_init(char *name, int entries,if (entries ==0 )return NULL ; - cache =kzalloc_obj (*cache); + cache =kzalloc_flex (*cache, entry, entries);if (cache ==NULL ) {ERROR ("Failed to allocate %s cache\n" , name);return ERR_PTR (-ENOMEM ); } - cache->entry =kzalloc_objs (*(cache->entry), entries); -if (cache->entry ==NULL ) { -ERROR ("Failed to allocate %s cache\n" , name); - goto cleanup; - } - + cache->entries = entries; + cache->unused = entries; cache->curr_blk =0 ; cache->next_blk =0 ; - cache->unused = entries; - cache->entries = entries; cache->block_size = block_size; cache->pages = block_size >>PAGE_SHIFT ; cache->pages = cache->pages ? cache->pages :1 ;
fs/squashfs/squashfs_fs_sb.h +14 -14
@@ -12,20 +12,6 @@#include "squashfs_fs.h" -struct squashfs_cache { -char *name; -int entries; -int curr_blk; -int next_blk; -int num_waiters; -int unused; -int block_size; -int pages; -spinlock_t lock; -wait_queue_head_t wait_queue; -struct squashfs_cache_entry *entry; -}; -struct squashfs_cache_entry {u64 block;int length;
@@ -40,6 +26,20 @@ struct squashfs_cache_entry {struct squashfs_page_actor *actor; }; +struct squashfs_cache { +char *name; +int entries; +int curr_blk; +int next_blk; +int num_waiters; +int unused; +int block_size; +int pages; +spinlock_t lock; +wait_queue_head_t wait_queue; + struct squashfs_cache_entry entry[] __counted_by(entries); +}; +struct squashfs_sb_info {const struct squashfs_decompressor *decompressor;int devblksize;
Signature · 1 line
2.53.0