Skip to content

Commit 99d81e9

Browse files
Saravana Kannandavem330
authored andcommitted
net: mdio-mux: Don't ignore memory allocation errors
If we are seeing memory allocation errors, don't try to continue registering child mdiobus devices. It's unlikely they'll succeed. Fixes: 342fa19 ("mdio: mux: make child bus walking more permissive and errors more verbose") Signed-off-by: Saravana Kannan <[email protected]> Reviewed-by: Andrew Lunn <[email protected]> Acked-by: Marc Zyngier <[email protected]> Tested-by: Marc Zyngier <[email protected]> Acked-by: Kevin Hilman <[email protected]> Tested-by: Kevin Hilman <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 663d946 commit 99d81e9

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

drivers/net/mdio/mdio-mux.c

Lines changed: 18 additions & 10 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

@@ -181,6 +191,10 @@ int mdio_mux_init(struct device *dev,
181191
}
182192

183193
dev_err(dev, "Error: No acceptable child buses found\n");
194+
195+
err_loop:
196+
mdio_mux_uninit_children(pb);
197+
of_node_put(child_bus_node);
184198
err_pb_kz:
185199
put_device(&parent_bus->dev);
186200
err_parent_bus:
@@ -192,14 +206,8 @@ EXPORT_SYMBOL_GPL(mdio_mux_init);
192206
void mdio_mux_uninit(void *mux_handle)
193207
{
194208
struct mdio_mux_parent_bus *pb = mux_handle;
195-
struct mdio_mux_child_bus *cb = pb->children;
196-
197-
while (cb) {
198-
mdiobus_unregister(cb->mii_bus);
199-
mdiobus_free(cb->mii_bus);
200-
cb = cb->next;
201-
}
202209

210+
mdio_mux_uninit_children(pb);
203211
put_device(&pb->mii_bus->dev);
204212
}
205213
EXPORT_SYMBOL_GPL(mdio_mux_uninit);

0 commit comments

Comments
 (0)