Skip to content

Commit b601616

Browse files
Jon Masondavem330
authored andcommitted
mdio: mux: Correct mdio_mux_init error path issues
There is a potential unnecessary refcount decrement on error path of put_device(&pb->mii_bus->dev), as it is possible to avoid the of_mdio_find_bus() call if mux_bus is specified by the calling function. The same put_device() is not called in the error path if the devm_kzalloc of pb fails. This caused the variable used in the put_device() to be changed, as the pb pointer was obviously not set up. There is an unnecessary of_node_get() on child_bus_node if the of_mdiobus_register() is successful, as the for_each_available_child_of_node() automatically increments this. Thus the refcount on this node will always be +1 more than it should be. There is no of_node_put() on child_bus_node if the of_mdiobus_register() call fails. Finally, it is lacking devm_kfree() of pb in the error path. While this might not be technically necessary, it was present in other parts of the function. So, I am adding it where necessary to make it uniform. Signed-off-by: Jon Mason <jon.mason@broadcom.com> Fixes: f20e665 ("mdio: mux: Enhanced MDIO mux framework for integrated multiplexers") Fixes: 0ca2997 ("netdev/of/phy: Add MDIO bus multiplexer support.") Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 83eadda commit b601616

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

drivers/net/phy/mdio-mux.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,9 @@ int mdio_mux_init(struct device *dev,
122122
pb = devm_kzalloc(dev, sizeof(*pb), GFP_KERNEL);
123123
if (pb == NULL) {
124124
ret_val = -ENOMEM;
125-
goto err_parent_bus;
125+
goto err_pb_kz;
126126
}
127127

128-
129128
pb->switch_data = data;
130129
pb->switch_fn = switch_fn;
131130
pb->current_child = -1;
@@ -154,6 +153,7 @@ int mdio_mux_init(struct device *dev,
154153
cb->mii_bus = mdiobus_alloc();
155154
if (!cb->mii_bus) {
156155
ret_val = -ENOMEM;
156+
devm_kfree(dev, cb);
157157
of_node_put(child_bus_node);
158158
break;
159159
}
@@ -169,8 +169,8 @@ int mdio_mux_init(struct device *dev,
169169
if (r) {
170170
mdiobus_free(cb->mii_bus);
171171
devm_kfree(dev, cb);
172+
of_node_put(child_bus_node);
172173
} else {
173-
of_node_get(child_bus_node);
174174
cb->next = pb->children;
175175
pb->children = cb;
176176
}
@@ -181,9 +181,11 @@ int mdio_mux_init(struct device *dev,
181181
return 0;
182182
}
183183

184+
devm_kfree(dev, pb);
185+
err_pb_kz:
184186
/* balance the reference of_mdio_find_bus() took */
185-
put_device(&pb->mii_bus->dev);
186-
187+
if (!mux_bus)
188+
put_device(&parent_bus->dev);
187189
err_parent_bus:
188190
of_node_put(parent_bus_node);
189191
return ret_val;

0 commit comments

Comments
 (0)