diff options
author | Joseph Qi <joseph.qi@huawei.com> | 2014-10-09 18:24:54 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2014-10-09 22:25:46 -0400 |
commit | 190a7721ac865744a59fdf2f291c2a211cab6217 (patch) | |
tree | 682febf00ea058368192b27ce2cbf3679a5f74ab /fs | |
parent | 98acbf63d63c83e847c5cbe454b36a53cfbbc7a5 (diff) |
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>
Diffstat (limited to 'fs')
-rw-r--r-- | fs/ocfs2/dlm/dlmdomain.c | 42 |
1 files changed, 22 insertions, 20 deletions
diff --git a/fs/ocfs2/dlm/dlmdomain.c b/fs/ocfs2/dlm/dlmdomain.c index 3fcf205ee900..257a6dfe3f13 100644 --- a/fs/ocfs2/dlm/dlmdomain.c +++ b/fs/ocfs2/dlm/dlmdomain.c | |||
@@ -1975,24 +1975,22 @@ static struct dlm_ctxt *dlm_alloc_ctxt(const char *domain, | |||
1975 | 1975 | ||
1976 | dlm = kzalloc(sizeof(*dlm), GFP_KERNEL); | 1976 | dlm = kzalloc(sizeof(*dlm), GFP_KERNEL); |
1977 | if (!dlm) { | 1977 | if (!dlm) { |
1978 | mlog_errno(-ENOMEM); | 1978 | ret = -ENOMEM; |
1979 | mlog_errno(ret); | ||
1979 | goto leave; | 1980 | goto leave; |
1980 | } | 1981 | } |
1981 | 1982 | ||
1982 | dlm->name = kstrdup(domain, GFP_KERNEL); | 1983 | dlm->name = kstrdup(domain, GFP_KERNEL); |
1983 | if (dlm->name == NULL) { | 1984 | if (dlm->name == NULL) { |
1984 | mlog_errno(-ENOMEM); | 1985 | ret = -ENOMEM; |
1985 | kfree(dlm); | 1986 | mlog_errno(ret); |
1986 | dlm = NULL; | ||
1987 | goto leave; | 1987 | goto leave; |
1988 | } | 1988 | } |
1989 | 1989 | ||
1990 | dlm->lockres_hash = (struct hlist_head **)dlm_alloc_pagevec(DLM_HASH_PAGES); | 1990 | dlm->lockres_hash = (struct hlist_head **)dlm_alloc_pagevec(DLM_HASH_PAGES); |
1991 | if (!dlm->lockres_hash) { | 1991 | if (!dlm->lockres_hash) { |
1992 | mlog_errno(-ENOMEM); | 1992 | ret = -ENOMEM; |
1993 | kfree(dlm->name); | 1993 | mlog_errno(ret); |
1994 | kfree(dlm); | ||
1995 | dlm = NULL; | ||
1996 | goto leave; | 1994 | goto leave; |
1997 | } | 1995 | } |
1998 | 1996 | ||
@@ -2002,11 +2000,8 @@ static struct dlm_ctxt *dlm_alloc_ctxt(const char *domain, | |||
2002 | dlm->master_hash = (struct hlist_head **) | 2000 | dlm->master_hash = (struct hlist_head **) |
2003 | dlm_alloc_pagevec(DLM_HASH_PAGES); | 2001 | dlm_alloc_pagevec(DLM_HASH_PAGES); |
2004 | if (!dlm->master_hash) { | 2002 | if (!dlm->master_hash) { |
2005 | mlog_errno(-ENOMEM); | 2003 | ret = -ENOMEM; |
2006 | dlm_free_pagevec((void **)dlm->lockres_hash, DLM_HASH_PAGES); | 2004 | mlog_errno(ret); |
2007 | kfree(dlm->name); | ||
2008 | kfree(dlm); | ||
2009 | dlm = NULL; | ||
2010 | goto leave; | 2005 | goto leave; |
2011 | } | 2006 | } |
2012 | 2007 | ||
@@ -2017,14 +2012,8 @@ static struct dlm_ctxt *dlm_alloc_ctxt(const char *domain, | |||
2017 | dlm->node_num = o2nm_this_node(); | 2012 | dlm->node_num = o2nm_this_node(); |
2018 | 2013 | ||
2019 | ret = dlm_create_debugfs_subroot(dlm); | 2014 | ret = dlm_create_debugfs_subroot(dlm); |
2020 | if (ret < 0) { | 2015 | if (ret < 0) |
2021 | dlm_free_pagevec((void **)dlm->master_hash, DLM_HASH_PAGES); | ||
2022 | dlm_free_pagevec((void **)dlm->lockres_hash, DLM_HASH_PAGES); | ||
2023 | kfree(dlm->name); | ||
2024 | kfree(dlm); | ||
2025 | dlm = NULL; | ||
2026 | goto leave; | 2016 | goto leave; |
2027 | } | ||
2028 | 2017 | ||
2029 | spin_lock_init(&dlm->spinlock); | 2018 | spin_lock_init(&dlm->spinlock); |
2030 | spin_lock_init(&dlm->master_lock); | 2019 | spin_lock_init(&dlm->master_lock); |
@@ -2085,6 +2074,19 @@ static struct dlm_ctxt *dlm_alloc_ctxt(const char *domain, | |||
2085 | atomic_read(&dlm->dlm_refs.refcount)); | 2074 | atomic_read(&dlm->dlm_refs.refcount)); |
2086 | 2075 | ||
2087 | leave: | 2076 | leave: |
2077 | if (ret < 0 && dlm) { | ||
2078 | if (dlm->master_hash) | ||
2079 | dlm_free_pagevec((void **)dlm->master_hash, | ||
2080 | DLM_HASH_PAGES); | ||
2081 | |||
2082 | if (dlm->lockres_hash) | ||
2083 | dlm_free_pagevec((void **)dlm->lockres_hash, | ||
2084 | DLM_HASH_PAGES); | ||
2085 | |||
2086 | kfree(dlm->name); | ||
2087 | kfree(dlm); | ||
2088 | dlm = NULL; | ||
2089 | } | ||
2088 | return dlm; | 2090 | return dlm; |
2089 | } | 2091 | } |
2090 | 2092 | ||