Linux-Watchdog Archive on lore.kernel.org
 help / color / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: Wim Van Sebroeck <wim@linux-watchdog.org>,
	Guenter Roeck <linux@roeck-us.net>
Cc: linux-watchdog@vger.kernel.org, kernel@pengutronix.de,
	Ahmad Fatoum <a.fatoum@pengutronix.de>,
	linux-kernel@vger.kernel.org
Subject: [PATCH v1 5/8] watchdog: f71808e_wdt: do stricter parameter validation
Date: Thu, 11 Jun 2020 21:17:46 +0200
Message-ID: <20200611191750.28096-6-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20200611191750.28096-1-a.fatoum@pengutronix.de>

We check the f71862fg_pin module parameter every time a watchdog device
for the f71862fg is opened, but the parameter can't change at runtime.

If we move the check to the start of init:

  - We catch userspace passing invalid, but unused, values
  - We check the condition only once
  - We simplify the code

Do so.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 drivers/watchdog/f71808e_wdt.c | 37 +++++++++++-----------------------
 1 file changed, 12 insertions(+), 25 deletions(-)

diff --git a/drivers/watchdog/f71808e_wdt.c b/drivers/watchdog/f71808e_wdt.c
index 26bf366aebc2..9f7823819ed1 100644
--- a/drivers/watchdog/f71808e_wdt.c
+++ b/drivers/watchdog/f71808e_wdt.c
@@ -306,27 +306,6 @@ static int watchdog_keepalive(void)
 	return err;
 }
 
-static int f71862fg_pin_configure(unsigned short ioaddr)
-{
-	/* When ioaddr is non-zero the calling function has to take care of
-	   mutex handling and superio preparation! */
-
-	if (f71862fg_pin == 63) {
-		if (ioaddr) {
-			/* SPI must be disabled first to use this pin! */
-			superio_clear_bit(ioaddr, SIO_REG_ROM_ADDR_SEL, 6);
-			superio_set_bit(ioaddr, SIO_REG_MFUNCT3, 4);
-		}
-	} else if (f71862fg_pin == 56) {
-		if (ioaddr)
-			superio_set_bit(ioaddr, SIO_REG_MFUNCT1, 1);
-	} else {
-		pr_err("Invalid argument f71862fg_pin=%d\n", f71862fg_pin);
-		return -EINVAL;
-	}
-	return 0;
-}
-
 static int watchdog_start(void)
 {
 	int err;
@@ -352,9 +331,13 @@ static int watchdog_start(void)
 		break;
 
 	case f71862fg:
-		err = f71862fg_pin_configure(watchdog.sioaddr);
-		if (err)
-			goto exit_superio;
+		if (f71862fg_pin == 63) {
+			/* SPI must be disabled first to use this pin! */
+			superio_clear_bit(watchdog.sioaddr, SIO_REG_ROM_ADDR_SEL, 6);
+			superio_set_bit(watchdog.sioaddr, SIO_REG_MFUNCT3, 4);
+		} else if (f71862fg_pin == 56) {
+			superio_set_bit(watchdog.sioaddr, SIO_REG_MFUNCT1, 1);
+		}
 		break;
 
 	case f71868:
@@ -810,7 +793,6 @@ static int __init f71808e_find(int sioaddr)
 		break;
 	case SIO_F71862_ID:
 		watchdog.type = f71862fg;
-		err = f71862fg_pin_configure(0); /* validate module parameter */
 		break;
 	case SIO_F71868_ID:
 		watchdog.type = f71868;
@@ -859,6 +841,11 @@ static int __init f71808e_init(void)
 	int err = -ENODEV;
 	int i;
 
+	if (f71862fg_pin != 63 && f71862fg_pin != 56) {
+		pr_err("Invalid argument f71862fg_pin=%d\n", f71862fg_pin);
+		return -EINVAL;
+	}
+
 	for (i = 0; i < ARRAY_SIZE(addrs); i++) {
 		err = f71808e_find(addrs[i]);
 		if (err == 0)
-- 
2.27.0


  parent reply index

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-11 19:17 [PATCH v1 0/8] watchdog: f71808e_wdt: migrate to kernel Ahmad Fatoum
2020-06-11 19:17 ` [PATCH v1 1/8] docs: watchdog: codify ident.options as superset of possible status flags Ahmad Fatoum
2020-06-30 20:49   ` Guenter Roeck
2020-06-11 19:17 ` [PATCH v1 2/8] watchdog: f71808e_wdt: indicate WDIOF_CARDRESET support in watchdog_info.options Ahmad Fatoum
2020-06-30 20:51   ` Guenter Roeck
2020-06-11 19:17 ` [PATCH v1 3/8] watchdog: f71808e_wdt: remove use of wrong watchdog_info option Ahmad Fatoum
2020-06-30 21:07   ` Guenter Roeck
2020-06-11 19:17 ` [PATCH v1 4/8] watchdog: f71808e_wdt: clear watchdog timeout occurred flag Ahmad Fatoum
2020-06-30 21:09   ` Guenter Roeck
2020-06-11 19:17 ` Ahmad Fatoum [this message]
2020-06-30 21:11   ` [PATCH v1 5/8] watchdog: f71808e_wdt: do stricter parameter validation Guenter Roeck
2020-06-11 19:17 ` [PATCH v1 6/8] watchdog: f71808e_wdt: consolidate variant handling into single array Ahmad Fatoum
2020-06-30 21:18   ` Guenter Roeck
2020-06-11 19:17 ` [PATCH v1 7/8] watchdog: f71808e_wdt: migrate to new kernel watchdog API Ahmad Fatoum
2020-06-30 21:26   ` Guenter Roeck
2020-06-11 19:17 ` [PATCH v1 8/8] watchdog: f71808e_wdt: rename variant-independent identifiers appropriately Ahmad Fatoum
2020-06-12  4:57   ` kernel test robot
2020-06-12  4:57   ` [RFC PATCH] watchdog: f71808e_wdt: fintek_variants[] can be static kernel test robot
2020-06-30 21:29   ` [PATCH v1 8/8] watchdog: f71808e_wdt: rename variant-independent identifiers appropriately Guenter Roeck
2020-07-13  8:59     ` Ahmad Fatoum

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=20200611191750.28096-6-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=kernel@pengutronix.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-watchdog@vger.kernel.org \
    --cc=linux@roeck-us.net \
    --cc=wim@linux-watchdog.org \
    /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

Linux-Watchdog Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-watchdog/0 linux-watchdog/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-watchdog linux-watchdog/ https://lore.kernel.org/linux-watchdog \
		linux-watchdog@vger.kernel.org
	public-inbox-index linux-watchdog

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-watchdog


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git