mirror of
				https://github.com/torvalds/linux.git
				synced 2025-11-04 10:40:15 +02:00 
			
		
		
		
	squashfs: make squashfs_cache_init() return ERR_PTR(-ENOMEM)
Patch series "squashfs: reduce memory usage and update docs". This patchset reduces the amount of memory that Squashfs uses when CONFIG_FILE_DIRECT is configured, and updates various out of date information in the documentation and Kconfig. This patch (of 4): Make squashfs_cache_init() return an ERR_PTR(-ENOMEM) on failure rather than NULL. This tidies up some calling code, but, it also allows NULL to be returned as a valid result when a cache hasn't be allocated. Link: https://lkml.kernel.org/r/20241229233752.54481-1-phillip@squashfs.org.uk Link: https://lkml.kernel.org/r/20241229233752.54481-2-phillip@squashfs.org.uk Signed-off-by: Phillip Lougher <phillip@squashfs.org.uk> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
This commit is contained in:
		
							parent
							
								
									f65c64f311
								
							
						
					
					
						commit
						49ff29240e
					
				
					 2 changed files with 17 additions and 10 deletions
				
			
		| 
						 | 
					@ -224,11 +224,15 @@ struct squashfs_cache *squashfs_cache_init(char *name, int entries,
 | 
				
			||||||
	int block_size)
 | 
						int block_size)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	int i, j;
 | 
						int i, j;
 | 
				
			||||||
	struct squashfs_cache *cache = kzalloc(sizeof(*cache), GFP_KERNEL);
 | 
						struct squashfs_cache *cache;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (entries == 0)
 | 
				
			||||||
 | 
							return NULL;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						cache = kzalloc(sizeof(*cache), GFP_KERNEL);
 | 
				
			||||||
	if (cache == NULL) {
 | 
						if (cache == NULL) {
 | 
				
			||||||
		ERROR("Failed to allocate %s cache\n", name);
 | 
							ERROR("Failed to allocate %s cache\n", name);
 | 
				
			||||||
		return NULL;
 | 
							return ERR_PTR(-ENOMEM);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	cache->entry = kcalloc(entries, sizeof(*(cache->entry)), GFP_KERNEL);
 | 
						cache->entry = kcalloc(entries, sizeof(*(cache->entry)), GFP_KERNEL);
 | 
				
			||||||
| 
						 | 
					@ -281,7 +285,7 @@ struct squashfs_cache *squashfs_cache_init(char *name, int entries,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
cleanup:
 | 
					cleanup:
 | 
				
			||||||
	squashfs_cache_delete(cache);
 | 
						squashfs_cache_delete(cache);
 | 
				
			||||||
	return NULL;
 | 
						return ERR_PTR(-ENOMEM);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -314,26 +314,29 @@ static int squashfs_fill_super(struct super_block *sb, struct fs_context *fc)
 | 
				
			||||||
	sb->s_flags |= SB_RDONLY;
 | 
						sb->s_flags |= SB_RDONLY;
 | 
				
			||||||
	sb->s_op = &squashfs_super_ops;
 | 
						sb->s_op = &squashfs_super_ops;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	err = -ENOMEM;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	msblk->block_cache = squashfs_cache_init("metadata",
 | 
						msblk->block_cache = squashfs_cache_init("metadata",
 | 
				
			||||||
			SQUASHFS_CACHED_BLKS, SQUASHFS_METADATA_SIZE);
 | 
								SQUASHFS_CACHED_BLKS, SQUASHFS_METADATA_SIZE);
 | 
				
			||||||
	if (msblk->block_cache == NULL)
 | 
						if (IS_ERR(msblk->block_cache)) {
 | 
				
			||||||
 | 
							err = PTR_ERR(msblk->block_cache);
 | 
				
			||||||
		goto failed_mount;
 | 
							goto failed_mount;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* Allocate read_page block */
 | 
						/* Allocate read_page block */
 | 
				
			||||||
	msblk->read_page = squashfs_cache_init("data",
 | 
						msblk->read_page = squashfs_cache_init("data",
 | 
				
			||||||
		msblk->max_thread_num, msblk->block_size);
 | 
							msblk->max_thread_num, msblk->block_size);
 | 
				
			||||||
	if (msblk->read_page == NULL) {
 | 
						if (IS_ERR(msblk->read_page)) {
 | 
				
			||||||
		errorf(fc, "Failed to allocate read_page block");
 | 
							errorf(fc, "Failed to allocate read_page block");
 | 
				
			||||||
 | 
							err = PTR_ERR(msblk->read_page);
 | 
				
			||||||
		goto failed_mount;
 | 
							goto failed_mount;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (msblk->devblksize == PAGE_SIZE) {
 | 
						if (msblk->devblksize == PAGE_SIZE) {
 | 
				
			||||||
		struct inode *cache = new_inode(sb);
 | 
							struct inode *cache = new_inode(sb);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if (cache == NULL)
 | 
							if (cache == NULL) {
 | 
				
			||||||
 | 
								err = -ENOMEM;
 | 
				
			||||||
			goto failed_mount;
 | 
								goto failed_mount;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		set_nlink(cache, 1);
 | 
							set_nlink(cache, 1);
 | 
				
			||||||
		cache->i_size = OFFSET_MAX;
 | 
							cache->i_size = OFFSET_MAX;
 | 
				
			||||||
| 
						 | 
					@ -406,8 +409,8 @@ static int squashfs_fill_super(struct super_block *sb, struct fs_context *fc)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	msblk->fragment_cache = squashfs_cache_init("fragment",
 | 
						msblk->fragment_cache = squashfs_cache_init("fragment",
 | 
				
			||||||
		min(SQUASHFS_CACHED_FRAGMENTS, fragments), msblk->block_size);
 | 
							min(SQUASHFS_CACHED_FRAGMENTS, fragments), msblk->block_size);
 | 
				
			||||||
	if (msblk->fragment_cache == NULL) {
 | 
						if (IS_ERR(msblk->fragment_cache)) {
 | 
				
			||||||
		err = -ENOMEM;
 | 
							err = PTR_ERR(msblk->fragment_cache);
 | 
				
			||||||
		goto failed_mount;
 | 
							goto failed_mount;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue