of_alias_get_id() may return -ENODEV which leads to illegal access to
the cmdq->clocks array.
Adding a check over alias_id to prevent the unexpected behavior.
Fixes: 85dfdbfc13ea ("mailbox: cmdq: add multi-gce clocks support for
mt8195")
Signed-off-by: Fei Shao <redacted>
---
drivers/mailbox/mtk-cmdq-mailbox.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
In the probe function, the clock IDs were pointed to local variables
which should only be used in the same code block, and any access to them
after the probing stage becomes a use-after-free case.
Since there are only limited variants of the gce clock names so far, we
can just declare them as global constants to fix the issue.
Fixes: 85dfdbfc13ea ("mailbox: cmdq: add multi-gce clocks support for
mt8195")
Signed-off-by: Fei Shao <redacted>
---
drivers/mailbox/mtk-cmdq-mailbox.c | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)
@@ -532,7 +535,6 @@ static int cmdq_probe(struct platform_device *pdev)structdevice_node*phandle=dev->of_node;structdevice_node*node;intalias_id=0;-charclk_name[4]="gce";cmdq=devm_kzalloc(dev,sizeof(*cmdq),GFP_KERNEL);if(!cmdq)
@@ -570,12 +572,9 @@ static int cmdq_probe(struct platform_device *pdev)if(cmdq->gce_num>1){for_each_child_of_node(phandle->parent,node){-charclk_id[8];-alias_id=of_alias_get_id(node,clk_name);if(alias_id>=0&&alias_id<cmdq->gce_num){-snprintf(clk_id,sizeof(clk_id),"%s%d",clk_name,alias_id);-cmdq->clocks[alias_id].id=clk_id;+cmdq->clocks[alias_id].id=clk_names[alias_id];cmdq->clocks[alias_id].clk=of_clk_get(node,0);if(IS_ERR(cmdq->clocks[alias_id].clk)){dev_err(dev,"failed to get gce clk: %d\n",alias_id);
--
2.33.0.882.g93a45727a2-goog
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
On Thu, Oct 14, 2021 at 05:31:10PM +0800, Fei Shao wrote:
of_alias_get_id() may return -ENODEV which leads to illegal access to
the cmdq->clocks array.
Adding a check over alias_id to prevent the unexpected behavior.
Fixes: 85dfdbfc13ea ("mailbox: cmdq: add multi-gce clocks support for
mt8195")
Signed-off-by: Fei Shao <redacted>
Probably better to keep their scope in probe function but extend the
lifecycle by using static.
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel