]> git.kernelconcepts.de Git - karo-tx-linux.git/commit
net: dsa: fix of_mdio_find_bus() device refcount leak
authorRussell King <rmk+kernel@arm.linux.org.uk>
Thu, 24 Sep 2015 19:35:57 +0000 (20:35 +0100)
committerDavid S. Miller <davem@davemloft.net>
Fri, 25 Sep 2015 06:04:52 +0000 (23:04 -0700)
commite496ae690b2faff751e1849fb97b060615e21f28
treee32e9642246190efcb59077b698a6398928f0d65
parenta136442131443d929d2d8d243157824de4dfbae8
net: dsa: fix of_mdio_find_bus() device refcount leak

Current users of of_mdio_find_bus() leak a struct device refcount, as
they fail to clean up the reference obtained inside class_find_device().

Fix the DSA code to properly refcount the returned MDIO bus by:
1. taking a reference on the struct device whenever we assign it to
   pd->chip[x].host_dev.
2. dropping the reference when we overwrite the existing reference.
3. dropping the reference when we free the data structure.
4. dropping the initial reference we obtained after setting up the
   platform data structure, or on failure.

In step 2 above, where we obtain a new MDIO bus, there is no need to
take a reference on it as we would only have to drop it immediately
after assignment again, iow:

put_device(cd->host_dev); /* drop original assignment ref */
cd->host_dev = get_device(&mdio_bus_switch->dev); /* get our ref */
put_device(&mdio_bus_switch->dev); /* drop of_mdio_find_bus ref */

Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/dsa/dsa.c