diff mbox series

[3/5] PCI: armada8x: Properly handle optional PHYs

Message ID 20190828163636.12967-3-thierry.reding@gmail.com (mailing list archive)
State Mainlined, archived
Commit e7a877b2fa79c57c3eac7d28803279a356844907
Headers show
Series [1/5] PCI: exynos: Properly handle optional PHYs | expand

Commit Message

Thierry Reding Aug. 28, 2019, 4:36 p.m. UTC
From: Thierry Reding <treding@nvidia.com>

devm_of_phy_get_by_index() can fail for a number of resides besides
probe deferral. It can for example return -ENOMEM if it runs out of
memory as it tries to allocate devres structures. Propagating only
-EPROBE_DEFER is problematic because it results in these legitimately
fatal errors being treated as "PHY not specified in DT".

What we really want is to ignore the optional PHYs only if they have not
been specified in DT. devm_of_phy_get_by_index() returns -ENODEV in this
case, so that's the special case that we need to handle. So we propagate
all errors, except -ENODEV, so that real failures will still cause the
driver to fail probe.

Cc: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
Signed-off-by: Thierry Reding <treding@nvidia.com>
---
 drivers/pci/controller/dwc/pcie-armada8k.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

Comments

Andrew Murray Aug. 28, 2019, 9:09 p.m. UTC | #1
On Wed, Aug 28, 2019 at 06:36:34PM +0200, Thierry Reding wrote:
> From: Thierry Reding <treding@nvidia.com>
> 
> devm_of_phy_get_by_index() can fail for a number of resides besides
> probe deferral. It can for example return -ENOMEM if it runs out of
> memory as it tries to allocate devres structures. Propagating only
> -EPROBE_DEFER is problematic because it results in these legitimately
> fatal errors being treated as "PHY not specified in DT".
> 
> What we really want is to ignore the optional PHYs only if they have not
> been specified in DT. devm_of_phy_get_by_index() returns -ENODEV in this
> case, so that's the special case that we need to handle. So we propagate
> all errors, except -ENODEV, so that real failures will still cause the
> driver to fail probe.
> 
> Cc: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
> Signed-off-by: Thierry Reding <treding@nvidia.com>
> ---
>  drivers/pci/controller/dwc/pcie-armada8k.c | 7 +++----
>  1 file changed, 3 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/pci/controller/dwc/pcie-armada8k.c b/drivers/pci/controller/dwc/pcie-armada8k.c
> index 3d55dc78d999..49596547e8c2 100644
> --- a/drivers/pci/controller/dwc/pcie-armada8k.c
> +++ b/drivers/pci/controller/dwc/pcie-armada8k.c
> @@ -118,11 +118,10 @@ static int armada8k_pcie_setup_phys(struct armada8k_pcie *pcie)
>  
>  	for (i = 0; i < ARMADA8K_PCIE_MAX_LANES; i++) {
>  		pcie->phy[i] = devm_of_phy_get_by_index(dev, node, i);
> -		if (IS_ERR(pcie->phy[i]) &&
> -		    (PTR_ERR(pcie->phy[i]) == -EPROBE_DEFER))
> -			return PTR_ERR(pcie->phy[i]);
> -
>  		if (IS_ERR(pcie->phy[i])) {
> +			if (PTR_ERR(pcie->phy[i]) != -ENODEV)
> +				return PTR_ERR(pcie->phy[i]);
> +

Once you've applied Bjorn's feedback you can add:

Reviewed-by: Andrew Murray <andrew.murray@arm.com>

>  			pcie->phy[i] = NULL;
>  			continue;
>  		}
> -- 
> 2.22.0
>
diff mbox series

Patch

diff --git a/drivers/pci/controller/dwc/pcie-armada8k.c b/drivers/pci/controller/dwc/pcie-armada8k.c
index 3d55dc78d999..49596547e8c2 100644
--- a/drivers/pci/controller/dwc/pcie-armada8k.c
+++ b/drivers/pci/controller/dwc/pcie-armada8k.c
@@ -118,11 +118,10 @@  static int armada8k_pcie_setup_phys(struct armada8k_pcie *pcie)
 
 	for (i = 0; i < ARMADA8K_PCIE_MAX_LANES; i++) {
 		pcie->phy[i] = devm_of_phy_get_by_index(dev, node, i);
-		if (IS_ERR(pcie->phy[i]) &&
-		    (PTR_ERR(pcie->phy[i]) == -EPROBE_DEFER))
-			return PTR_ERR(pcie->phy[i]);
-
 		if (IS_ERR(pcie->phy[i])) {
+			if (PTR_ERR(pcie->phy[i]) != -ENODEV)
+				return PTR_ERR(pcie->phy[i]);
+
 			pcie->phy[i] = NULL;
 			continue;
 		}