Skip to content

Commit

Permalink
interconnect: Handle memory allocation errors
Browse files Browse the repository at this point in the history
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 <georgi.djakov@linaro.org>
Link: https://lore.kernel.org/r/20200226110420.5357-2-georgi.djakov@linaro.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
Georgi Djakov authored and Greg Kroah-Hartman committed Mar 3, 2020
1 parent 3745488 commit 3791163
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions drivers/interconnect/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,11 @@ struct icc_path *of_icc_get(struct device *dev, const char *name)
path->name = kasprintf(GFP_KERNEL, "%s-%s",
src_node->name, dst_node->name);

if (!path->name) {
kfree(path);
return ERR_PTR(-ENOMEM);
}

return path;
}
EXPORT_SYMBOL_GPL(of_icc_get);
Expand Down Expand Up @@ -579,6 +584,10 @@ struct icc_path *icc_get(struct device *dev, const int src_id, const int dst_id)
}

path->name = kasprintf(GFP_KERNEL, "%s-%s", src->name, dst->name);
if (!path->name) {
kfree(path);
path = ERR_PTR(-ENOMEM);
}
out:
mutex_unlock(&icc_lock);
return path;
Expand Down

0 comments on commit 3791163

Please sign in to comment.