Skip to content

Commit 29b44a3

Browse files
krzkvinodkoul
authored andcommitted
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: Krzysztof Kozlowski <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Vinod Koul <[email protected]>
1 parent 608863e commit 29b44a3

File tree

1 file changed

+17
-33
lines changed

1 file changed

+17
-33
lines changed

drivers/phy/ti/phy-am654-serdes.c

Lines changed: 17 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*/
88

99
#include <dt-bindings/phy/phy.h>
10+
#include <linux/cleanup.h>
1011
#include <linux/clk.h>
1112
#include <linux/clk-provider.h>
1213
#include <linux/delay.h>
@@ -644,57 +645,44 @@ static int serdes_am654_clk_register(struct serdes_am654 *am654_phy,
644645
struct device_node *node = am654_phy->of_node;
645646
struct device *dev = am654_phy->dev;
646647
struct serdes_am654_clk_mux *mux;
647-
struct device_node *regmap_node;
648648
const char **parent_names;
649649
struct clk_init_data *init;
650650
unsigned int num_parents;
651651
struct regmap *regmap;
652652
const __be32 *addr;
653653
unsigned int reg;
654654
struct clk *clk;
655-
int ret = 0;
656655

657656
mux = devm_kzalloc(dev, sizeof(*mux), GFP_KERNEL);
658657
if (!mux)
659658
return -ENOMEM;
660659

661660
init = &mux->clk_data;
662661

663-
regmap_node = of_parse_phandle(node, "ti,serdes-clk", 0);
664-
if (!regmap_node) {
665-
dev_err(dev, "Fail to get serdes-clk node\n");
666-
ret = -ENODEV;
667-
goto out_put_node;
668-
}
662+
struct device_node *regmap_node __free(device_node) =
663+
of_parse_phandle(node, "ti,serdes-clk", 0);
664+
if (!regmap_node)
665+
return dev_err_probe(dev, -ENODEV, "Fail to get serdes-clk node\n");
669666

670667
regmap = syscon_node_to_regmap(regmap_node->parent);
671-
if (IS_ERR(regmap)) {
672-
dev_err(dev, "Fail to get Syscon regmap\n");
673-
ret = PTR_ERR(regmap);
674-
goto out_put_node;
675-
}
668+
if (IS_ERR(regmap))
669+
return dev_err_probe(dev, PTR_ERR(regmap),
670+
"Fail to get Syscon regmap\n");
676671

677672
num_parents = of_clk_get_parent_count(node);
678-
if (num_parents < 2) {
679-
dev_err(dev, "SERDES clock must have parents\n");
680-
ret = -EINVAL;
681-
goto out_put_node;
682-
}
673+
if (num_parents < 2)
674+
return dev_err_probe(dev, -EINVAL, "SERDES clock must have parents\n");
683675

684676
parent_names = devm_kzalloc(dev, (sizeof(char *) * num_parents),
685677
GFP_KERNEL);
686-
if (!parent_names) {
687-
ret = -ENOMEM;
688-
goto out_put_node;
689-
}
678+
if (!parent_names)
679+
return -ENOMEM;
690680

691681
of_clk_parent_fill(node, parent_names, num_parents);
692682

693683
addr = of_get_address(regmap_node, 0, NULL, NULL);
694-
if (!addr) {
695-
ret = -EINVAL;
696-
goto out_put_node;
697-
}
684+
if (!addr)
685+
return -EINVAL;
698686

699687
reg = be32_to_cpu(*addr);
700688

@@ -710,16 +698,12 @@ static int serdes_am654_clk_register(struct serdes_am654 *am654_phy,
710698
mux->hw.init = init;
711699

712700
clk = devm_clk_register(dev, &mux->hw);
713-
if (IS_ERR(clk)) {
714-
ret = PTR_ERR(clk);
715-
goto out_put_node;
716-
}
701+
if (IS_ERR(clk))
702+
return PTR_ERR(clk);
717703

718704
am654_phy->clks[clock_num] = clk;
719705

720-
out_put_node:
721-
of_node_put(regmap_node);
722-
return ret;
706+
return 0;
723707
}
724708

725709
static const struct of_device_id serdes_am654_id_table[] = {

0 commit comments

Comments
 (0)