[RFC PATCH v2 7/8] regulator: qcom_spmi-regulator: Clean-up by using managed work init

From: Matti Vaittinen
Date: Mon Mar 08 2021 - 03:44:09 EST


Few drivers implement remove call-back only for ensuring a delayed
work gets cancelled prior driver removal. Clean-up these by switching
to use devm_delayed_work_autocancel() instead.

Additionally, this helps avoiding mixing devm and manual resource
management and cleans up a (theoretical?) bug where devm managed
over-current IRQ might schedule a new work item after wq was cleaned
at remove().

This change is compile-tested only. All testing is appreciated.

Signed-off-by: Matti Vaittinen <matti.vaittinen@xxxxxxxxxxxxxxxxx>
---
drivers/regulator/qcom_spmi-regulator.c | 34 ++++++-------------------
1 file changed, 8 insertions(+), 26 deletions(-)

diff --git a/drivers/regulator/qcom_spmi-regulator.c b/drivers/regulator/qcom_spmi-regulator.c
index e62e1d72d943..c2442d7798ab 100644
--- a/drivers/regulator/qcom_spmi-regulator.c
+++ b/drivers/regulator/qcom_spmi-regulator.c
@@ -5,6 +5,7 @@

#include <linux/module.h>
#include <linux/delay.h>
+#include <linux/devm-helpers.h>
#include <linux/err.h>
#include <linux/kernel.h>
#include <linux/interrupt.h>
@@ -1842,7 +1843,10 @@ static int spmi_regulator_of_parse(struct device_node *node,
return ret;
}

- INIT_DELAYED_WORK(&vreg->ocp_work, spmi_regulator_vs_ocp_work);
+ ret = devm_delayed_work_autocancel(dev, &vreg->ocp_work,
+ spmi_regulator_vs_ocp_work);
+ if (ret)
+ return ret;
}

return 0;
@@ -2157,10 +2161,8 @@ static int qcom_spmi_regulator_probe(struct platform_device *pdev)
vreg->regmap = regmap;
if (reg->ocp) {
vreg->ocp_irq = platform_get_irq_byname(pdev, reg->ocp);
- if (vreg->ocp_irq < 0) {
- ret = vreg->ocp_irq;
- goto err;
- }
+ if (vreg->ocp_irq < 0)
+ return vreg->ocp_irq;
}
vreg->desc.id = -1;
vreg->desc.owner = THIS_MODULE;
@@ -2203,8 +2205,7 @@ static int qcom_spmi_regulator_probe(struct platform_device *pdev)
rdev = devm_regulator_register(dev, &vreg->desc, &config);
if (IS_ERR(rdev)) {
dev_err(dev, "failed to register %s\n", name);
- ret = PTR_ERR(rdev);
- goto err;
+ return PTR_ERR(rdev);
}

INIT_LIST_HEAD(&vreg->node);
@@ -2212,24 +2213,6 @@ static int qcom_spmi_regulator_probe(struct platform_device *pdev)
}

return 0;
-
-err:
- list_for_each_entry(vreg, vreg_list, node)
- if (vreg->ocp_irq)
- cancel_delayed_work_sync(&vreg->ocp_work);
- return ret;
-}
-
-static int qcom_spmi_regulator_remove(struct platform_device *pdev)
-{
- struct spmi_regulator *vreg;
- struct list_head *vreg_list = platform_get_drvdata(pdev);
-
- list_for_each_entry(vreg, vreg_list, node)
- if (vreg->ocp_irq)
- cancel_delayed_work_sync(&vreg->ocp_work);
-
- return 0;
}

static struct platform_driver qcom_spmi_regulator_driver = {
@@ -2238,7 +2221,6 @@ static struct platform_driver qcom_spmi_regulator_driver = {
.of_match_table = qcom_spmi_regulator_match,
},
.probe = qcom_spmi_regulator_probe,
- .remove = qcom_spmi_regulator_remove,
};
module_platform_driver(qcom_spmi_regulator_driver);

--
2.25.4


--
Matti Vaittinen, Linux device drivers
ROHM Semiconductors, Finland SWDC
Kiviharjunlenkki 1E
90220 OULU
FINLAND

~~~ "I don't think so," said Rene Descartes. Just then he vanished ~~~
Simon says - in Latin please.
~~~ "non cogito me" dixit Rene Descarte, deinde evanescavit ~~~
Thanks to Simon Glass for the translation =]