mirror of
https://github.com/SCST-project/scst.git
synced 2026-05-28 09:20:18 +00:00
Converted kmalloc() + sprintf() calls into a kasprintf() call and converted
kmalloc() + strcpy() calls into a kstrdup() call. (Merged r2986, r2897 and r2901 from the sysfs-changes branch.) git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@2944 d57e44dd-8a1f-0410-8b47-8ef2f437770f
This commit is contained in:
@@ -481,44 +481,37 @@ struct scst_tgt *scst_register_target(struct scst_tgt_template *vtt,
|
||||
|
||||
if (target_name != NULL) {
|
||||
#ifdef CONFIG_SCST_PROC
|
||||
int len = strlen(target_name) +
|
||||
strlen(SCST_DEFAULT_ACG_NAME) + 1 + 1;
|
||||
|
||||
tgt->default_group_name = kmalloc(len, GFP_KERNEL);
|
||||
tgt->default_group_name = kasprintf(GFP_KERNEL, "%s_%s",
|
||||
SCST_DEFAULT_ACG_NAME,
|
||||
target_name);
|
||||
if (tgt->default_group_name == NULL) {
|
||||
TRACE(TRACE_OUT_OF_MEM, "Allocation of default "
|
||||
"group name failed (tgt %s)", target_name);
|
||||
rc = -ENOMEM;
|
||||
goto out_free_tgt;
|
||||
}
|
||||
sprintf(tgt->default_group_name, "%s_%s", SCST_DEFAULT_ACG_NAME,
|
||||
target_name);
|
||||
|
||||
/* In case of error default_group_name will be freed in scst_free_tgt() */
|
||||
#endif
|
||||
|
||||
tgt->tgt_name = kmalloc(strlen(target_name) + 1, GFP_KERNEL);
|
||||
tgt->tgt_name = kstrdup(target_name, GFP_KERNEL);
|
||||
if (tgt->tgt_name == NULL) {
|
||||
TRACE(TRACE_OUT_OF_MEM, "Allocation of tgt name %s failed",
|
||||
target_name);
|
||||
rc = -ENOMEM;
|
||||
goto out_free_tgt;
|
||||
}
|
||||
strcpy(tgt->tgt_name, target_name);
|
||||
} else {
|
||||
static int tgt_num; /* protected by scst_mutex */
|
||||
int len = strlen(vtt->name) +
|
||||
strlen(SCST_DEFAULT_TGT_NAME_SUFFIX) + 11 + 1;
|
||||
|
||||
tgt->tgt_name = kmalloc(len, GFP_KERNEL);
|
||||
tgt->tgt_name = kasprintf(GFP_KERNEL, "%s%s%d", vtt->name,
|
||||
SCST_DEFAULT_TGT_NAME_SUFFIX, tgt_num);
|
||||
if (tgt->tgt_name == NULL) {
|
||||
TRACE(TRACE_OUT_OF_MEM, "Allocation of tgt name failed "
|
||||
"(template name %s)", vtt->name);
|
||||
rc = -ENOMEM;
|
||||
goto out_free_tgt;
|
||||
}
|
||||
sprintf(tgt->tgt_name, "%s%s%d", vtt->name,
|
||||
SCST_DEFAULT_TGT_NAME_SUFFIX, tgt_num++);
|
||||
tgt_num++;
|
||||
}
|
||||
|
||||
if (mutex_lock_interruptible(&scst_mutex) != 0) {
|
||||
@@ -897,14 +890,14 @@ static int scst_register_device(struct scsi_device *scsidp)
|
||||
|
||||
dev->type = scsidp->type;
|
||||
|
||||
dev->virt_name = kmalloc(50, GFP_KERNEL);
|
||||
dev->virt_name = kasprintf(GFP_KERNEL, "%d:%d:%d:%d",
|
||||
scsidp->host->host_no,
|
||||
scsidp->channel, scsidp->id, scsidp->lun);
|
||||
if (dev->virt_name == NULL) {
|
||||
PRINT_ERROR("%s", "Unable to alloc device name");
|
||||
res = -ENOMEM;
|
||||
goto out_free_dev;
|
||||
}
|
||||
snprintf(dev->virt_name, 50, "%d:%d:%d:%d", scsidp->host->host_no,
|
||||
scsidp->channel, scsidp->id, scsidp->lun);
|
||||
|
||||
list_for_each_entry(d, &scst_dev_list, dev_list_entry) {
|
||||
if (strcmp(d->virt_name, dev->virt_name) == 0) {
|
||||
|
||||
Reference in New Issue
Block a user