2018-03-23 21:38:08

by Alexey Khoroshilov

[permalink] [raw]
Subject: [PATCH] watchdog: davinci_wdt: fix error handling in davinci_wdt_probe()

clk_disable_unprepare() was added to one error path,
but there is another one. The patch makes sure clk is
disabled at the both of them.

Found by Linux Driver Verification project (linuxtesting.org).

Signed-off-by: Alexey Khoroshilov <[email protected]>
---
drivers/watchdog/davinci_wdt.c | 15 +++++++++++----
1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/drivers/watchdog/davinci_wdt.c b/drivers/watchdog/davinci_wdt.c
index 3e4c592c239f..6c6594261cb7 100644
--- a/drivers/watchdog/davinci_wdt.c
+++ b/drivers/watchdog/davinci_wdt.c
@@ -236,15 +236,22 @@ static int davinci_wdt_probe(struct platform_device *pdev)

wdt_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
davinci_wdt->base = devm_ioremap_resource(dev, wdt_mem);
- if (IS_ERR(davinci_wdt->base))
- return PTR_ERR(davinci_wdt->base);
+ if (IS_ERR(davinci_wdt->base)) {
+ ret = PTR_ERR(davinci_wdt->base);
+ goto err_clk_disable;
+ }

ret = watchdog_register_device(wdd);
- if (ret < 0) {
- clk_disable_unprepare(davinci_wdt->clk);
+ if (ret) {
dev_err(dev, "cannot register watchdog device\n");
+ goto err_clk_disable;
}

+ return 0;
+
+err_clk_disable:
+ clk_disable_unprepare(davinci_wdt->clk);
+
return ret;
}

--
2.7.4



2018-03-24 00:24:01

by Guenter Roeck

[permalink] [raw]
Subject: Re: [PATCH] watchdog: davinci_wdt: fix error handling in davinci_wdt_probe()

On 03/23/2018 02:36 PM, Alexey Khoroshilov wrote:
> clk_disable_unprepare() was added to one error path,
> but there is another one. The patch makes sure clk is
> disabled at the both of them.
>
> Found by Linux Driver Verification project (linuxtesting.org).
>
> Signed-off-by: Alexey Khoroshilov <[email protected]>

Reviewed-by: Guenter Roeck <[email protected]>

> ---
> drivers/watchdog/davinci_wdt.c | 15 +++++++++++----
> 1 file changed, 11 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/watchdog/davinci_wdt.c b/drivers/watchdog/davinci_wdt.c
> index 3e4c592c239f..6c6594261cb7 100644
> --- a/drivers/watchdog/davinci_wdt.c
> +++ b/drivers/watchdog/davinci_wdt.c
> @@ -236,15 +236,22 @@ static int davinci_wdt_probe(struct platform_device *pdev)
>
> wdt_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> davinci_wdt->base = devm_ioremap_resource(dev, wdt_mem);
> - if (IS_ERR(davinci_wdt->base))
> - return PTR_ERR(davinci_wdt->base);
> + if (IS_ERR(davinci_wdt->base)) {
> + ret = PTR_ERR(davinci_wdt->base);
> + goto err_clk_disable;
> + }
>
> ret = watchdog_register_device(wdd);
> - if (ret < 0) {
> - clk_disable_unprepare(davinci_wdt->clk);
> + if (ret) {
> dev_err(dev, "cannot register watchdog device\n");
> + goto err_clk_disable;
> }
>
> + return 0;
> +
> +err_clk_disable:
> + clk_disable_unprepare(davinci_wdt->clk);
> +
> return ret;
> }
>
>