[PATCH] PCI: pcie-rockchip: use probe_err helpers instead of open coding
From: Andrzej Hajda
Date: Fri Dec 21 2018 - 03:32:52 EST
probe_err helpers makes probe error handling easier and less error prone.
Signed-off-by: Andrzej Hajda <a.hajda@xxxxxxxxxxx>
---
Hi all,
This is sample conversion of one of drivers to proposed probe_err* helpers.
It was created to convince Greg that these helpers are useful.
With this helper we gain:
- corect error handling (deferral does not spam dmesg, other errors are logged),
- uniform error logging,
- simplified code,
- possibilty to check why some devices are deferred,
- shorter code.
Here are links to patchsets adding helpers v1[1], v4[2], in v1 I have added
big patch doing conversion to probe_err to show scale of the 'issue'.
If the helpers will be accepted I plan to send patches converting other drivers
as well.
[1]: https://lkml.org/lkml/2018/10/16/601
[2]: https://lkml.org/lkml/2018/12/20/438
Regards
Andrzej
---
drivers/pci/controller/pcie-rockchip.c | 100 ++++++++++---------------
1 file changed, 39 insertions(+), 61 deletions(-)
diff --git a/drivers/pci/controller/pcie-rockchip.c b/drivers/pci/controller/pcie-rockchip.c
index c53d1322a3d6..0d4f012c02ba 100644
--- a/drivers/pci/controller/pcie-rockchip.c
+++ b/drivers/pci/controller/pcie-rockchip.c
@@ -69,86 +69,67 @@ int rockchip_pcie_parse_dt(struct rockchip_pcie *rockchip)
rockchip->link_gen = 2;
rockchip->core_rst = devm_reset_control_get_exclusive(dev, "core");
- if (IS_ERR(rockchip->core_rst)) {
- if (PTR_ERR(rockchip->core_rst) != -EPROBE_DEFER)
- dev_err(dev, "missing core reset property in node\n");
- return PTR_ERR(rockchip->core_rst);
- }
+ if (IS_ERR(rockchip->core_rst))
+ return probe_err_ptr(dev, rockchip->core_rst,
+ "missing core reset property in node\n");
rockchip->mgmt_rst = devm_reset_control_get_exclusive(dev, "mgmt");
- if (IS_ERR(rockchip->mgmt_rst)) {
- if (PTR_ERR(rockchip->mgmt_rst) != -EPROBE_DEFER)
- dev_err(dev, "missing mgmt reset property in node\n");
- return PTR_ERR(rockchip->mgmt_rst);
- }
+ if (IS_ERR(rockchip->mgmt_rst))
+ return probe_err_ptr(dev, rockchip->mgmt_rst,
+ "missing mgmt reset property in node\n");
rockchip->mgmt_sticky_rst = devm_reset_control_get_exclusive(dev,
"mgmt-sticky");
- if (IS_ERR(rockchip->mgmt_sticky_rst)) {
- if (PTR_ERR(rockchip->mgmt_sticky_rst) != -EPROBE_DEFER)
- dev_err(dev, "missing mgmt-sticky reset property in node\n");
- return PTR_ERR(rockchip->mgmt_sticky_rst);
- }
+ if (IS_ERR(rockchip->mgmt_sticky_rst))
+ return probe_err_ptr(dev, rockchip->mgmt_sticky_rst,
+ "missing mgmt-sticky reset property in node\n");
rockchip->pipe_rst = devm_reset_control_get_exclusive(dev, "pipe");
- if (IS_ERR(rockchip->pipe_rst)) {
- if (PTR_ERR(rockchip->pipe_rst) != -EPROBE_DEFER)
- dev_err(dev, "missing pipe reset property in node\n");
- return PTR_ERR(rockchip->pipe_rst);
- }
+ if (IS_ERR(rockchip->pipe_rst))
+ return probe_err_ptr(dev, rockchip->pipe_rst,
+ "missing pipe reset property in node\n");
rockchip->pm_rst = devm_reset_control_get_exclusive(dev, "pm");
- if (IS_ERR(rockchip->pm_rst)) {
- if (PTR_ERR(rockchip->pm_rst) != -EPROBE_DEFER)
- dev_err(dev, "missing pm reset property in node\n");
- return PTR_ERR(rockchip->pm_rst);
- }
+ if (IS_ERR(rockchip->pm_rst))
+ return probe_err_ptr(dev, rockchip->pm_rst,
+ "missing pm reset property in node\n");
rockchip->pclk_rst = devm_reset_control_get_exclusive(dev, "pclk");
- if (IS_ERR(rockchip->pclk_rst)) {
- if (PTR_ERR(rockchip->pclk_rst) != -EPROBE_DEFER)
- dev_err(dev, "missing pclk reset property in node\n");
- return PTR_ERR(rockchip->pclk_rst);
- }
+ if (IS_ERR(rockchip->pclk_rst))
+ return probe_err_ptr(dev, rockchip->pclk_rst,
+ "missing pclk reset property in node\n");
rockchip->aclk_rst = devm_reset_control_get_exclusive(dev, "aclk");
- if (IS_ERR(rockchip->aclk_rst)) {
- if (PTR_ERR(rockchip->aclk_rst) != -EPROBE_DEFER)
- dev_err(dev, "missing aclk reset property in node\n");
- return PTR_ERR(rockchip->aclk_rst);
- }
+ if (IS_ERR(rockchip->aclk_rst))
+ return probe_err_ptr(dev, rockchip->aclk_rst,
+ "missing aclk reset property in node\n");
if (rockchip->is_rc) {
rockchip->ep_gpio = devm_gpiod_get(dev, "ep", GPIOD_OUT_HIGH);
- if (IS_ERR(rockchip->ep_gpio)) {
- dev_err(dev, "missing ep-gpios property in node\n");
- return PTR_ERR(rockchip->ep_gpio);
- }
+ if (IS_ERR(rockchip->ep_gpio))
+ return probe_err_ptr(dev, rockchip->ep_gpio,
+ "missing ep-gpios property in node\n");
}
rockchip->aclk_pcie = devm_clk_get(dev, "aclk");
- if (IS_ERR(rockchip->aclk_pcie)) {
- dev_err(dev, "aclk clock not found\n");
- return PTR_ERR(rockchip->aclk_pcie);
- }
+ if (IS_ERR(rockchip->aclk_pcie))
+ return probe_err_ptr(dev, rockchip->aclk_pcie,
+ "aclk clock not found\n");
rockchip->aclk_perf_pcie = devm_clk_get(dev, "aclk-perf");
- if (IS_ERR(rockchip->aclk_perf_pcie)) {
- dev_err(dev, "aclk_perf clock not found\n");
- return PTR_ERR(rockchip->aclk_perf_pcie);
- }
+ if (IS_ERR(rockchip->aclk_perf_pcie))
+ return probe_err_ptr(dev, rockchip->aclk_perf_pcie,
+ "aclk_perf clock not found\n");
rockchip->hclk_pcie = devm_clk_get(dev, "hclk");
- if (IS_ERR(rockchip->hclk_pcie)) {
- dev_err(dev, "hclk clock not found\n");
- return PTR_ERR(rockchip->hclk_pcie);
- }
+ if (IS_ERR(rockchip->hclk_pcie))
+ return probe_err_ptr(dev, rockchip->hclk_pcie,
+ "hclk clock not found\n");
rockchip->clk_pcie_pm = devm_clk_get(dev, "pm");
- if (IS_ERR(rockchip->clk_pcie_pm)) {
- dev_err(dev, "pm clock not found\n");
- return PTR_ERR(rockchip->clk_pcie_pm);
- }
+ if (IS_ERR(rockchip->clk_pcie_pm))
+ return probe_err_ptr(dev, rockchip->clk_pcie_pm,
+ "pm clock not found\n");
return 0;
}
@@ -323,12 +304,9 @@ int rockchip_pcie_get_phys(struct rockchip_pcie *rockchip)
phy = devm_of_phy_get(dev, dev->of_node, name);
kfree(name);
- if (IS_ERR(phy)) {
- if (PTR_ERR(phy) != -EPROBE_DEFER)
- dev_err(dev, "missing phy for lane %d: %ld\n",
- i, PTR_ERR(phy));
- return PTR_ERR(phy);
- }
+ if (IS_ERR(phy))
+ return probe_err_ptr(dev, phy,
+ "missing phy for lane %d\n", i);
rockchip->phys[i] = phy;
}
--
2.17.1