Commit 3e644828 authored by Wen Yang's avatar Wen Yang Committed by Kishon Vijay Abraham I

phy: ti: am654-serdes: fix an use-after-free in serdes_am654_clk_register()

The regmap_node variable is still being used in the syscon_node_to_regmap()
call after the of_node_put() call, which may result in use-after-free.

Fixes: 71e2f5c5 ("phy: ti: Add a new SERDES driver for TI's AM654x SoC")
Signed-off-by: default avatarWen Yang <wen.yang99@zte.com.cn>
Cc: Kishon Vijay Abraham I <kishon@ti.com>
Cc: Roger Quadros <rogerq@ti.com>
Reviewed-by: default avatarRoger Quadros <rogerq@ti.com>
Signed-off-by: default avatarKishon Vijay Abraham I <kishon@ti.com>
parent cacc9539
...@@ -405,6 +405,7 @@ static int serdes_am654_clk_register(struct serdes_am654 *am654_phy, ...@@ -405,6 +405,7 @@ static int serdes_am654_clk_register(struct serdes_am654 *am654_phy,
const __be32 *addr; const __be32 *addr;
unsigned int reg; unsigned int reg;
struct clk *clk; struct clk *clk;
int ret = 0;
mux = devm_kzalloc(dev, sizeof(*mux), GFP_KERNEL); mux = devm_kzalloc(dev, sizeof(*mux), GFP_KERNEL);
if (!mux) if (!mux)
...@@ -413,34 +414,40 @@ static int serdes_am654_clk_register(struct serdes_am654 *am654_phy, ...@@ -413,34 +414,40 @@ static int serdes_am654_clk_register(struct serdes_am654 *am654_phy,
init = &mux->clk_data; init = &mux->clk_data;
regmap_node = of_parse_phandle(node, "ti,serdes-clk", 0); regmap_node = of_parse_phandle(node, "ti,serdes-clk", 0);
of_node_put(regmap_node);
if (!regmap_node) { if (!regmap_node) {
dev_err(dev, "Fail to get serdes-clk node\n"); dev_err(dev, "Fail to get serdes-clk node\n");
return -ENODEV; ret = -ENODEV;
goto out_put_node;
} }
regmap = syscon_node_to_regmap(regmap_node->parent); regmap = syscon_node_to_regmap(regmap_node->parent);
if (IS_ERR(regmap)) { if (IS_ERR(regmap)) {
dev_err(dev, "Fail to get Syscon regmap\n"); dev_err(dev, "Fail to get Syscon regmap\n");
return PTR_ERR(regmap); ret = PTR_ERR(regmap);
goto out_put_node;
} }
num_parents = of_clk_get_parent_count(node); num_parents = of_clk_get_parent_count(node);
if (num_parents < 2) { if (num_parents < 2) {
dev_err(dev, "SERDES clock must have parents\n"); dev_err(dev, "SERDES clock must have parents\n");
return -EINVAL; ret = -EINVAL;
goto out_put_node;
} }
parent_names = devm_kzalloc(dev, (sizeof(char *) * num_parents), parent_names = devm_kzalloc(dev, (sizeof(char *) * num_parents),
GFP_KERNEL); GFP_KERNEL);
if (!parent_names) if (!parent_names) {
return -ENOMEM; ret = -ENOMEM;
goto out_put_node;
}
of_clk_parent_fill(node, parent_names, num_parents); of_clk_parent_fill(node, parent_names, num_parents);
addr = of_get_address(regmap_node, 0, NULL, NULL); addr = of_get_address(regmap_node, 0, NULL, NULL);
if (!addr) if (!addr) {
return -EINVAL; ret = -EINVAL;
goto out_put_node;
}
reg = be32_to_cpu(*addr); reg = be32_to_cpu(*addr);
...@@ -456,12 +463,16 @@ static int serdes_am654_clk_register(struct serdes_am654 *am654_phy, ...@@ -456,12 +463,16 @@ static int serdes_am654_clk_register(struct serdes_am654 *am654_phy,
mux->hw.init = init; mux->hw.init = init;
clk = devm_clk_register(dev, &mux->hw); clk = devm_clk_register(dev, &mux->hw);
if (IS_ERR(clk)) if (IS_ERR(clk)) {
return PTR_ERR(clk); ret = PTR_ERR(clk);
goto out_put_node;
}
am654_phy->clks[clock_num] = clk; am654_phy->clks[clock_num] = clk;
return 0; out_put_node:
of_node_put(regmap_node);
return ret;
} }
static const struct of_device_id serdes_am654_id_table[] = { static const struct of_device_id serdes_am654_id_table[] = {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment