Commit 29b44a38 authored by Krzysztof Kozlowski's avatar Krzysztof Kozlowski Committed by Vinod Koul

phy: ti: am654-serdes: Use scoped device node handling to simplify error paths

Obtain the device node reference with scoped/cleanup.h to reduce error
handling and make the code a bit simpler.

Unlike in other typical of_node_get+syscon_node_to_regmap cases, the
reference cannot be dropped immediately after syscon_node_to_regmap(),
because further part of probe() uses it.
Signed-off-by: default avatarKrzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Link: https://lore.kernel.org/r/20240826-phy-of-node-scope-v1-8-5b4d82582644@linaro.orgSigned-off-by: default avatarVinod Koul <vkoul@kernel.org>
parent 608863e1
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
*/ */
#include <dt-bindings/phy/phy.h> #include <dt-bindings/phy/phy.h>
#include <linux/cleanup.h>
#include <linux/clk.h> #include <linux/clk.h>
#include <linux/clk-provider.h> #include <linux/clk-provider.h>
#include <linux/delay.h> #include <linux/delay.h>
...@@ -644,7 +645,6 @@ static int serdes_am654_clk_register(struct serdes_am654 *am654_phy, ...@@ -644,7 +645,6 @@ static int serdes_am654_clk_register(struct serdes_am654 *am654_phy,
struct device_node *node = am654_phy->of_node; struct device_node *node = am654_phy->of_node;
struct device *dev = am654_phy->dev; struct device *dev = am654_phy->dev;
struct serdes_am654_clk_mux *mux; struct serdes_am654_clk_mux *mux;
struct device_node *regmap_node;
const char **parent_names; const char **parent_names;
struct clk_init_data *init; struct clk_init_data *init;
unsigned int num_parents; unsigned int num_parents;
...@@ -652,7 +652,6 @@ static int serdes_am654_clk_register(struct serdes_am654 *am654_phy, ...@@ -652,7 +652,6 @@ 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)
...@@ -660,41 +659,30 @@ static int serdes_am654_clk_register(struct serdes_am654 *am654_phy, ...@@ -660,41 +659,30 @@ 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); struct device_node *regmap_node __free(device_node) =
if (!regmap_node) { of_parse_phandle(node, "ti,serdes-clk", 0);
dev_err(dev, "Fail to get serdes-clk node\n"); if (!regmap_node)
ret = -ENODEV; return dev_err_probe(dev, -ENODEV, "Fail to get serdes-clk node\n");
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"); return dev_err_probe(dev, PTR_ERR(regmap),
ret = PTR_ERR(regmap); "Fail to get Syscon regmap\n");
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"); return dev_err_probe(dev, -EINVAL, "SERDES clock must have parents\n");
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)
ret = -ENOMEM; return -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)
ret = -EINVAL; return -EINVAL;
goto out_put_node;
}
reg = be32_to_cpu(*addr); reg = be32_to_cpu(*addr);
...@@ -710,16 +698,12 @@ static int serdes_am654_clk_register(struct serdes_am654 *am654_phy, ...@@ -710,16 +698,12 @@ 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))
ret = PTR_ERR(clk); return PTR_ERR(clk);
goto out_put_node;
}
am654_phy->clks[clock_num] = clk; am654_phy->clks[clock_num] = clk;
out_put_node: return 0;
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