From f7bcb02390ad319ecc4161b9c9989f710fa6edb2 Mon Sep 17 00:00:00 2001 From: Sam Protsenko Date: Sun, 12 Dec 2021 19:02:47 +0200 Subject: watchdog: s3c2410: Fix getting the optional clock "watchdog_src" clock is optional and may not be present for some SoCs supported by this driver. Nevertheless, in case the clock is provided but some error happens during its getting, that error should be handled properly. Use devm_clk_get_optional() API for that. Also report possible errors using dev_err_probe() to handle properly -EPROBE_DEFER error (if clock provider is not ready by the time WDT probe function is executed). Fixes: e249d01b5e8b ("watchdog: s3c2410: Support separate source clock") Reported-by: kernel test robot Reported-by: Dan Carpenter Suggested-by: Guenter Roeck Signed-off-by: Sam Protsenko Reviewed-by: Guenter Roeck Reviewed-by: Krzysztof Kozlowski Link: https://lore.kernel.org/r/20211212170247.30646-1-semen.protsenko@linaro.org Signed-off-by: Guenter Roeck Signed-off-by: Wim Van Sebroeck --- drivers/watchdog/s3c2410_wdt.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'drivers/watchdog') diff --git a/drivers/watchdog/s3c2410_wdt.c b/drivers/watchdog/s3c2410_wdt.c index 523a6707bb31..6db22f2e3a4f 100644 --- a/drivers/watchdog/s3c2410_wdt.c +++ b/drivers/watchdog/s3c2410_wdt.c @@ -711,16 +711,18 @@ static int s3c2410wdt_probe(struct platform_device *pdev) * "watchdog_src" clock is optional; if it's not present -- just skip it * and use "watchdog" clock as both bus and source clock. */ - wdt->src_clk = devm_clk_get(dev, "watchdog_src"); - if (!IS_ERR(wdt->src_clk)) { - ret = clk_prepare_enable(wdt->src_clk); - if (ret < 0) { - dev_err(dev, "failed to enable source clock\n"); - ret = PTR_ERR(wdt->src_clk); - goto err_bus_clk; - } - } else { - wdt->src_clk = NULL; + wdt->src_clk = devm_clk_get_optional(dev, "watchdog_src"); + if (IS_ERR(wdt->src_clk)) { + dev_err_probe(dev, PTR_ERR(wdt->src_clk), + "failed to get source clock\n"); + ret = PTR_ERR(wdt->src_clk); + goto err_bus_clk; + } + + ret = clk_prepare_enable(wdt->src_clk); + if (ret) { + dev_err(dev, "failed to enable source clock\n"); + goto err_bus_clk; } wdt->wdt_device.min_timeout = 1; -- cgit v1.2.3