From: Guenter Roeck <linux@roeck-us.net>
To: Wolfram Sang <wsa+renesas@sang-engineering.com>,
linux-watchdog@vger.kernel.org
Cc: linux-renesas-soc@vger.kernel.org,
Wim Van Sebroeck <wim@linux-watchdog.org>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 01/16] watchdog: refactor watchdog_init_timeout
Date: Tue, 16 Apr 2019 06:23:08 -0700 [thread overview]
Message-ID: <b65ae931-bfb3-acb4-8097-da4b81be1ea5@roeck-us.net> (raw)
In-Reply-To: <20190416102515.12269-2-wsa+renesas@sang-engineering.com>
On 4/16/19 3:25 AM, Wolfram Sang wrote:
> The function is not easy to read and has a problem: -EINVAL is returned
> when the module parameter is invalid but the DT parameter is OK.
>
> Refactor the code to have the same pattern of checks for the module
> parameter and DT. Further ones can be easily added in the future if the
> need arises. The above mentioned problem is fixed, too.
>
> Some documentation is added to describe the different handlings of '0'
> for the module parameter and the DT property.
>
> Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
Reviewed-by: Guenter Roeck <linux@roeck-us.net>
> ---
> drivers/watchdog/watchdog_core.c | 33 +++++++++++++++++++--------------
> 1 file changed, 19 insertions(+), 14 deletions(-)
>
> diff --git a/drivers/watchdog/watchdog_core.c b/drivers/watchdog/watchdog_core.c
> index eb8fa25f8eb2..21e53cc49977 100644
> --- a/drivers/watchdog/watchdog_core.c
> +++ b/drivers/watchdog/watchdog_core.c
> @@ -105,9 +105,12 @@ static void watchdog_check_min_max_timeout(struct watchdog_device *wdd)
> * timeout module parameter (if it is valid value) or the timeout-sec property
> * (only if it is a valid value and the timeout_parm is out of bounds).
> * If none of them are valid then we keep the old value (which should normally
> - * be the default timeout value).
> + * be the default timeout value). Note that for the module parameter, '0' means
> + * 'use default' while it is an invalid value for the timeout-sec property.
> + * It should simply be dropped if you want to use the default value then.
> *
> - * A zero is returned on success and -EINVAL for failure.
> + * A zero is returned on success or -EINVAL if all provided values are out of
> + * bounds.
> */
> int watchdog_init_timeout(struct watchdog_device *wdd,
> unsigned int timeout_parm, struct device *dev)
> @@ -117,22 +120,24 @@ int watchdog_init_timeout(struct watchdog_device *wdd,
>
> watchdog_check_min_max_timeout(wdd);
>
> - /* try to get the timeout module parameter first */
> - if (!watchdog_timeout_invalid(wdd, timeout_parm) && timeout_parm) {
> - wdd->timeout = timeout_parm;
> - return ret;
> - }
> - if (timeout_parm)
> + /* check the driver supplied value (likely a module parameter) first */
> + if (timeout_parm) {
> + if (!watchdog_timeout_invalid(wdd, timeout_parm)) {
> + wdd->timeout = timeout_parm;
> + return 0;
> + }
> ret = -EINVAL;
> + }
>
> /* try to get the timeout_sec property */
> - if (dev == NULL || dev->of_node == NULL)
> - return ret;
> - of_property_read_u32(dev->of_node, "timeout-sec", &t);
> - if (!watchdog_timeout_invalid(wdd, t) && t)
> - wdd->timeout = t;
> - else
> + if (dev && dev->of_node &&
> + of_property_read_u32(dev->of_node, "timeout-sec", &t) == 0) {
> + if (t && !watchdog_timeout_invalid(wdd, t)) {
> + wdd->timeout = t;
> + return 0;
> + }
> ret = -EINVAL;
> + }
>
> return ret;
> }
>
next prev parent reply other threads:[~2019-04-16 13:23 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20190416102515.12269-1-wsa+renesas@sang-engineering.com>
2019-04-16 10:25 ` Wolfram Sang
2019-04-16 13:23 ` Guenter Roeck [this message]
2019-04-16 10:25 ` [PATCH v2 02/16] watchdog: add error messages when initializing timeout fails Wolfram Sang
2019-04-16 10:25 ` [PATCH v2 03/16] watchdog: cadence_wdt: drop warning after calling watchdog_init_timeout Wolfram Sang
2019-04-16 10:25 ` [PATCH v2 04/16] watchdog: cadence_wdt: still probe if user supplied timeout is invalid Wolfram Sang
2019-04-16 10:25 ` [PATCH v2 05/16] watchdog: ebc-c384_wdt: drop warning after calling watchdog_init_timeout Wolfram Sang
2019-04-16 10:28 ` William Breathitt Gray
2019-04-16 10:25 ` [PATCH v2 06/16] watchdog: hpwdt: " Wolfram Sang
2019-04-16 20:34 ` Jerry Hoemann
2019-04-16 20:48 ` Guenter Roeck
2019-04-16 20:55 ` Wolfram Sang
2019-04-16 21:20 ` Guenter Roeck
2019-04-16 22:17 ` Wolfram Sang
2019-04-16 22:38 ` Guenter Roeck
2019-04-17 19:45 ` Wolfram Sang
2019-04-17 20:17 ` Guenter Roeck
2019-04-17 21:18 ` Wolfram Sang
2019-04-17 22:00 ` Guenter Roeck
2019-04-24 8:38 ` Geert Uytterhoeven
2019-04-24 12:57 ` Guenter Roeck
2019-04-16 20:50 ` Wolfram Sang
2019-04-16 21:14 ` Guenter Roeck
2019-04-16 10:25 ` [PATCH v2 07/16] watchdog: i6300esb: " Wolfram Sang
2019-04-16 10:25 ` [PATCH v2 08/16] watchdog: imx_sc_wdt: " Wolfram Sang
2019-04-16 10:25 ` [PATCH v2 09/16] watchdog: ni903x_wdt: " Wolfram Sang
2019-04-16 10:25 ` [PATCH v2 10/16] watchdog: nic7018_wdt: " Wolfram Sang
2019-04-16 10:25 ` [PATCH v2 11/16] watchdog: renesas_wdt: " Wolfram Sang
2019-04-16 10:25 ` [PATCH v2 12/16] watchdog: sp5100_tco: " Wolfram Sang
2019-04-16 10:25 ` [PATCH v2 13/16] watchdog: st_lpc_wdt: " Wolfram Sang
2019-04-16 10:25 ` [PATCH v2 14/16] watchdog: stm32_iwdg: " Wolfram Sang
2019-04-16 10:25 ` [PATCH v2 15/16] watchdog: xen_wdt: " Wolfram Sang
2019-04-16 10:25 ` [PATCH v2 16/16] watchdog: ziirave_wdt: " Wolfram Sang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=b65ae931-bfb3-acb4-8097-da4b81be1ea5@roeck-us.net \
--to=linux@roeck-us.net \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-renesas-soc@vger.kernel.org \
--cc=linux-watchdog@vger.kernel.org \
--cc=wim@linux-watchdog.org \
--cc=wsa+renesas@sang-engineering.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®