Skip to content

Commit 97712f8

Browse files
committed
Merge branch 'mdio-fixes'
Saravana Kannan says: ==================== Clean up and fix error handling in mdio_mux_init() This patch series was started due to -EPROBE_DEFER not being handled correctly in mdio_mux_init() and causing issues [1]. While at it, I also did some more error handling fixes and clean ups. The -EPROBE_DEFER fix is the last patch. Ideally, in the last patch we'd treat any error similar to -EPROBE_DEFER but I'm not sure if it'll break any board/platforms where some child mdiobus never successfully registers. If we treated all errors similar to -EPROBE_DEFER, then none of the child mdiobus will work and that might be a regression. If people are sure this is not a real case, then I can fix up the last patch to always fail the entire mdio-mux init if any of the child mdiobus registration fails. ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents ed5d293 + 7bd0cef commit 97712f8

File tree

1 file changed

+24
-13
lines changed

1 file changed

+24
-13
lines changed

drivers/net/mdio/mdio-mux.c

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,17 @@ static int mdio_mux_write(struct mii_bus *bus, int phy_id,
8282

8383
static int parent_count;
8484

85+
static void mdio_mux_uninit_children(struct mdio_mux_parent_bus *pb)
86+
{
87+
struct mdio_mux_child_bus *cb = pb->children;
88+
89+
while (cb) {
90+
mdiobus_unregister(cb->mii_bus);
91+
mdiobus_free(cb->mii_bus);
92+
cb = cb->next;
93+
}
94+
}
95+
8596
int mdio_mux_init(struct device *dev,
8697
struct device_node *mux_node,
8798
int (*switch_fn)(int cur, int desired, void *data),
@@ -144,16 +155,15 @@ int mdio_mux_init(struct device *dev,
144155
cb = devm_kzalloc(dev, sizeof(*cb), GFP_KERNEL);
145156
if (!cb) {
146157
ret_val = -ENOMEM;
147-
continue;
158+
goto err_loop;
148159
}
149160
cb->bus_number = v;
150161
cb->parent = pb;
151162

152163
cb->mii_bus = mdiobus_alloc();
153164
if (!cb->mii_bus) {
154165
ret_val = -ENOMEM;
155-
devm_kfree(dev, cb);
156-
continue;
166+
goto err_loop;
157167
}
158168
cb->mii_bus->priv = cb;
159169

@@ -165,11 +175,15 @@ int mdio_mux_init(struct device *dev,
165175
cb->mii_bus->write = mdio_mux_write;
166176
r = of_mdiobus_register(cb->mii_bus, child_bus_node);
167177
if (r) {
178+
mdiobus_free(cb->mii_bus);
179+
if (r == -EPROBE_DEFER) {
180+
ret_val = r;
181+
goto err_loop;
182+
}
183+
devm_kfree(dev, cb);
168184
dev_err(dev,
169185
"Error: Failed to register MDIO bus for child %pOF\n",
170186
child_bus_node);
171-
mdiobus_free(cb->mii_bus);
172-
devm_kfree(dev, cb);
173187
} else {
174188
cb->next = pb->children;
175189
pb->children = cb;
@@ -181,7 +195,10 @@ int mdio_mux_init(struct device *dev,
181195
}
182196

183197
dev_err(dev, "Error: No acceptable child buses found\n");
184-
devm_kfree(dev, pb);
198+
199+
err_loop:
200+
mdio_mux_uninit_children(pb);
201+
of_node_put(child_bus_node);
185202
err_pb_kz:
186203
put_device(&parent_bus->dev);
187204
err_parent_bus:
@@ -193,14 +210,8 @@ EXPORT_SYMBOL_GPL(mdio_mux_init);
193210
void mdio_mux_uninit(void *mux_handle)
194211
{
195212
struct mdio_mux_parent_bus *pb = mux_handle;
196-
struct mdio_mux_child_bus *cb = pb->children;
197-
198-
while (cb) {
199-
mdiobus_unregister(cb->mii_bus);
200-
mdiobus_free(cb->mii_bus);
201-
cb = cb->next;
202-
}
203213

214+
mdio_mux_uninit_children(pb);
204215
put_device(&pb->mii_bus->dev);
205216
}
206217
EXPORT_SYMBOL_GPL(mdio_mux_uninit);

0 commit comments

Comments
 (0)