2022-11-30 08:59:33

by ChiYuan Huang

[permalink] [raw]
Subject: [PATCH 2/2] regulator: mt6370: Switch to use dev_err_probe() helper

From: ChiYuan Huang <[email protected]>

Use dev_err_probe helper to simplify the probe function.

Signed-off-by: ChiYuan Huang <[email protected]>
---
drivers/regulator/mt6370-regulator.c | 39 +++++++++++++-----------------------
1 file changed, 14 insertions(+), 25 deletions(-)

diff --git a/drivers/regulator/mt6370-regulator.c b/drivers/regulator/mt6370-regulator.c
index c2b589a..e090fbe 100644
--- a/drivers/regulator/mt6370-regulator.c
+++ b/drivers/regulator/mt6370-regulator.c
@@ -303,11 +303,9 @@ static int mt6370_regulator_irq_register(struct mt6370_priv *priv)
ret = devm_request_threaded_irq(priv->dev, irq, NULL,
mt6370_irqs[i].handler, 0,
mt6370_irqs[i].name, rdev);
- if (ret) {
- dev_err(priv->dev,
- "Failed to register (%d) interrupt\n", i);
- return ret;
- }
+ if (ret)
+ return dev_err_probe(priv->dev, ret,
+ "Failed to register (%d) interrupt\n", i);
}

return 0;
@@ -329,20 +327,16 @@ static int mt6370_regualtor_register(struct mt6370_priv *priv)
int i, ret;

regulator_np = of_get_child_by_name(parent->of_node, "regulators");
- if (!regulator_np) {
- dev_err(dev, "Could not find parent 'regulators' node\n");
- return -ENODEV;
- }
+ if (!regulator_np)
+ return dev_err_probe(dev, -ENODEV, "Could not find parent 'regulators' node\n");

ret = of_regulator_match(dev, regulator_np, mt6370_regulator_match,
ARRAY_SIZE(mt6370_regulator_match));

of_node_put(regulator_np);

- if (ret < 0) {
- dev_err(dev, "Error parsing regulator init data: %d\n", ret);
- return ret;
- }
+ if (ret < 0)
+ return dev_err_probe(dev, ret, "Error parsing regulator init data\n");

for (i = 0; i < MT6370_MAX_IDX; i++) {
const struct regulator_desc *desc = mt6370_regulator_descs + i;
@@ -355,17 +349,14 @@ static int mt6370_regualtor_register(struct mt6370_priv *priv)

if (cfg.of_node && desc->of_parse_cb) {
ret = desc->of_parse_cb(cfg.of_node, desc, &cfg);
- if (ret) {
- dev_err(dev, "Failed in of_parse_cb\n");
- return ret;
- }
+ if (ret)
+ return dev_err_probe(dev, ret, "Failed in of_parse_cb\n");
}

rdev = devm_regulator_register(dev, desc, &cfg);
- if (IS_ERR(rdev)) {
- dev_err(dev, "Failed to register (%d) regulator\n", i);
- return PTR_ERR(rdev);
- }
+ if (IS_ERR(rdev))
+ return dev_err_probe(dev, PTR_ERR(rdev),
+ "Failed to register (%d) regulator\n", i);

priv->rdev[i] = rdev;
}
@@ -385,10 +376,8 @@ static int mt6370_regulator_probe(struct platform_device *pdev)
priv->dev = &pdev->dev;

priv->regmap = dev_get_regmap(pdev->dev.parent, NULL);
- if (!priv->regmap) {
- dev_err(&pdev->dev, "Failed to init regmap\n");
- return -ENODEV;
- }
+ if (!priv->regmap)
+ return dev_err_probe(&pdev->dev, -ENODEV, "Failed to init regmap\n");

ret = mt6370_regualtor_register(priv);
if (ret)
--
2.7.4