Skip to content

Commit

Permalink
watchdog: tangox_wdt: test clock rate to avoid division by 0
Browse files Browse the repository at this point in the history
The clk API may return 0 on clk_get_rate, so we should check the result before
using it as a divisor. For this, refactor the code to use a central
error path.

Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
  • Loading branch information
Wolfram Sang authored and Wim Van Sebroeck committed Mar 16, 2016
1 parent ccc8208 commit 84b84bc
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions drivers/watchdog/tangox_wdt.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ static int tangox_wdt_probe(struct platform_device *pdev)
return err;

dev->clk_rate = clk_get_rate(dev->clk);
if (!dev->clk_rate) {
err = -EINVAL;
goto err;
}

dev->wdt.parent = &pdev->dev;
dev->wdt.info = &tangox_wdt_info;
Expand Down Expand Up @@ -171,10 +175,8 @@ static int tangox_wdt_probe(struct platform_device *pdev)
}

err = watchdog_register_device(&dev->wdt);
if (err) {
clk_disable_unprepare(dev->clk);
return err;
}
if (err)
goto err;

platform_set_drvdata(pdev, dev);

Expand All @@ -187,6 +189,10 @@ static int tangox_wdt_probe(struct platform_device *pdev)
dev_info(&pdev->dev, "SMP86xx/SMP87xx watchdog registered\n");

return 0;

err:
clk_disable_unprepare(dev->clk);
return err;
}

static int tangox_wdt_remove(struct platform_device *pdev)
Expand Down

0 comments on commit 84b84bc

Please sign in to comment.