Skip to content

Commit 5edc8c6

Browse files
a3fWim Van Sebroeck
authored andcommitted
watchdog: f71808e_wdt: do stricter parameter validation
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 <[email protected]> Reviewed-by: Guenter Roeck <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Guenter Roeck <[email protected]> Signed-off-by: Wim Van Sebroeck <[email protected]>
1 parent 4f39d57 commit 5edc8c6

File tree

1 file changed

+12
-25
lines changed

1 file changed

+12
-25
lines changed

drivers/watchdog/f71808e_wdt.c

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -306,27 +306,6 @@ static int watchdog_keepalive(void)
306306
return err;
307307
}
308308

309-
static int f71862fg_pin_configure(unsigned short ioaddr)
310-
{
311-
/* When ioaddr is non-zero the calling function has to take care of
312-
mutex handling and superio preparation! */
313-
314-
if (f71862fg_pin == 63) {
315-
if (ioaddr) {
316-
/* SPI must be disabled first to use this pin! */
317-
superio_clear_bit(ioaddr, SIO_REG_ROM_ADDR_SEL, 6);
318-
superio_set_bit(ioaddr, SIO_REG_MFUNCT3, 4);
319-
}
320-
} else if (f71862fg_pin == 56) {
321-
if (ioaddr)
322-
superio_set_bit(ioaddr, SIO_REG_MFUNCT1, 1);
323-
} else {
324-
pr_err("Invalid argument f71862fg_pin=%d\n", f71862fg_pin);
325-
return -EINVAL;
326-
}
327-
return 0;
328-
}
329-
330309
static int watchdog_start(void)
331310
{
332311
int err;
@@ -352,9 +331,13 @@ static int watchdog_start(void)
352331
break;
353332

354333
case f71862fg:
355-
err = f71862fg_pin_configure(watchdog.sioaddr);
356-
if (err)
357-
goto exit_superio;
334+
if (f71862fg_pin == 63) {
335+
/* SPI must be disabled first to use this pin! */
336+
superio_clear_bit(watchdog.sioaddr, SIO_REG_ROM_ADDR_SEL, 6);
337+
superio_set_bit(watchdog.sioaddr, SIO_REG_MFUNCT3, 4);
338+
} else if (f71862fg_pin == 56) {
339+
superio_set_bit(watchdog.sioaddr, SIO_REG_MFUNCT1, 1);
340+
}
358341
break;
359342

360343
case f71868:
@@ -810,7 +793,6 @@ static int __init f71808e_find(int sioaddr)
810793
break;
811794
case SIO_F71862_ID:
812795
watchdog.type = f71862fg;
813-
err = f71862fg_pin_configure(0); /* validate module parameter */
814796
break;
815797
case SIO_F71868_ID:
816798
watchdog.type = f71868;
@@ -859,6 +841,11 @@ static int __init f71808e_init(void)
859841
int err = -ENODEV;
860842
int i;
861843

844+
if (f71862fg_pin != 63 && f71862fg_pin != 56) {
845+
pr_err("Invalid argument f71862fg_pin=%d\n", f71862fg_pin);
846+
return -EINVAL;
847+
}
848+
862849
for (i = 0; i < ARRAY_SIZE(addrs); i++) {
863850
err = f71808e_find(addrs[i]);
864851
if (err == 0)

0 commit comments

Comments
 (0)