Commit b6688015 authored by Matti Vaittinen's avatar Matti Vaittinen Committed by Greg Kroah-Hartman

regulator: qcom_spmi-regulator: Clean-up by using managed work init

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: default avatarMatti Vaittinen <matti.vaittinen@fi.rohmeurope.com>
Link: https://lore.kernel.org/r/3bd35bb43257f4bf5b99f75d207ed5e1e08d1d38.1616506559.git.matti.vaittinen@fi.rohmeurope.comSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 6d0c5de2
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include <linux/module.h> #include <linux/module.h>
#include <linux/delay.h> #include <linux/delay.h>
#include <linux/devm-helpers.h>
#include <linux/err.h> #include <linux/err.h>
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/interrupt.h> #include <linux/interrupt.h>
...@@ -1842,7 +1843,10 @@ static int spmi_regulator_of_parse(struct device_node *node, ...@@ -1842,7 +1843,10 @@ static int spmi_regulator_of_parse(struct device_node *node,
return ret; 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; return 0;
...@@ -2157,10 +2161,8 @@ static int qcom_spmi_regulator_probe(struct platform_device *pdev) ...@@ -2157,10 +2161,8 @@ static int qcom_spmi_regulator_probe(struct platform_device *pdev)
vreg->regmap = regmap; vreg->regmap = regmap;
if (reg->ocp) { if (reg->ocp) {
vreg->ocp_irq = platform_get_irq_byname(pdev, reg->ocp); vreg->ocp_irq = platform_get_irq_byname(pdev, reg->ocp);
if (vreg->ocp_irq < 0) { if (vreg->ocp_irq < 0)
ret = vreg->ocp_irq; return vreg->ocp_irq;
goto err;
}
} }
vreg->desc.id = -1; vreg->desc.id = -1;
vreg->desc.owner = THIS_MODULE; vreg->desc.owner = THIS_MODULE;
...@@ -2203,8 +2205,7 @@ static int qcom_spmi_regulator_probe(struct platform_device *pdev) ...@@ -2203,8 +2205,7 @@ static int qcom_spmi_regulator_probe(struct platform_device *pdev)
rdev = devm_regulator_register(dev, &vreg->desc, &config); rdev = devm_regulator_register(dev, &vreg->desc, &config);
if (IS_ERR(rdev)) { if (IS_ERR(rdev)) {
dev_err(dev, "failed to register %s\n", name); dev_err(dev, "failed to register %s\n", name);
ret = PTR_ERR(rdev); return PTR_ERR(rdev);
goto err;
} }
INIT_LIST_HEAD(&vreg->node); INIT_LIST_HEAD(&vreg->node);
...@@ -2212,24 +2213,6 @@ static int qcom_spmi_regulator_probe(struct platform_device *pdev) ...@@ -2212,24 +2213,6 @@ static int qcom_spmi_regulator_probe(struct platform_device *pdev)
} }
return 0; 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 = { static struct platform_driver qcom_spmi_regulator_driver = {
...@@ -2238,7 +2221,6 @@ 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, .of_match_table = qcom_spmi_regulator_match,
}, },
.probe = qcom_spmi_regulator_probe, .probe = qcom_spmi_regulator_probe,
.remove = qcom_spmi_regulator_remove,
}; };
module_platform_driver(qcom_spmi_regulator_driver); module_platform_driver(qcom_spmi_regulator_driver);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment