[v1,1/1,1/2] Check the timeout module parameter is in the min-max range
diff mbox series

Message ID 1590542319-35736-1-git-send-email-yuechao.zhao@advantech.com.cn
State New
Headers show
Series
  • [v1,1/1,1/2] Check the timeout module parameter is in the min-max range
Related show

Commit Message

yuechao.zhao@advantech.com.cn May 27, 2020, 1:18 a.m. UTC
From: Yuechao Zhao <yuechao.zhao@advantech.com.cn>

Check the return value of 'watchdog_init_timeout()' for checking the
timeout module parameter is in the min-max range.

Signed-off-by: Yuechao Zhao <yuechao.zhao@advantech.com.cn>
---
 drivers/hwmon/nct7904.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

Comments

Guenter Roeck May 27, 2020, 1:42 a.m. UTC | #1
On 5/26/20 6:18 PM, yuechao.zhao@advantech.com.cn wrote:
> From: Yuechao Zhao <yuechao.zhao@advantech.com.cn>
> 
> Check the return value of 'watchdog_init_timeout()' for checking the
> timeout module parameter is in the min-max range.
> 
> Signed-off-by: Yuechao Zhao <yuechao.zhao@advantech.com.cn>

Please fix the subject. It should start with "hwmon: (nct7904)"

> ---
>  drivers/hwmon/nct7904.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/hwmon/nct7904.c b/drivers/hwmon/nct7904.c
> index 18c95be..d069d59 100644
> --- a/drivers/hwmon/nct7904.c
> +++ b/drivers/hwmon/nct7904.c
> @@ -1152,7 +1152,10 @@ static int nct7904_probe(struct i2c_client *client,
>  	data->wdt.max_timeout = MAX_TIMEOUT;
>  	data->wdt.parent = &client->dev;
>  
> -	watchdog_init_timeout(&data->wdt, timeout * 60, &client->dev);
> +	ret = watchdog_init_timeout(&data->wdt, timeout * 60, &client->dev);
> +	if (ret < 0)
> +		return ret;
> +

Why ? The idea of returning an error from watchdog_init_timeout
is to give the driver a chance to select a default, not to refuse
loading the driver.

>  	watchdog_set_nowayout(&data->wdt, nowayout);
>  	watchdog_set_drvdata(&data->wdt, data);
>  
>

Patch
diff mbox series

diff --git a/drivers/hwmon/nct7904.c b/drivers/hwmon/nct7904.c
index 18c95be..d069d59 100644
--- a/drivers/hwmon/nct7904.c
+++ b/drivers/hwmon/nct7904.c
@@ -1152,7 +1152,10 @@  static int nct7904_probe(struct i2c_client *client,
 	data->wdt.max_timeout = MAX_TIMEOUT;
 	data->wdt.parent = &client->dev;
 
-	watchdog_init_timeout(&data->wdt, timeout * 60, &client->dev);
+	ret = watchdog_init_timeout(&data->wdt, timeout * 60, &client->dev);
+	if (ret < 0)
+		return ret;
+
 	watchdog_set_nowayout(&data->wdt, nowayout);
 	watchdog_set_drvdata(&data->wdt, data);