Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>

authored by

Phillip Lougher and committed by
Andrew Morton
49ff2924 f65c64f3

+17 -10
+7 -3
fs/squashfs/cache.c
··· 224 224 int block_size) 225 225 { 226 226 int i, j; 227 - struct squashfs_cache *cache = kzalloc(sizeof(*cache), GFP_KERNEL); 227 + struct squashfs_cache *cache; 228 228 229 + if (entries == 0) 230 + return NULL; 231 + 232 + cache = kzalloc(sizeof(*cache), GFP_KERNEL); 229 233 if (cache == NULL) { 230 234 ERROR("Failed to allocate %s cache\n", name); 231 - return NULL; 235 + return ERR_PTR(-ENOMEM); 232 236 } 233 237 234 238 cache->entry = kcalloc(entries, sizeof(*(cache->entry)), GFP_KERNEL); ··· 285 281 286 282 cleanup: 287 283 squashfs_cache_delete(cache); 288 - return NULL; 284 + return ERR_PTR(-ENOMEM); 289 285 } 290 286 291 287
+10 -7
fs/squashfs/super.c
··· 314 314 sb->s_flags |= SB_RDONLY; 315 315 sb->s_op = &squashfs_super_ops; 316 316 317 - err = -ENOMEM; 318 - 319 317 msblk->block_cache = squashfs_cache_init("metadata", 320 318 SQUASHFS_CACHED_BLKS, SQUASHFS_METADATA_SIZE); 321 - if (msblk->block_cache == NULL) 319 + if (IS_ERR(msblk->block_cache)) { 320 + err = PTR_ERR(msblk->block_cache); 322 321 goto failed_mount; 322 + } 323 323 324 324 /* Allocate read_page block */ 325 325 msblk->read_page = squashfs_cache_init("data", 326 326 msblk->max_thread_num, msblk->block_size); 327 - if (msblk->read_page == NULL) { 327 + if (IS_ERR(msblk->read_page)) { 328 328 errorf(fc, "Failed to allocate read_page block"); 329 + err = PTR_ERR(msblk->read_page); 329 330 goto failed_mount; 330 331 } 331 332 332 333 if (msblk->devblksize == PAGE_SIZE) { 333 334 struct inode *cache = new_inode(sb); 334 335 335 - if (cache == NULL) 336 + if (cache == NULL) { 337 + err = -ENOMEM; 336 338 goto failed_mount; 339 + } 337 340 338 341 set_nlink(cache, 1); 339 342 cache->i_size = OFFSET_MAX; ··· 409 406 410 407 msblk->fragment_cache = squashfs_cache_init("fragment", 411 408 min(SQUASHFS_CACHED_FRAGMENTS, fragments), msblk->block_size); 412 - if (msblk->fragment_cache == NULL) { 413 - err = -ENOMEM; 409 + if (IS_ERR(msblk->fragment_cache)) { 410 + err = PTR_ERR(msblk->fragment_cache); 414 411 goto failed_mount; 415 412 } 416 413