int block_size)
 {
        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) {
                ERROR("Failed to allocate %s cache\n", name);
-               return NULL;
+               return ERR_PTR(-ENOMEM);
        }
 
        cache->entry = kcalloc(entries, sizeof(*(cache->entry)), GFP_KERNEL);
 
 cleanup:
        squashfs_cache_delete(cache);
-       return NULL;
+       return ERR_PTR(-ENOMEM);
 }
 
 
 
        sb->s_flags |= SB_RDONLY;
        sb->s_op = &squashfs_super_ops;
 
-       err = -ENOMEM;
-
        msblk->block_cache = squashfs_cache_init("metadata",
                        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;
+       }
 
        /* Allocate read_page block */
        msblk->read_page = squashfs_cache_init("data",
                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");
+               err = PTR_ERR(msblk->read_page);
                goto failed_mount;
        }
 
        if (msblk->devblksize == PAGE_SIZE) {
                struct inode *cache = new_inode(sb);
 
-               if (cache == NULL)
+               if (cache == NULL) {
+                       err = -ENOMEM;
                        goto failed_mount;
+               }
 
                set_nlink(cache, 1);
                cache->i_size = OFFSET_MAX;
 
        msblk->fragment_cache = squashfs_cache_init("fragment",
                min(SQUASHFS_CACHED_FRAGMENTS, fragments), msblk->block_size);
-       if (msblk->fragment_cache == NULL) {
-               err = -ENOMEM;
+       if (IS_ERR(msblk->fragment_cache)) {
+               err = PTR_ERR(msblk->fragment_cache);
                goto failed_mount;
        }