[PATCH 2/7] iscsi-target: Less checks in iscsi_set_default_param() after error detection

From: SF Markus Elfring
Date: Sat Dec 12 2015 - 09:37:20 EST


From: Markus Elfring <elfring@xxxxxxxxxxxxxxxxxxxxx>
Date: Sat, 12 Dec 2015 12:50:10 +0100

This issue was detected by using the Coccinelle software.

A sanity check would be performed by the iscsi_set_default_param() function
even if it is known already that the passed variable contained
a null pointer.

* This implementation detail could be improved by adjustments
for jump targets according to the Linux coding style convention.

* Let us return directly if a call of the function "kzalloc" failed.

Signed-off-by: Markus Elfring <elfring@xxxxxxxxxxxxxxxxxxxxx>
---
drivers/target/iscsi/iscsi_target_parameters.c | 21 ++++++++++-----------
1 file changed, 10 insertions(+), 11 deletions(-)

diff --git a/drivers/target/iscsi/iscsi_target_parameters.c b/drivers/target/iscsi/iscsi_target_parameters.c
index 0a8bd3f..15b2618 100644
--- a/drivers/target/iscsi/iscsi_target_parameters.c
+++ b/drivers/target/iscsi/iscsi_target_parameters.c
@@ -131,20 +131,20 @@ static struct iscsi_param *iscsi_set_default_param(struct iscsi_param_list *para

if (!param) {
pr_err("Unable to allocate memory for parameter.\n");
- goto out;
+ return NULL;
}
INIT_LIST_HEAD(&param->p_list);

param->name = kstrdup(name, GFP_KERNEL);
if (!param->name) {
pr_err("Unable to allocate memory for parameter name.\n");
- goto out;
+ goto free_param;
}

param->value = kstrdup(value, GFP_KERNEL);
if (!param->value) {
pr_err("Unable to allocate memory for parameter value.\n");
- goto out;
+ goto free_name;
}

param->phase = phase;
@@ -182,18 +182,17 @@ static struct iscsi_param *iscsi_set_default_param(struct iscsi_param_list *para
default:
pr_err("Unknown type_range 0x%02x\n",
param->type_range);
- goto out;
+ goto free_value;
}
list_add_tail(&param->p_list, &param_list->param_list);

return param;
-out:
- if (param) {
- kfree(param->value);
- kfree(param->name);
- kfree(param);
- }
-
+free_value:
+ kfree(param->value);
+free_name:
+ kfree(param->name);
+free_param:
+ kfree(param);
return NULL;
}

--
2.6.3

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/