Skip to content

Commit 342fa19

Browse files
Jon Masondavem330
authored andcommitted
mdio: mux: make child bus walking more permissive and errors more verbose
If any errors are encountered while walking the device tree structure of the MDIO bus for children, the code may silently continue, silently exit, or throw an error and exit. This make it difficult for device tree writers to know there is an error. Also, it makes any error in a child entry of the MDIO bus be fatal for all entries. Instead, we should provide verbose errors describing the error and then attempt to continue if it all possible. Also, use of_mdio_parse_addr() Signed-off-by: Jon Mason <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent e8317a4 commit 342fa19

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

drivers/net/phy/mdio-mux.c

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -135,27 +135,33 @@ int mdio_mux_init(struct device *dev,
135135
for_each_available_child_of_node(dev->of_node, child_bus_node) {
136136
u32 v;
137137

138-
r = of_property_read_u32(child_bus_node, "reg", &v);
139-
if (r)
138+
v = of_mdio_parse_addr(dev, child_bus_node);
139+
if (v < 0) {
140+
dev_err(dev,
141+
"Error: Failed to find reg for child %s\n",
142+
of_node_full_name(child_bus_node));
140143
continue;
144+
}
141145

142146
cb = devm_kzalloc(dev, sizeof(*cb), GFP_KERNEL);
143147
if (cb == NULL) {
144148
dev_err(dev,
145-
"Error: Failed to allocate memory for child\n");
149+
"Error: Failed to allocate memory for child %s\n",
150+
of_node_full_name(child_bus_node));
146151
ret_val = -ENOMEM;
147-
of_node_put(child_bus_node);
148-
break;
152+
continue;
149153
}
150154
cb->bus_number = v;
151155
cb->parent = pb;
152156

153157
cb->mii_bus = mdiobus_alloc();
154158
if (!cb->mii_bus) {
159+
dev_err(dev,
160+
"Error: Failed to allocate MDIO bus for child %s\n",
161+
of_node_full_name(child_bus_node));
155162
ret_val = -ENOMEM;
156163
devm_kfree(dev, cb);
157-
of_node_put(child_bus_node);
158-
break;
164+
continue;
159165
}
160166
cb->mii_bus->priv = cb;
161167

@@ -167,6 +173,9 @@ int mdio_mux_init(struct device *dev,
167173
cb->mii_bus->write = mdio_mux_write;
168174
r = of_mdiobus_register(cb->mii_bus, child_bus_node);
169175
if (r) {
176+
dev_err(dev,
177+
"Error: Failed to register MDIO bus for child %s\n",
178+
of_node_full_name(child_bus_node));
170179
mdiobus_free(cb->mii_bus);
171180
devm_kfree(dev, cb);
172181
} else {
@@ -180,6 +189,7 @@ int mdio_mux_init(struct device *dev,
180189
return 0;
181190
}
182191

192+
dev_err(dev, "Error: No acceptable child buses found\n");
183193
devm_kfree(dev, pb);
184194
err_pb_kz:
185195
/* balance the reference of_mdio_find_bus() took */

0 commit comments

Comments
 (0)