Skip to content

Commit 3791163

Browse files
Georgi Djakovgregkh
authored andcommitted
interconnect: Handle memory allocation errors
When we allocate memory, kasprintf() can fail and we must check its return value. Fixes: 0530983 ("interconnect: Add a name to struct icc_path") Signed-off-by: Georgi Djakov <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 3745488 commit 3791163

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

drivers/interconnect/core.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,11 @@ struct icc_path *of_icc_get(struct device *dev, const char *name)
445445
path->name = kasprintf(GFP_KERNEL, "%s-%s",
446446
src_node->name, dst_node->name);
447447

448+
if (!path->name) {
449+
kfree(path);
450+
return ERR_PTR(-ENOMEM);
451+
}
452+
448453
return path;
449454
}
450455
EXPORT_SYMBOL_GPL(of_icc_get);
@@ -579,6 +584,10 @@ struct icc_path *icc_get(struct device *dev, const int src_id, const int dst_id)
579584
}
580585

581586
path->name = kasprintf(GFP_KERNEL, "%s-%s", src->name, dst->name);
587+
if (!path->name) {
588+
kfree(path);
589+
path = ERR_PTR(-ENOMEM);
590+
}
582591
out:
583592
mutex_unlock(&icc_lock);
584593
return path;

0 commit comments

Comments
 (0)