mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-12-04 01:24:12 +08:00
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 <a.fatoum@pengutronix.de> Reviewed-by: Guenter Roeck <linux@roeck-us.net> Link: https://lore.kernel.org/r/20200611191750.28096-6-a.fatoum@pengutronix.de Signed-off-by: Guenter Roeck <linux@roeck-us.net> Signed-off-by: Wim Van Sebroeck <wim@linux-watchdog.org>
This commit is contained in:
parent
4f39d57584
commit
5edc8c6873
@ -306,27 +306,6 @@ exit_unlock:
|
|||||||
return err;
|
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)
|
static int watchdog_start(void)
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
@ -352,9 +331,13 @@ static int watchdog_start(void)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case f71862fg:
|
case f71862fg:
|
||||||
err = f71862fg_pin_configure(watchdog.sioaddr);
|
if (f71862fg_pin == 63) {
|
||||||
if (err)
|
/* SPI must be disabled first to use this pin! */
|
||||||
goto exit_superio;
|
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;
|
break;
|
||||||
|
|
||||||
case f71868:
|
case f71868:
|
||||||
@ -810,7 +793,6 @@ static int __init f71808e_find(int sioaddr)
|
|||||||
break;
|
break;
|
||||||
case SIO_F71862_ID:
|
case SIO_F71862_ID:
|
||||||
watchdog.type = f71862fg;
|
watchdog.type = f71862fg;
|
||||||
err = f71862fg_pin_configure(0); /* validate module parameter */
|
|
||||||
break;
|
break;
|
||||||
case SIO_F71868_ID:
|
case SIO_F71868_ID:
|
||||||
watchdog.type = f71868;
|
watchdog.type = f71868;
|
||||||
@ -859,6 +841,11 @@ static int __init f71808e_init(void)
|
|||||||
int err = -ENODEV;
|
int err = -ENODEV;
|
||||||
int i;
|
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++) {
|
for (i = 0; i < ARRAY_SIZE(addrs); i++) {
|
||||||
err = f71808e_find(addrs[i]);
|
err = f71808e_find(addrs[i]);
|
||||||
if (err == 0)
|
if (err == 0)
|
||||||
|
Loading…
Reference in New Issue
Block a user