mirror of
https://github.com/torvalds/linux.git
synced 2024-11-15 08:31:55 +00:00
ocfs2/dlm: refactor error handling in dlm_alloc_ctxt
Refactoring error handling in dlm_alloc_ctxt to simplify code. Signed-off-by: Joseph Qi <joseph.qi@huawei.com> Reviewed-by: Alex Chen <alex.chen@huawei.com> Cc: Mark Fasheh <mfasheh@suse.com> Cc: Joel Becker <jlbec@evilplan.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
parent
98acbf63d6
commit
190a7721ac
@ -1975,24 +1975,22 @@ static struct dlm_ctxt *dlm_alloc_ctxt(const char *domain,
|
|||||||
|
|
||||||
dlm = kzalloc(sizeof(*dlm), GFP_KERNEL);
|
dlm = kzalloc(sizeof(*dlm), GFP_KERNEL);
|
||||||
if (!dlm) {
|
if (!dlm) {
|
||||||
mlog_errno(-ENOMEM);
|
ret = -ENOMEM;
|
||||||
|
mlog_errno(ret);
|
||||||
goto leave;
|
goto leave;
|
||||||
}
|
}
|
||||||
|
|
||||||
dlm->name = kstrdup(domain, GFP_KERNEL);
|
dlm->name = kstrdup(domain, GFP_KERNEL);
|
||||||
if (dlm->name == NULL) {
|
if (dlm->name == NULL) {
|
||||||
mlog_errno(-ENOMEM);
|
ret = -ENOMEM;
|
||||||
kfree(dlm);
|
mlog_errno(ret);
|
||||||
dlm = NULL;
|
|
||||||
goto leave;
|
goto leave;
|
||||||
}
|
}
|
||||||
|
|
||||||
dlm->lockres_hash = (struct hlist_head **)dlm_alloc_pagevec(DLM_HASH_PAGES);
|
dlm->lockres_hash = (struct hlist_head **)dlm_alloc_pagevec(DLM_HASH_PAGES);
|
||||||
if (!dlm->lockres_hash) {
|
if (!dlm->lockres_hash) {
|
||||||
mlog_errno(-ENOMEM);
|
ret = -ENOMEM;
|
||||||
kfree(dlm->name);
|
mlog_errno(ret);
|
||||||
kfree(dlm);
|
|
||||||
dlm = NULL;
|
|
||||||
goto leave;
|
goto leave;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2002,11 +2000,8 @@ static struct dlm_ctxt *dlm_alloc_ctxt(const char *domain,
|
|||||||
dlm->master_hash = (struct hlist_head **)
|
dlm->master_hash = (struct hlist_head **)
|
||||||
dlm_alloc_pagevec(DLM_HASH_PAGES);
|
dlm_alloc_pagevec(DLM_HASH_PAGES);
|
||||||
if (!dlm->master_hash) {
|
if (!dlm->master_hash) {
|
||||||
mlog_errno(-ENOMEM);
|
ret = -ENOMEM;
|
||||||
dlm_free_pagevec((void **)dlm->lockres_hash, DLM_HASH_PAGES);
|
mlog_errno(ret);
|
||||||
kfree(dlm->name);
|
|
||||||
kfree(dlm);
|
|
||||||
dlm = NULL;
|
|
||||||
goto leave;
|
goto leave;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2017,14 +2012,8 @@ static struct dlm_ctxt *dlm_alloc_ctxt(const char *domain,
|
|||||||
dlm->node_num = o2nm_this_node();
|
dlm->node_num = o2nm_this_node();
|
||||||
|
|
||||||
ret = dlm_create_debugfs_subroot(dlm);
|
ret = dlm_create_debugfs_subroot(dlm);
|
||||||
if (ret < 0) {
|
if (ret < 0)
|
||||||
dlm_free_pagevec((void **)dlm->master_hash, DLM_HASH_PAGES);
|
|
||||||
dlm_free_pagevec((void **)dlm->lockres_hash, DLM_HASH_PAGES);
|
|
||||||
kfree(dlm->name);
|
|
||||||
kfree(dlm);
|
|
||||||
dlm = NULL;
|
|
||||||
goto leave;
|
goto leave;
|
||||||
}
|
|
||||||
|
|
||||||
spin_lock_init(&dlm->spinlock);
|
spin_lock_init(&dlm->spinlock);
|
||||||
spin_lock_init(&dlm->master_lock);
|
spin_lock_init(&dlm->master_lock);
|
||||||
@ -2085,6 +2074,19 @@ static struct dlm_ctxt *dlm_alloc_ctxt(const char *domain,
|
|||||||
atomic_read(&dlm->dlm_refs.refcount));
|
atomic_read(&dlm->dlm_refs.refcount));
|
||||||
|
|
||||||
leave:
|
leave:
|
||||||
|
if (ret < 0 && dlm) {
|
||||||
|
if (dlm->master_hash)
|
||||||
|
dlm_free_pagevec((void **)dlm->master_hash,
|
||||||
|
DLM_HASH_PAGES);
|
||||||
|
|
||||||
|
if (dlm->lockres_hash)
|
||||||
|
dlm_free_pagevec((void **)dlm->lockres_hash,
|
||||||
|
DLM_HASH_PAGES);
|
||||||
|
|
||||||
|
kfree(dlm->name);
|
||||||
|
kfree(dlm);
|
||||||
|
dlm = NULL;
|
||||||
|
}
|
||||||
return dlm;
|
return dlm;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user