mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-09-06 10:57:46 +00:00
watchdog: qcom-wdt: Convert to use device managed functions and other improvements
Use device managed functions to simplify error handling, reduce source code size, improve readability, and reduce the likelyhood of bugs. Other improvements as listed below. The conversion was done automatically with coccinelle using the following semantic patches. The semantic patches and the scripts used to generate this commit log are available at https://github.com/groeck/coccinelle-patches - Drop assignments to otherwise unused variables - Drop empty remove function - Use devm_add_action_or_reset() for calls to clk_disable_unprepare - Introduce local variable 'struct device *dev' and use it instead of dereferencing it repeatedly - Use devm_watchdog_register_driver() to register watchdog device Cc: Andy Gross <andy.gross@linaro.org> Cc: David Brown <david.brown@linaro.org> Signed-off-by: Guenter Roeck <linux@roeck-us.net> Signed-off-by: Wim Van Sebroeck <wim@linux-watchdog.org>
This commit is contained in:
parent
9723a82a97
commit
bba07e6ed7
1 changed files with 25 additions and 30 deletions
|
@ -142,22 +142,28 @@ static const struct watchdog_info qcom_wdt_info = {
|
||||||
.identity = KBUILD_MODNAME,
|
.identity = KBUILD_MODNAME,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static void qcom_clk_disable_unprepare(void *data)
|
||||||
|
{
|
||||||
|
clk_disable_unprepare(data);
|
||||||
|
}
|
||||||
|
|
||||||
static int qcom_wdt_probe(struct platform_device *pdev)
|
static int qcom_wdt_probe(struct platform_device *pdev)
|
||||||
{
|
{
|
||||||
|
struct device *dev = &pdev->dev;
|
||||||
struct qcom_wdt *wdt;
|
struct qcom_wdt *wdt;
|
||||||
struct resource *res;
|
struct resource *res;
|
||||||
struct device_node *np = pdev->dev.of_node;
|
struct device_node *np = dev->of_node;
|
||||||
const u32 *regs;
|
const u32 *regs;
|
||||||
u32 percpu_offset;
|
u32 percpu_offset;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
regs = of_device_get_match_data(&pdev->dev);
|
regs = of_device_get_match_data(dev);
|
||||||
if (!regs) {
|
if (!regs) {
|
||||||
dev_err(&pdev->dev, "Unsupported QCOM WDT module\n");
|
dev_err(dev, "Unsupported QCOM WDT module\n");
|
||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
}
|
}
|
||||||
|
|
||||||
wdt = devm_kzalloc(&pdev->dev, sizeof(*wdt), GFP_KERNEL);
|
wdt = devm_kzalloc(dev, sizeof(*wdt), GFP_KERNEL);
|
||||||
if (!wdt)
|
if (!wdt)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
|
@ -172,21 +178,25 @@ static int qcom_wdt_probe(struct platform_device *pdev)
|
||||||
res->start += percpu_offset;
|
res->start += percpu_offset;
|
||||||
res->end += percpu_offset;
|
res->end += percpu_offset;
|
||||||
|
|
||||||
wdt->base = devm_ioremap_resource(&pdev->dev, res);
|
wdt->base = devm_ioremap_resource(dev, res);
|
||||||
if (IS_ERR(wdt->base))
|
if (IS_ERR(wdt->base))
|
||||||
return PTR_ERR(wdt->base);
|
return PTR_ERR(wdt->base);
|
||||||
|
|
||||||
wdt->clk = devm_clk_get(&pdev->dev, NULL);
|
wdt->clk = devm_clk_get(dev, NULL);
|
||||||
if (IS_ERR(wdt->clk)) {
|
if (IS_ERR(wdt->clk)) {
|
||||||
dev_err(&pdev->dev, "failed to get input clock\n");
|
dev_err(dev, "failed to get input clock\n");
|
||||||
return PTR_ERR(wdt->clk);
|
return PTR_ERR(wdt->clk);
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = clk_prepare_enable(wdt->clk);
|
ret = clk_prepare_enable(wdt->clk);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
dev_err(&pdev->dev, "failed to setup clock\n");
|
dev_err(dev, "failed to setup clock\n");
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
ret = devm_add_action_or_reset(dev, qcom_clk_disable_unprepare,
|
||||||
|
wdt->clk);
|
||||||
|
if (ret)
|
||||||
|
return ret;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* We use the clock rate to calculate the max timeout, so ensure it's
|
* We use the clock rate to calculate the max timeout, so ensure it's
|
||||||
|
@ -199,16 +209,15 @@ static int qcom_wdt_probe(struct platform_device *pdev)
|
||||||
wdt->rate = clk_get_rate(wdt->clk);
|
wdt->rate = clk_get_rate(wdt->clk);
|
||||||
if (wdt->rate == 0 ||
|
if (wdt->rate == 0 ||
|
||||||
wdt->rate > 0x10000000U) {
|
wdt->rate > 0x10000000U) {
|
||||||
dev_err(&pdev->dev, "invalid clock rate\n");
|
dev_err(dev, "invalid clock rate\n");
|
||||||
ret = -EINVAL;
|
return -EINVAL;
|
||||||
goto err_clk_unprepare;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
wdt->wdd.info = &qcom_wdt_info;
|
wdt->wdd.info = &qcom_wdt_info;
|
||||||
wdt->wdd.ops = &qcom_wdt_ops;
|
wdt->wdd.ops = &qcom_wdt_ops;
|
||||||
wdt->wdd.min_timeout = 1;
|
wdt->wdd.min_timeout = 1;
|
||||||
wdt->wdd.max_timeout = 0x10000000U / wdt->rate;
|
wdt->wdd.max_timeout = 0x10000000U / wdt->rate;
|
||||||
wdt->wdd.parent = &pdev->dev;
|
wdt->wdd.parent = dev;
|
||||||
wdt->layout = regs;
|
wdt->layout = regs;
|
||||||
|
|
||||||
if (readl(wdt_addr(wdt, WDT_STS)) & 1)
|
if (readl(wdt_addr(wdt, WDT_STS)) & 1)
|
||||||
|
@ -220,28 +229,15 @@ static int qcom_wdt_probe(struct platform_device *pdev)
|
||||||
* the max instead.
|
* the max instead.
|
||||||
*/
|
*/
|
||||||
wdt->wdd.timeout = min(wdt->wdd.max_timeout, 30U);
|
wdt->wdd.timeout = min(wdt->wdd.max_timeout, 30U);
|
||||||
watchdog_init_timeout(&wdt->wdd, 0, &pdev->dev);
|
watchdog_init_timeout(&wdt->wdd, 0, dev);
|
||||||
|
|
||||||
ret = watchdog_register_device(&wdt->wdd);
|
ret = devm_watchdog_register_device(dev, &wdt->wdd);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
dev_err(&pdev->dev, "failed to register watchdog\n");
|
dev_err(dev, "failed to register watchdog\n");
|
||||||
goto err_clk_unprepare;
|
|
||||||
}
|
|
||||||
|
|
||||||
platform_set_drvdata(pdev, wdt);
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
err_clk_unprepare:
|
|
||||||
clk_disable_unprepare(wdt->clk);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int qcom_wdt_remove(struct platform_device *pdev)
|
platform_set_drvdata(pdev, wdt);
|
||||||
{
|
|
||||||
struct qcom_wdt *wdt = platform_get_drvdata(pdev);
|
|
||||||
|
|
||||||
watchdog_unregister_device(&wdt->wdd);
|
|
||||||
clk_disable_unprepare(wdt->clk);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -277,7 +273,6 @@ MODULE_DEVICE_TABLE(of, qcom_wdt_of_table);
|
||||||
|
|
||||||
static struct platform_driver qcom_watchdog_driver = {
|
static struct platform_driver qcom_watchdog_driver = {
|
||||||
.probe = qcom_wdt_probe,
|
.probe = qcom_wdt_probe,
|
||||||
.remove = qcom_wdt_remove,
|
|
||||||
.driver = {
|
.driver = {
|
||||||
.name = KBUILD_MODNAME,
|
.name = KBUILD_MODNAME,
|
||||||
.of_match_table = qcom_wdt_of_table,
|
.of_match_table = qcom_wdt_of_table,
|
||||||
|
|
Loading…
Reference in a new issue