PCI: rockchip: Properly handle optional regulators
PATCH 1/1 PCI: rockchip: Properly handle optional regulators
From: Thierry Reding <[email protected]>
regulator_get_optional() can fail for a number of reasons besides probe deferral. It can for example return -ENOMEM if it runs out of memory as it tries to allocate data structures. Propagating only -EPROBE_DEFER is problematic because it results in these legitimately fatal errors being treated as "regulator not specified in DT".
What we really want is to ignore the optional regulators only if they have not been specified in DT. regulator_get_optional() 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.
--- drivers/pci/controller/pcie-rockchip-host.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
drivers/pci/controller/pcie-rockchip-host.c +8 -8
@@ -608,29 +608,29 @@ static int rockchip_pcie_parse_host_dt(struct rockchip_pcie *rockchip) rockchip->vpcie12v =devm_regulator_get_optional (dev,"vpcie12v" );if (IS_ERR (rockchip->vpcie12v)) { -if (PTR_ERR (rockchip->vpcie12v) == -EPROBE_DEFER ) -return -EPROBE_DEFER ; +if (PTR_ERR (rockchip->vpcie12v) != -ENODEV ) +return PTR_ERR (rockchip->vpcie12v);dev_info (dev,"no vpcie12v regulator found\n" ); } rockchip->vpcie3v3 =devm_regulator_get_optional (dev,"vpcie3v3" );if (IS_ERR (rockchip->vpcie3v3)) { -if (PTR_ERR (rockchip->vpcie3v3) == -EPROBE_DEFER ) -return -EPROBE_DEFER ; +if (PTR_ERR (rockchip->vpcie3v3) != -ENODEV ) +return PTR_ERR (rockchip->vpcie3v3);dev_info (dev,"no vpcie3v3 regulator found\n" ); } rockchip->vpcie1v8 =devm_regulator_get_optional (dev,"vpcie1v8" );if (IS_ERR (rockchip->vpcie1v8)) { -if (PTR_ERR (rockchip->vpcie1v8) == -EPROBE_DEFER ) -return -EPROBE_DEFER ; +if (PTR_ERR (rockchip->vpcie1v8) != -ENODEV ) +return PTR_ERR (rockchip->vpcie1v8);dev_info (dev,"no vpcie1v8 regulator found\n" ); } rockchip->vpcie0v9 =devm_regulator_get_optional (dev,"vpcie0v9" );if (IS_ERR (rockchip->vpcie0v9)) { -if (PTR_ERR (rockchip->vpcie0v9) == -EPROBE_DEFER ) -return -EPROBE_DEFER ; +if (PTR_ERR (rockchip->vpcie0v9) != -ENODEV ) +return PTR_ERR (rockchip->vpcie0v9);dev_info (dev,"no vpcie0v9 regulator found\n" ); }
Signature · 1 line
2.22.0
Quoted 24 lines · Thierry Reding
From: Thierry Reding <[email protected]>
regulator_get_optional()can fail for a number of reasons besides probe deferral. It can for example return-ENOMEMif it runs out of memory as it tries to allocate data structures. Propagating only -EPROBE_DEFER is problematic because it results in these legitimately fatal errors being treated as "regulator not specified in DT".What we really want is to ignore the optional regulators only if they have not been specified in DT.
regulator_get_optional()returns-ENODEVin 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.Signed-off-by Thierry Reding <[email protected]>--- drivers/pci/controller/pcie-rockchip-host.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)drivers/pci/controller/pcie-rockchip-host.c +0
-0
drivers/pci/controller/pcie-rockchip-host.c static int rockchip_pcie_parse_host_dt(struct rockchip_pcie *rockchip) · line 613
Quoted 8 lines
drivers/pci/controller/pcie-rockchip-host.c +2
-2@@ -608,29 +608,29 @@ static int rockchip_pcie_parse_host_dt(struct rockchip_pcie *rockchip) rockchip->vpcie12v =devm_regulator_get_optional (dev,"vpcie12v" );if (IS_ERR (rockchip->vpcie12v)) { -if (PTR_ERR (rockchip->vpcie12v) == -EPROBE_DEFER ) -return -EPROBE_DEFER ; +if (PTR_ERR (rockchip->vpcie12v) != -ENODEV ) +return PTR_ERR (rockchip->vpcie12v);dev_info (dev,"no vpcie12v regulator found\n" );
In the event that -ENODEV is returned - we don't set vpcie12v to NULL, however it seems that this is OK as vpcie12v is tested with IS_ERR before use everywhere else in this file.
By the way it looks like this patch pattern could be applied right across the kernel, there are also others in PCI: pci-imx6 and pcie-histb.c - not sure if you wanted to fix those up too.
Quoted 32 lines
drivers/pci/controller/pcie-rockchip-host.c +6
-6} rockchip->vpcie3v3 =devm_regulator_get_optional (dev,"vpcie3v3" );if (IS_ERR (rockchip->vpcie3v3)) { -if (PTR_ERR (rockchip->vpcie3v3) == -EPROBE_DEFER ) -return -EPROBE_DEFER ; +if (PTR_ERR (rockchip->vpcie3v3) != -ENODEV ) +return PTR_ERR (rockchip->vpcie3v3);dev_info (dev,"no vpcie3v3 regulator found\n" ); } rockchip->vpcie1v8 =devm_regulator_get_optional (dev,"vpcie1v8" );if (IS_ERR (rockchip->vpcie1v8)) { -if (PTR_ERR (rockchip->vpcie1v8) == -EPROBE_DEFER ) -return -EPROBE_DEFER ; +if (PTR_ERR (rockchip->vpcie1v8) != -ENODEV ) +return PTR_ERR (rockchip->vpcie1v8);dev_info (dev,"no vpcie1v8 regulator found\n" ); } rockchip->vpcie0v9 =devm_regulator_get_optional (dev,"vpcie0v9" );if (IS_ERR (rockchip->vpcie0v9)) { -if (PTR_ERR (rockchip->vpcie0v9) == -EPROBE_DEFER ) -return -EPROBE_DEFER ; +if (PTR_ERR (rockchip->vpcie0v9) != -ENODEV ) +return PTR_ERR (rockchip->vpcie0v9);dev_info (dev,"no vpcie0v9 regulator found\n" ); }Signature · 1 line
2.22.0
Quoted 26 lines · Andrew Murray
Quoted 25 lines · Thierry Reding
From: Thierry Reding <[email protected]>
regulator_get_optional()can fail for a number of reasons besides probe deferral. It can for example return-ENOMEMif it runs out of memory as it tries to allocate data structures. Propagating only -EPROBE_DEFER is problematic because it results in these legitimately fatal errors being treated as "regulator not specified in DT".What we really want is to ignore the optional regulators only if they have not been specified in DT.
regulator_get_optional()returns-ENODEVin 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.Signed-off-by Thierry Reding <[email protected]>--- drivers/pci/controller/pcie-rockchip-host.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)drivers/pci/controller/pcie-rockchip-host.c +0
-0@@ -608,29 +608,29 @@ static int rockchip_pcie_parse_host_dt(struct rockchip_pcie *rockchip)
Quoted 11 lines
drivers/pci/controller/pcie-rockchip-host.c static int rockchip_pcie_parse_host_dt(struct rockchip_pcie *rockchip) · line 613
Quoted 7 lines
drivers/pci/controller/pcie-rockchip-host.c +2
-2rockchip->vpcie12v =devm_regulator_get_optional (dev,"vpcie12v" );if (IS_ERR (rockchip->vpcie12v)) { -if (PTR_ERR (rockchip->vpcie12v) == -EPROBE_DEFER ) -return -EPROBE_DEFER ; +if (PTR_ERR (rockchip->vpcie12v) != -ENODEV ) +return PTR_ERR (rockchip->vpcie12v);dev_info (dev,"no vpcie12v regulator found\n" );In the event that
-ENODEVis returned - we don't set vpcie12v to NULL, however it seems that this is OK as vpcie12v is tested withIS_ERRbefore use everywhere else in this file.
Yeah, I was trying to keep the diff small here. There doesn't seem to be any canonical way to mark regulators as "not available". This driver leaves it set as an error pointer, the Tegra PCI driver sets it to NULL. They're both valid ways to do it as long as they use the proper checks before using them. So I wasn't trying to force one way or another, just kept it the way it was and only fixed the problematic checks.
Quoted 3 lines
By the way it looks like this patch pattern could be applied right across the kernel, there are also others in PCI: pci-imx6 and
pcie-histb.c- not sure if you wanted to fix those up too.
I hadn't checked any other drivers, but I can take another look and prepare patches for them.
Quoted 1 line
Reviewed-by Andrew Murray <[email protected]>
Thanks,
Thierry
Quoted 29 lines
Quoted 29 lines
drivers/pci/controller/pcie-rockchip-host.c +6
-6} rockchip->vpcie3v3 =devm_regulator_get_optional (dev,"vpcie3v3" );if (IS_ERR (rockchip->vpcie3v3)) { -if (PTR_ERR (rockchip->vpcie3v3) == -EPROBE_DEFER ) -return -EPROBE_DEFER ; +if (PTR_ERR (rockchip->vpcie3v3) != -ENODEV ) +return PTR_ERR (rockchip->vpcie3v3);dev_info (dev,"no vpcie3v3 regulator found\n" ); } rockchip->vpcie1v8 =devm_regulator_get_optional (dev,"vpcie1v8" );if (IS_ERR (rockchip->vpcie1v8)) { -if (PTR_ERR (rockchip->vpcie1v8) == -EPROBE_DEFER ) -return -EPROBE_DEFER ; +if (PTR_ERR (rockchip->vpcie1v8) != -ENODEV ) +return PTR_ERR (rockchip->vpcie1v8);dev_info (dev,"no vpcie1v8 regulator found\n" ); } rockchip->vpcie0v9 =devm_regulator_get_optional (dev,"vpcie0v9" );if (IS_ERR (rockchip->vpcie0v9)) { -if (PTR_ERR (rockchip->vpcie0v9) == -EPROBE_DEFER ) -return -EPROBE_DEFER ; +if (PTR_ERR (rockchip->vpcie0v9) != -ENODEV ) +return PTR_ERR (rockchip->vpcie0v9);dev_info (dev,"no vpcie0v9 regulator found\n" ); }
Quoted 3 lines
Quoted 3 lines
Signature · 1 line
2.22.0
_______________________________________________
Linux-rockchip mailing list [email protected]
http://lists.infradead.org/mailman/listinfo/linux-rockchip
Am Mittwoch, 28. August 2019, 17:07:37 CEST schrieb Thierry Reding:
Quoted 8 lines
From: Thierry Reding <[email protected]>
regulator_get_optional()can fail for a number of reasons besides probe deferral. It can for example return-ENOMEMif it runs out of memory as it tries to allocate data structures. Propagating only -EPROBE_DEFER is problematic because it results in these legitimately fatal errors being treated as "regulator not specified in DT".
Quoted 7 lines
What we really want is to ignore the optional regulators only if they have not been specified in DT.
regulator_get_optional()returns-ENODEVin 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.Signed-off-by Thierry Reding <[email protected]>
on a rk3399-gru-scarlet with no 12v regulator defined and pcie-wifi keeping on working with this patch:
Change itself also looks correct,
Thanks for doing that cleanup
Heiko
Re: [PATCH] PCI: rockchip: Properly handle optional regulators【请注意,邮件由linux-rockchip-bounces+shawn.lin=rock-chips.com@lists.infradead.org代发】
In reply to Thierry RedingQuoted 8 lines · Thierry Reding
From: Thierry Reding <[email protected]>
regulator_get_optional()can fail for a number of reasons besides probe deferral. It can for example return-ENOMEMif it runs out of memory as it tries to allocate data structures. Propagating only -EPROBE_DEFER is problematic because it results in these legitimately fatal errors being treated as "regulator not specified in DT".
Quoted 7 lines
What we really want is to ignore the optional regulators only if they have not been specified in DT.
regulator_get_optional()returns-ENODEVin 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.Signed-off-by Thierry Reding <[email protected]>
LGTM,
Quoted 47 lines
--- drivers/pci/controller/pcie-rockchip-host.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)drivers/pci/controller/pcie-rockchip-host.c +8
-8@@ -608,29 +608,29 @@ static int rockchip_pcie_parse_host_dt(struct rockchip_pcie *rockchip) rockchip->vpcie12v =devm_regulator_get_optional (dev,"vpcie12v" );if (IS_ERR (rockchip->vpcie12v)) { -if (PTR_ERR (rockchip->vpcie12v) == -EPROBE_DEFER ) -return -EPROBE_DEFER ; +if (PTR_ERR (rockchip->vpcie12v) != -ENODEV ) +return PTR_ERR (rockchip->vpcie12v);dev_info (dev,"no vpcie12v regulator found\n" ); } rockchip->vpcie3v3 =devm_regulator_get_optional (dev,"vpcie3v3" );if (IS_ERR (rockchip->vpcie3v3)) { -if (PTR_ERR (rockchip->vpcie3v3) == -EPROBE_DEFER ) -return -EPROBE_DEFER ; +if (PTR_ERR (rockchip->vpcie3v3) != -ENODEV ) +return PTR_ERR (rockchip->vpcie3v3);dev_info (dev,"no vpcie3v3 regulator found\n" ); } rockchip->vpcie1v8 =devm_regulator_get_optional (dev,"vpcie1v8" );if (IS_ERR (rockchip->vpcie1v8)) { -if (PTR_ERR (rockchip->vpcie1v8) == -EPROBE_DEFER ) -return -EPROBE_DEFER ; +if (PTR_ERR (rockchip->vpcie1v8) != -ENODEV ) +return PTR_ERR (rockchip->vpcie1v8);dev_info (dev,"no vpcie1v8 regulator found\n" ); } rockchip->vpcie0v9 =devm_regulator_get_optional (dev,"vpcie0v9" );if (IS_ERR (rockchip->vpcie0v9)) { -if (PTR_ERR (rockchip->vpcie0v9) == -EPROBE_DEFER ) -return -EPROBE_DEFER ; +if (PTR_ERR (rockchip->vpcie0v9) != -ENODEV ) +return PTR_ERR (rockchip->vpcie0v9);dev_info (dev,"no vpcie0v9 regulator found\n" ); }