]> Pileus Git - ~andy/linux/commitdiff
target: fix return code in target_core_init_configfs error path
authorPeter Senna Tschudin <peter.senna@gmail.com>
Mon, 17 Sep 2012 18:05:33 +0000 (20:05 +0200)
committerNicholas Bellinger <nab@linux-iscsi.org>
Tue, 18 Sep 2012 01:09:56 +0000 (18:09 -0700)
This patch fixes error cases within target_core_init_configfs() to
properly set ret = -ENOMEM before jumping to the out_global exception
path.

This was originally discovered with the following Coccinelle semantic
match information:

Convert a nonnegative error return code to a negative one, as returned
elsewhere in the function.  A simplified version of the semantic match
that finds this problem is as follows: (http://coccinelle.lip6.fr/)

// <smpl>
(
if@p1 (\(ret < 0\|ret != 0\))
 { ... return ret; }
|
ret@p1 = 0
)
... when != ret = e1
    when != &ret
*if(...)
{
  ... when != ret = e2
      when forall
 return ret;
}
// </smpl>

Signed-off-by: Peter Senna Tschudin <peter.senna@gmail.com>
Cc: stable@vger.kernel.org
Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>
drivers/target/target_core_configfs.c

index a1b41715464abd2a472570c1f3c8203d8693cf70..015f5be27bf6f00dab299b20b295ef71df4af3e2 100644 (file)
@@ -3124,6 +3124,7 @@ static int __init target_core_init_configfs(void)
                                GFP_KERNEL);
        if (!target_cg->default_groups) {
                pr_err("Unable to allocate target_cg->default_groups\n");
+               ret = -ENOMEM;
                goto out_global;
        }
 
@@ -3139,6 +3140,7 @@ static int __init target_core_init_configfs(void)
                                GFP_KERNEL);
        if (!hba_cg->default_groups) {
                pr_err("Unable to allocate hba_cg->default_groups\n");
+               ret = -ENOMEM;
                goto out_global;
        }
        config_group_init_type_name(&alua_group,
@@ -3154,6 +3156,7 @@ static int __init target_core_init_configfs(void)
                        GFP_KERNEL);
        if (!alua_cg->default_groups) {
                pr_err("Unable to allocate alua_cg->default_groups\n");
+               ret = -ENOMEM;
                goto out_global;
        }
 
@@ -3165,14 +3168,17 @@ static int __init target_core_init_configfs(void)
         * Add core/alua/lu_gps/default_lu_gp
         */
        lu_gp = core_alua_allocate_lu_gp("default_lu_gp", 1);
-       if (IS_ERR(lu_gp))
+       if (IS_ERR(lu_gp)) {
+               ret = -ENOMEM;
                goto out_global;
+       }
 
        lu_gp_cg = &alua_lu_gps_group;
        lu_gp_cg->default_groups = kzalloc(sizeof(struct config_group) * 2,
                        GFP_KERNEL);
        if (!lu_gp_cg->default_groups) {
                pr_err("Unable to allocate lu_gp_cg->default_groups\n");
+               ret = -ENOMEM;
                goto out_global;
        }