Dan Carpenter
2012-Feb-13 13:50 UTC
[Ocfs2-devel] [patch] ocfs2: cleanup error handling in o2hb_alloc_hb_set()
If "ret" is NULL, then "hs" is also NULL, so there is no need to free it. config_group_init_type_name() can't fail if the name ("heartbeat" in this case) is less than CONFIGFS_ITEM_NAME_LEN (20) characters long so we can just remove this error handling code. Signed-off-by: Dan Carpenter <dan.carpenter at oracle.com> diff --git a/fs/ocfs2/cluster/heartbeat.c b/fs/ocfs2/cluster/heartbeat.c index f3f2d95..0bca51b 100644 --- a/fs/ocfs2/cluster/heartbeat.c +++ b/fs/ocfs2/cluster/heartbeat.c @@ -2306,20 +2306,14 @@ static struct config_item_type o2hb_heartbeat_group_type = { struct config_group *o2hb_alloc_hb_set(void) { struct o2hb_heartbeat_group *hs = NULL; - struct config_group *ret = NULL; hs = kzalloc(sizeof(struct o2hb_heartbeat_group), GFP_KERNEL); if (hs == NULL) - goto out; + return NULL; config_group_init_type_name(&hs->hs_group, "heartbeat", &o2hb_heartbeat_group_type); - - ret = &hs->hs_group; -out: - if (ret == NULL) - kfree(hs); - return ret; + return &hs->hs_group; } void o2hb_free_hb_set(struct config_group *group)
Sunil Mushran
2012-Feb-13 19:39 UTC
[Ocfs2-devel] [patch] ocfs2: cleanup error handling in o2hb_alloc_hb_set()
hmm... I would say NAK because config_group_item_type_name() could change in the future. And there is nothing wrong with the current code. On 02/13/2012 05:50 AM, Dan Carpenter wrote:> If "ret" is NULL, then "hs" is also NULL, so there is no need to free > it. config_group_init_type_name() can't fail if the name ("heartbeat" > in this case) is less than CONFIGFS_ITEM_NAME_LEN (20) characters long > so we can just remove this error handling code. > > Signed-off-by: Dan Carpenter<dan.carpenter at oracle.com> > > diff --git a/fs/ocfs2/cluster/heartbeat.c b/fs/ocfs2/cluster/heartbeat.c > index f3f2d95..0bca51b 100644 > --- a/fs/ocfs2/cluster/heartbeat.c > +++ b/fs/ocfs2/cluster/heartbeat.c > @@ -2306,20 +2306,14 @@ static struct config_item_type o2hb_heartbeat_group_type = { > struct config_group *o2hb_alloc_hb_set(void) > { > struct o2hb_heartbeat_group *hs = NULL; > - struct config_group *ret = NULL; > > hs = kzalloc(sizeof(struct o2hb_heartbeat_group), GFP_KERNEL); > if (hs == NULL) > - goto out; > + return NULL; > > config_group_init_type_name(&hs->hs_group, "heartbeat", > &o2hb_heartbeat_group_type); > - > - ret =&hs->hs_group; > -out: > - if (ret == NULL) > - kfree(hs); > - return ret; > + return&hs->hs_group; > } > > void o2hb_free_hb_set(struct config_group *group)
Joel Becker
2012-Feb-13 20:04 UTC
[Ocfs2-devel] [patch] ocfs2: cleanup error handling in o2hb_alloc_hb_set()
On Mon, Feb 13, 2012 at 04:50:47PM +0300, Dan Carpenter wrote:> If "ret" is NULL, then "hs" is also NULL, so there is no need to free > it. config_group_init_type_name() can't fail if the name ("heartbeat" > in this case) is less than CONFIGFS_ITEM_NAME_LEN (20) characters long > so we can just remove this error handling code.Is there a problem we're fixing here? We can make all sorts of arguments about single-exit functions vs immediate returns, but if there isn't a problem, I'm not sure what we gain by code churn. Joel> > Signed-off-by: Dan Carpenter <dan.carpenter at oracle.com> > > diff --git a/fs/ocfs2/cluster/heartbeat.c b/fs/ocfs2/cluster/heartbeat.c > index f3f2d95..0bca51b 100644 > --- a/fs/ocfs2/cluster/heartbeat.c > +++ b/fs/ocfs2/cluster/heartbeat.c > @@ -2306,20 +2306,14 @@ static struct config_item_type o2hb_heartbeat_group_type = { > struct config_group *o2hb_alloc_hb_set(void) > { > struct o2hb_heartbeat_group *hs = NULL; > - struct config_group *ret = NULL; > > hs = kzalloc(sizeof(struct o2hb_heartbeat_group), GFP_KERNEL); > if (hs == NULL) > - goto out; > + return NULL; > > config_group_init_type_name(&hs->hs_group, "heartbeat", > &o2hb_heartbeat_group_type); > - > - ret = &hs->hs_group; > -out: > - if (ret == NULL) > - kfree(hs); > - return ret; > + return &hs->hs_group; > } > > void o2hb_free_hb_set(struct config_group *group)-- "Copy from one, it's plagiarism; copy from two, it's research." - Wilson Mizner http://www.jlbec.org/ jlbec at evilplan.org