net: fix net_device refcounting
of_find_net_device_by_node() uses class_find_device() internally to lookup the corresponding network device. class_find_device() returns a reference to the embedded struct device, with its refcount incremented. Add a comment to the definition in net/core/net-sysfs.c indicating the need to drop this refcount, and fix the DSA code to drop this refcount when the OF-generated platform data is cleaned up and freed. Also arrange for the ref to be dropped when handling errors. Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
Родитель
38737e490d
Коммит
9861f72074
|
@ -1481,6 +1481,15 @@ static int of_dev_node_match(struct device *dev, const void *data)
|
||||||
return ret == 0 ? dev->of_node == data : ret;
|
return ret == 0 ? dev->of_node == data : ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* of_find_net_device_by_node - lookup the net device for the device node
|
||||||
|
* @np: OF device node
|
||||||
|
*
|
||||||
|
* Looks up the net_device structure corresponding with the device node.
|
||||||
|
* If successful, returns a pointer to the net_device with the embedded
|
||||||
|
* struct device refcount incremented by one, or NULL on failure. The
|
||||||
|
* refcount must be dropped when done with the net_device.
|
||||||
|
*/
|
||||||
struct net_device *of_find_net_device_by_node(struct device_node *np)
|
struct net_device *of_find_net_device_by_node(struct device_node *np)
|
||||||
{
|
{
|
||||||
struct device *dev;
|
struct device *dev;
|
||||||
|
|
|
@ -679,7 +679,7 @@ static int dsa_of_probe(struct device *dev)
|
||||||
pd = kzalloc(sizeof(*pd), GFP_KERNEL);
|
pd = kzalloc(sizeof(*pd), GFP_KERNEL);
|
||||||
if (!pd) {
|
if (!pd) {
|
||||||
ret = -ENOMEM;
|
ret = -ENOMEM;
|
||||||
goto out_put_mdio;
|
goto out_put_ethernet;
|
||||||
}
|
}
|
||||||
|
|
||||||
dev->platform_data = pd;
|
dev->platform_data = pd;
|
||||||
|
@ -773,6 +773,8 @@ out_free_chip:
|
||||||
out_free:
|
out_free:
|
||||||
kfree(pd);
|
kfree(pd);
|
||||||
dev->platform_data = NULL;
|
dev->platform_data = NULL;
|
||||||
|
out_put_ethernet:
|
||||||
|
put_device(ðernet_dev->dev);
|
||||||
out_put_mdio:
|
out_put_mdio:
|
||||||
put_device(&mdio_bus->dev);
|
put_device(&mdio_bus->dev);
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -786,6 +788,7 @@ static void dsa_of_remove(struct device *dev)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
dsa_of_free_platform_data(pd);
|
dsa_of_free_platform_data(pd);
|
||||||
|
put_device(&pd->of_netdev->dev);
|
||||||
kfree(pd);
|
kfree(pd);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
|
Загрузка…
Ссылка в новой задаче