xfs: return corresponding errcode if xfs_initialize_perag() fail

[ Upstream commit 595189c25c28a55523354336bf24453242c81c15 ]

In xfs_initialize_perag(), if kmem_zalloc(), xfs_buf_hash_init(), or
radix_tree_preload() failed, the returned value 'error' is not set
accordingly.

Reported-as-fixing: 8b26c5825e ("xfs: handle ENOMEM correctly during initialisation of perag structures")
Fixes: 9b24717979 ("xfs: cache unlinked pointers in an rhashtable")
Reported-by: Hulk Robot <hulkci@huawei.com>
Signed-off-by: Yu Kuai <yukuai3@huawei.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
Yu Kuai 2020-11-18 09:21:26 -08:00 committed by Greg Kroah-Hartman
parent 738ec76706
commit ad3c4c96bf

View File

@ -195,21 +195,26 @@ xfs_initialize_perag(
} }
pag = kmem_zalloc(sizeof(*pag), KM_MAYFAIL); pag = kmem_zalloc(sizeof(*pag), KM_MAYFAIL);
if (!pag) if (!pag) {
error = -ENOMEM;
goto out_unwind_new_pags; goto out_unwind_new_pags;
}
pag->pag_agno = index; pag->pag_agno = index;
pag->pag_mount = mp; pag->pag_mount = mp;
spin_lock_init(&pag->pag_ici_lock); spin_lock_init(&pag->pag_ici_lock);
mutex_init(&pag->pag_ici_reclaim_lock); mutex_init(&pag->pag_ici_reclaim_lock);
INIT_RADIX_TREE(&pag->pag_ici_root, GFP_ATOMIC); INIT_RADIX_TREE(&pag->pag_ici_root, GFP_ATOMIC);
if (xfs_buf_hash_init(pag))
error = xfs_buf_hash_init(pag);
if (error)
goto out_free_pag; goto out_free_pag;
init_waitqueue_head(&pag->pagb_wait); init_waitqueue_head(&pag->pagb_wait);
spin_lock_init(&pag->pagb_lock); spin_lock_init(&pag->pagb_lock);
pag->pagb_count = 0; pag->pagb_count = 0;
pag->pagb_tree = RB_ROOT; pag->pagb_tree = RB_ROOT;
if (radix_tree_preload(GFP_NOFS)) error = radix_tree_preload(GFP_NOFS);
if (error)
goto out_hash_destroy; goto out_hash_destroy;
spin_lock(&mp->m_perag_lock); spin_lock(&mp->m_perag_lock);