drivers: watchdog: sam0: Check if timeout is valid

The upper limit of the timeout should not be 0.
tests/drivers/watchdog/wdt_basic_api checks for this and fails as the
driver currently only checks that the timout does not exceed the upper
bound.
This also makes it check the lower bound, so that the test passes.

Signed-off-by: Benjamin Valentin <benjamin.valentin@ml-pa.com>
This commit is contained in:
Benjamin Valentin 2019-05-08 17:39:40 +02:00 committed by Maureen Helm
commit 29deef2def

View file

@ -117,6 +117,11 @@ static int wdt_sam0_install_timeout(struct device *dev,
return -ENOTSUP; return -ENOTSUP;
} }
if (cfg->window.max == 0) {
LOG_ERR("Upper limit timeout out of range");
return -EINVAL;
}
per = wdt_sam0_timeout_to_wdt_period(cfg->window.max); per = wdt_sam0_timeout_to_wdt_period(cfg->window.max);
if (per > WDT_CONFIG_PER_16K_Val) { if (per > WDT_CONFIG_PER_16K_Val) {
LOG_ERR("Upper limit timeout out of range"); LOG_ERR("Upper limit timeout out of range");