From 3b64c4cead5531ba84370c5381106777b980a75b Mon Sep 17 00:00:00 2001 From: Jack Pham Date: Mon, 26 Sep 2016 10:33:20 -0700 Subject: usb: pd: Return different errors in devm_usbpd_get_by_phandle() Allow callers of devm_usbpd_get_by_phandle() to distinguish between different errors depending on what failure is encountered. For instance, return -EPROBE_DEFER if the device is available but not yet probed, which allows callers to appropriately try again later. Change-Id: I96b03d0a4c2a04a405af5a40f9f713443bc5769b Signed-off-by: Jack Pham --- drivers/usb/pd/policy_engine.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'drivers/usb/pd') diff --git a/drivers/usb/pd/policy_engine.c b/drivers/usb/pd/policy_engine.c index 1bb7082be8e6..03717c34d362 100644 --- a/drivers/usb/pd/policy_engine.c +++ b/drivers/usb/pd/policy_engine.c @@ -2228,12 +2228,15 @@ struct usbpd *devm_usbpd_get_by_phandle(struct device *dev, const char *phandle) struct platform_device *pdev; struct device *pd_dev; + if (!usbpd_class.p) /* usbpd_init() not yet called */ + return ERR_PTR(-EAGAIN); + if (!dev->of_node) - return ERR_PTR(-ENODEV); + return ERR_PTR(-EINVAL); pd_np = of_parse_phandle(dev->of_node, phandle, 0); if (!pd_np) - return ERR_PTR(-ENODEV); + return ERR_PTR(-ENXIO); pdev = of_find_device_by_node(pd_np); if (!pdev) @@ -2243,7 +2246,8 @@ struct usbpd *devm_usbpd_get_by_phandle(struct device *dev, const char *phandle) match_usbpd_device); if (!pd_dev) { platform_device_put(pdev); - return ERR_PTR(-ENODEV); + /* device was found but maybe hadn't probed yet, so defer */ + return ERR_PTR(-EPROBE_DEFER); } ptr = devres_alloc(devm_usbpd_put, sizeof(*ptr), GFP_KERNEL); @@ -2255,7 +2259,7 @@ struct usbpd *devm_usbpd_get_by_phandle(struct device *dev, const char *phandle) pd = dev_get_drvdata(pd_dev); if (!pd) - return ERR_PTR(-ENODEV); + return ERR_PTR(-EPROBE_DEFER); *ptr = pd; devres_add(dev, ptr); -- cgit v1.2.3