]> git.baikalelectronics.ru Git - kernel.git/commit
net: phy: Fix PHY module checks and NULL deref in phy_attach_direct()
authorFlorian Fainelli <f.fainelli@gmail.com>
Thu, 9 Feb 2017 03:05:26 +0000 (19:05 -0800)
committerDavid S. Miller <davem@davemloft.net>
Thu, 9 Feb 2017 21:22:12 +0000 (16:22 -0500)
commita4bc33fd3f10adac06ddb8949574a9d3d5449876
treeeee88d8cc491a121d8c587caebd7503fd5bb03e5
parent000b15ee0d5fb91bbe82ae87b56c2a5ffb40adb6
net: phy: Fix PHY module checks and NULL deref in phy_attach_direct()

The Generic PHY drivers gets assigned after we checked that the current
PHY driver is NULL, so we need to check a few things before we can
safely dereference d->driver. This would be causing a NULL deference to
occur when a system binds to the Generic PHY driver. Update
phy_attach_direct() to do the following:

- grab the driver module reference after we have assigned the Generic
  PHY drivers accordingly, and remember we came from the generic PHY
  path

- update the error path to clean up the module reference in case the
  Generic PHY probe function fails

- split the error path involving phy_detacht() to avoid double free/put
  since phy_detach() does all the clean up

- finally, have phy_detach() drop the module reference count before we
  call device_release_driver() for the Generic PHY driver case

Fixes: 1a7f30949843 ("net: phy: Fix lack of reference count on PHY driver")
Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/phy/phy_device.c