Commit c818a94c authored by Thierry Reding's avatar Thierry Reding Committed by Felipe Balbi

usb: phy: Restore deferred probing path

Commit 1290a958 ("usb: phy: propagate __of_usb_find_phy()'s error on
failure") broke platforms that rely on deferred probing to order probing
of PHY and host controller drivers. The reason is that the commit simply
propagates errors from __of_usb_find_phy(), which returns -ENODEV if no
PHY has been registered yet for a given device tree node. The only case
in which -EPROBE_DEFER would now be returned is if try_module_get() did
fail, which does not make sense.

The correct thing to do is to return -EPROBE_DEFER if a PHY hasn't been
registered yet. The only condition under which it makes sense to return
-ENODEV is if the device tree node representing the PHY has been
disabled (via the status property) because in that case the PHY will
never be registered.

This patch addresses the problem by making __of_usb_find_phy() return an
appropriate error code while keeping in line with the above-mentioned
commit to propagate error codes rather than overwriting them. At the
same time the check for a valid PHY is decoupled from the check for the
try_module_get() call and a separate error code is returned if the
latter fails.

Fixes: 1290a958 (usb: phy: propagate __of_usb_find_phy()'s error on failure)
Signed-off-by: default avatarThierry Reding <treding@nvidia.com>
Signed-off-by: default avatarFelipe Balbi <balbi@ti.com>
parent 6785a103
......@@ -59,6 +59,9 @@ static struct usb_phy *__of_usb_find_phy(struct device_node *node)
{
struct usb_phy *phy;
if (!of_device_is_available(node))
return ERR_PTR(-ENODEV);
list_for_each_entry(phy, &phy_list, head) {
if (node != phy->dev->of_node)
continue;
......@@ -66,7 +69,7 @@ static struct usb_phy *__of_usb_find_phy(struct device_node *node)
return phy;
}
return ERR_PTR(-ENODEV);
return ERR_PTR(-EPROBE_DEFER);
}
static void devm_usb_phy_release(struct device *dev, void *res)
......@@ -190,10 +193,13 @@ struct usb_phy *devm_usb_get_phy_by_phandle(struct device *dev,
spin_lock_irqsave(&phy_lock, flags);
phy = __of_usb_find_phy(node);
if (IS_ERR(phy) || !try_module_get(phy->dev->driver->owner)) {
if (!IS_ERR(phy))
phy = ERR_PTR(-EPROBE_DEFER);
if (IS_ERR(phy)) {
devres_free(ptr);
goto err1;
}
if (!try_module_get(phy->dev->driver->owner)) {
phy = ERR_PTR(-ENODEV);
devres_free(ptr);
goto err1;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment