Skip to content

Commit f6f31af

Browse files
JuliaLawallkishon
authored andcommitted
phy: rockchip-usb: add missing of_node_put
for_each_available_child_of_node performs an of_node_get on each iteration, so a return from the middle of the loop requires an of_node_put. A simplified version of the semantic patch that finds this problem is as follows (http://coccinelle.lip6.fr): // <smpl> @@ expression root,e; local idexpression child; @@ for_each_available_child_of_node(root, child) { ... when != of_node_put(child) when != e = child ( return child; | * return ...; ) ... } // </smpl> Signed-off-by: Julia Lawall <[email protected]> Reviewed-by: Heiko Stuebner <[email protected]> Tested-by: Heiko Stuebner <[email protected]> Signed-off-by: Kishon Vijay Abraham I <[email protected]>
1 parent d0ca576 commit f6f31af

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

drivers/phy/phy-rockchip-usb.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,16 @@ static int rockchip_usb_phy_probe(struct platform_device *pdev)
108108

109109
for_each_available_child_of_node(dev->of_node, child) {
110110
rk_phy = devm_kzalloc(dev, sizeof(*rk_phy), GFP_KERNEL);
111-
if (!rk_phy)
112-
return -ENOMEM;
111+
if (!rk_phy) {
112+
err = -ENOMEM;
113+
goto put_child;
114+
}
113115

114116
if (of_property_read_u32(child, "reg", &reg_offset)) {
115117
dev_err(dev, "missing reg property in node %s\n",
116118
child->name);
117-
return -EINVAL;
119+
err = -EINVAL;
120+
goto put_child;
118121
}
119122

120123
rk_phy->reg_offset = reg_offset;
@@ -127,18 +130,22 @@ static int rockchip_usb_phy_probe(struct platform_device *pdev)
127130
rk_phy->phy = devm_phy_create(dev, child, &ops);
128131
if (IS_ERR(rk_phy->phy)) {
129132
dev_err(dev, "failed to create PHY\n");
130-
return PTR_ERR(rk_phy->phy);
133+
err = PTR_ERR(rk_phy->phy);
134+
goto put_child;
131135
}
132136
phy_set_drvdata(rk_phy->phy, rk_phy);
133137

134138
/* only power up usb phy when it use, so disable it when init*/
135139
err = rockchip_usb_phy_power(rk_phy, 1);
136140
if (err)
137-
return err;
141+
goto put_child;
138142
}
139143

140144
phy_provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate);
141145
return PTR_ERR_OR_ZERO(phy_provider);
146+
put_child:
147+
of_node_put(child);
148+
return err;
142149
}
143150

144151
static const struct of_device_id rockchip_usb_phy_dt_ids[] = {

0 commit comments

Comments
 (0)