diff options
author | Sebastian Andrzej Siewior <bigeasy@linutronix.de> | 2012-11-29 14:29:01 -0500 |
---|---|---|
committer | Nicholas Bellinger <nab@linux-iscsi.org> | 2012-12-07 20:55:44 -0500 |
commit | ed72a4d52add345595f09b360d6ac5f20428d361 (patch) | |
tree | 6ad4f0a9313fc390b7ec6799560b2a0d10207e1a /drivers/target/iscsi/iscsi_target_parameters.c | |
parent | 778229af95977a4aca8656143d457401c2bb8f96 (diff) |
iscsi-target: use kstrdup() for iscsi_param
The kmalloc() + strlen() + memcpy() block is what kstrdup() does as
well. While here I also removed the "to NULL assignment" of pointers
which are fed to kfree or thrown away anyway.
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>
Diffstat (limited to 'drivers/target/iscsi/iscsi_target_parameters.c')
-rw-r--r-- | drivers/target/iscsi/iscsi_target_parameters.c | 16 |
1 files changed, 3 insertions, 13 deletions
diff --git a/drivers/target/iscsi/iscsi_target_parameters.c b/drivers/target/iscsi/iscsi_target_parameters.c index 90b740048f26..839def0dd57c 100644 --- a/drivers/target/iscsi/iscsi_target_parameters.c +++ b/drivers/target/iscsi/iscsi_target_parameters.c | |||
@@ -154,22 +154,18 @@ static struct iscsi_param *iscsi_set_default_param(struct iscsi_param_list *para | |||
154 | } | 154 | } |
155 | INIT_LIST_HEAD(¶m->p_list); | 155 | INIT_LIST_HEAD(¶m->p_list); |
156 | 156 | ||
157 | param->name = kzalloc(strlen(name) + 1, GFP_KERNEL); | 157 | param->name = kstrdup(name, GFP_KERNEL); |
158 | if (!param->name) { | 158 | if (!param->name) { |
159 | pr_err("Unable to allocate memory for parameter name.\n"); | 159 | pr_err("Unable to allocate memory for parameter name.\n"); |
160 | goto out; | 160 | goto out; |
161 | } | 161 | } |
162 | 162 | ||
163 | param->value = kzalloc(strlen(value) + 1, GFP_KERNEL); | 163 | param->value = kstrdup(value, GFP_KERNEL); |
164 | if (!param->value) { | 164 | if (!param->value) { |
165 | pr_err("Unable to allocate memory for parameter value.\n"); | 165 | pr_err("Unable to allocate memory for parameter value.\n"); |
166 | goto out; | 166 | goto out; |
167 | } | 167 | } |
168 | 168 | ||
169 | memcpy(param->name, name, strlen(name)); | ||
170 | param->name[strlen(name)] = '\0'; | ||
171 | memcpy(param->value, value, strlen(value)); | ||
172 | param->value[strlen(value)] = '\0'; | ||
173 | param->phase = phase; | 169 | param->phase = phase; |
174 | param->scope = scope; | 170 | param->scope = scope; |
175 | param->sender = sender; | 171 | param->sender = sender; |
@@ -635,11 +631,8 @@ void iscsi_release_param_list(struct iscsi_param_list *param_list) | |||
635 | list_del(¶m->p_list); | 631 | list_del(¶m->p_list); |
636 | 632 | ||
637 | kfree(param->name); | 633 | kfree(param->name); |
638 | param->name = NULL; | ||
639 | kfree(param->value); | 634 | kfree(param->value); |
640 | param->value = NULL; | ||
641 | kfree(param); | 635 | kfree(param); |
642 | param = NULL; | ||
643 | } | 636 | } |
644 | 637 | ||
645 | iscsi_release_extra_responses(param_list); | 638 | iscsi_release_extra_responses(param_list); |
@@ -687,15 +680,12 @@ int iscsi_update_param_value(struct iscsi_param *param, char *value) | |||
687 | { | 680 | { |
688 | kfree(param->value); | 681 | kfree(param->value); |
689 | 682 | ||
690 | param->value = kzalloc(strlen(value) + 1, GFP_KERNEL); | 683 | param->value = kstrdup(value, GFP_KERNEL); |
691 | if (!param->value) { | 684 | if (!param->value) { |
692 | pr_err("Unable to allocate memory for value.\n"); | 685 | pr_err("Unable to allocate memory for value.\n"); |
693 | return -ENOMEM; | 686 | return -ENOMEM; |
694 | } | 687 | } |
695 | 688 | ||
696 | memcpy(param->value, value, strlen(value)); | ||
697 | param->value[strlen(value)] = '\0'; | ||
698 | |||
699 | pr_debug("iSCSI Parameter updated to %s=%s\n", | 689 | pr_debug("iSCSI Parameter updated to %s=%s\n", |
700 | param->name, param->value); | 690 | param->name, param->value); |
701 | return 0; | 691 | return 0; |