mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-08-23 09:19:51 +00:00
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>
This commit is contained in:
parent
778229af95
commit
ed72a4d52a
1 changed files with 3 additions and 13 deletions
|
@ -154,22 +154,18 @@ static struct iscsi_param *iscsi_set_default_param(struct iscsi_param_list *para
|
||||||
}
|
}
|
||||||
INIT_LIST_HEAD(¶m->p_list);
|
INIT_LIST_HEAD(¶m->p_list);
|
||||||
|
|
||||||
param->name = kzalloc(strlen(name) + 1, GFP_KERNEL);
|
param->name = kstrdup(name, GFP_KERNEL);
|
||||||
if (!param->name) {
|
if (!param->name) {
|
||||||
pr_err("Unable to allocate memory for parameter name.\n");
|
pr_err("Unable to allocate memory for parameter name.\n");
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
param->value = kzalloc(strlen(value) + 1, GFP_KERNEL);
|
param->value = kstrdup(value, GFP_KERNEL);
|
||||||
if (!param->value) {
|
if (!param->value) {
|
||||||
pr_err("Unable to allocate memory for parameter value.\n");
|
pr_err("Unable to allocate memory for parameter value.\n");
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(param->name, name, strlen(name));
|
|
||||||
param->name[strlen(name)] = '\0';
|
|
||||||
memcpy(param->value, value, strlen(value));
|
|
||||||
param->value[strlen(value)] = '\0';
|
|
||||||
param->phase = phase;
|
param->phase = phase;
|
||||||
param->scope = scope;
|
param->scope = scope;
|
||||||
param->sender = sender;
|
param->sender = sender;
|
||||||
|
@ -635,11 +631,8 @@ void iscsi_release_param_list(struct iscsi_param_list *param_list)
|
||||||
list_del(¶m->p_list);
|
list_del(¶m->p_list);
|
||||||
|
|
||||||
kfree(param->name);
|
kfree(param->name);
|
||||||
param->name = NULL;
|
|
||||||
kfree(param->value);
|
kfree(param->value);
|
||||||
param->value = NULL;
|
|
||||||
kfree(param);
|
kfree(param);
|
||||||
param = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
iscsi_release_extra_responses(param_list);
|
iscsi_release_extra_responses(param_list);
|
||||||
|
@ -687,15 +680,12 @@ int iscsi_update_param_value(struct iscsi_param *param, char *value)
|
||||||
{
|
{
|
||||||
kfree(param->value);
|
kfree(param->value);
|
||||||
|
|
||||||
param->value = kzalloc(strlen(value) + 1, GFP_KERNEL);
|
param->value = kstrdup(value, GFP_KERNEL);
|
||||||
if (!param->value) {
|
if (!param->value) {
|
||||||
pr_err("Unable to allocate memory for value.\n");
|
pr_err("Unable to allocate memory for value.\n");
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(param->value, value, strlen(value));
|
|
||||||
param->value[strlen(value)] = '\0';
|
|
||||||
|
|
||||||
pr_debug("iSCSI Parameter updated to %s=%s\n",
|
pr_debug("iSCSI Parameter updated to %s=%s\n",
|
||||||
param->name, param->value);
|
param->name, param->value);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
Loading…
Reference in a new issue