Skip to contentSkip to conversation

watchdog: ftwdt010_wdt: add _restart() function

PATCH In review Sergei Antonov 2 participants 5 messages Aug 26, 2022 Watchdog device drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 watchdog: ftwdt010_wdt: add _restart() function

Add a missing _restart function to watchdog_ops. FTWDT010 resets system when it is started with timeout = 0.

---
 drivers/watchdog/ftwdt010_wdt.c | 8 ++++++++
 1 file changed, 8 insertions(+)
drivers/watchdog/ftwdt010_wdt.c +8 -0
index 21dcc7765688..9eaaaca1094d 100644
@@ -93,6 +93,13 @@ static int ftwdt010_wdt_set_timeout(struct watchdog_device *wdd,
 	return 0;
 }
 
+static int ftwdt010_wdt_restart(struct watchdog_device *wdd,
+				unsigned long action, void *data)
+{
+	wdd->timeout = 0;
+	return ftwdt010_wdt_start(wdd);
+}
+
 static irqreturn_t ftwdt010_wdt_interrupt(int irq, void *data)
 {
 	struct ftwdt010_wdt *gwdt = data;
@@ -107,6 +114,7 @@ static const struct watchdog_ops ftwdt010_wdt_ops = {
 	.stop		= ftwdt010_wdt_stop,
 	.ping		= ftwdt010_wdt_ping,
 	.set_timeout	= ftwdt010_wdt_set_timeout,
+	.restart	= ftwdt010_wdt_restart,
 	.owner		= THIS_MODULE,
 };
 
Signature · 1 line
2.34.1
maintainer
#1 lore raw
Quoted 1 line · Sergei Antonov

Add a missing _restart function to watchdog_ops.

The restart function isn't "missing" because it is optional.

Quoted 12 lines

FTWDT010 resets system when it is started with timeout = 0.

---
 drivers/watchdog/ftwdt010_wdt.c | 8 ++++++++
 1 file changed, 8 insertions(+)
drivers/watchdog/ftwdt010_wdt.c +0 -0
index 21dcc7765688..9eaaaca1094d 100644

drivers/watchdog/ftwdt010_wdt.c static int ftwdt010_wdt_set_timeout(struct watchdog_device *wdd, · line 100

Quoted 8 lines
drivers/watchdog/ftwdt010_wdt.c +5 -0
@@ -93,6 +93,13 @@ static int ftwdt010_wdt_set_timeout(struct watchdog_device *wdd,
 	return 0;
 }
 
+static int ftwdt010_wdt_restart(struct watchdog_device *wdd,
+				unsigned long action, void *data)
+{
+	wdd->timeout = 0;
+	return ftwdt010_wdt_start(wdd);

While technically correct, this crates the impression that ftwdt010_wdt_start() might return an error - which it never does. Given that, I would prefer

	ftwdt010_wdt_start(wdd);
	return 0;

Also, did you make sure that interrupt support does not interfer with restart ? We don't want to get an interrupt when the watchdog fires due to a call to the restart handler.

Thanks,
Guenter

Quoted 16 lines
drivers/watchdog/ftwdt010_wdt.c +3 -0
+}
+
 static irqreturn_t ftwdt010_wdt_interrupt(int irq, void *data)
 {
 	struct ftwdt010_wdt *gwdt = data;
@@ -107,6 +114,7 @@ static const struct watchdog_ops ftwdt010_wdt_ops = {
 	.stop		= ftwdt010_wdt_stop,
 	.ping		= ftwdt010_wdt_ping,
 	.set_timeout	= ftwdt010_wdt_set_timeout,
+	.restart	= ftwdt010_wdt_restart,
 	.owner		= THIS_MODULE,
 };
 
Signature · 1 line
2.34.1
#2 lore raw
Quoted 30 lines · Guenter Roeck
Quoted 1 line · Sergei Antonov

Add a missing _restart function to watchdog_ops.

The restart function isn't "missing" because it is optional.

Quoted 12 lines

FTWDT010 resets system when it is started with timeout = 0.

---
 drivers/watchdog/ftwdt010_wdt.c | 8 ++++++++
 1 file changed, 8 insertions(+)
drivers/watchdog/ftwdt010_wdt.c +0 -0
index 21dcc7765688..9eaaaca1094d 100644

drivers/watchdog/ftwdt010_wdt.c static int ftwdt010_wdt_set_timeout(struct watchdog_device *wdd, · line 100

Quoted 8 lines
drivers/watchdog/ftwdt010_wdt.c +5 -0
@@ -93,6 +93,13 @@ static int ftwdt010_wdt_set_timeout(struct watchdog_device *wdd,
      return 0;
 }
 
+static int ftwdt010_wdt_restart(struct watchdog_device *wdd,
+                             unsigned long action, void *data)
+{
+     wdd->timeout = 0;
+     return ftwdt010_wdt_start(wdd);

While technically correct, this crates the impression that ftwdt010_wdt_start() might return an error - which it never does. Given that, I would prefer

Quoted 2 lines
        ftwdt010_wdt_start(wdd);
        return 0;

Why loose the return value? My code lets it propagate. It is potentially non-zero.

Quoted 3 lines

Also, did you make sure that interrupt support does not interfer with restart ? We don't want to get an interrupt when the watchdog fires due to a call to the restart handler.

No, I did not test watchdog interrupt on my hardware (don't' know yet how to set it up correctly). I only tested that restart restarts the hardware as expected.
Now that I think of it, it may be more precise to do gwdt->has_irq = false;
before calling ftwdt010_wdt_start()
So that WDCR_WDINTR flag will not be set and the chip will not trigger an interrupt.

maintainer
#3 lore raw
Quoted 34 lines · Sergei Antonov
Quoted 30 lines · Guenter Roeck
Quoted 1 line · Sergei Antonov

Add a missing _restart function to watchdog_ops.

The restart function isn't "missing" because it is optional.

Quoted 12 lines

FTWDT010 resets system when it is started with timeout = 0.

---
 drivers/watchdog/ftwdt010_wdt.c | 8 ++++++++
 1 file changed, 8 insertions(+)
drivers/watchdog/ftwdt010_wdt.c +0 -0
index 21dcc7765688..9eaaaca1094d 100644

drivers/watchdog/ftwdt010_wdt.c static int ftwdt010_wdt_set_timeout(struct watchdog_device *wdd, · line 100

Quoted 8 lines
drivers/watchdog/ftwdt010_wdt.c +5 -0
@@ -93,6 +93,13 @@ static int ftwdt010_wdt_set_timeout(struct watchdog_device *wdd,
      return 0;
 }
 
+static int ftwdt010_wdt_restart(struct watchdog_device *wdd,
+                             unsigned long action, void *data)
+{
+     wdd->timeout = 0;
+     return ftwdt010_wdt_start(wdd);

While technically correct, this crates the impression that ftwdt010_wdt_start() might return an error - which it never does. Given that, I would prefer

Quoted 2 lines
        ftwdt010_wdt_start(wdd);
        return 0;
Quoted 3 lines

Why loose the return value? My code lets it propagate. It is potentially non-zero.

No, it never is. Look at the code. That is the whole point.

Quoted 4 lines
Quoted 3 lines

Also, did you make sure that interrupt support does not interfer with restart ? We don't want to get an interrupt when the watchdog fires due to a call to the restart handler.

Quoted 8 lines

No, I did not test watchdog interrupt on my hardware (don't' know yet how to set it up correctly). I only tested that restart restarts the hardware as expected.
Now that I think of it, it may be more precise to do gwdt->has_irq = false;
before calling ftwdt010_wdt_start()
So that WDCR_WDINTR flag will not be set and the chip will not trigger an interrupt.

In that case I'd rather see a separate function which is called from both ftwdt010_wdt_start() and the restart function and has timeout and the interrupt flag as parameters. That would also address the never-happening error return.

Thanks,
Guenter

#4 lore raw
Quoted 12 lines · Guenter Roeck
Quoted 12 lines
Quoted 11 lines

drivers/watchdog/ftwdt010_wdt.c static int ftwdt010_wdt_set_timeout(struct watchdog_device *wdd, · line 100

Quoted 5 lines
drivers/watchdog/ftwdt010_wdt.c +5 -0
+static int ftwdt010_wdt_restart(struct watchdog_device *wdd,
+                             unsigned long action, void *data)
+{
+     wdd->timeout = 0;
+     return ftwdt010_wdt_start(wdd);

While technically correct, this crates the impression that ftwdt010_wdt_start() might return an error - which it never does. Given that, I would prefer

        ftwdt010_wdt_start(wdd);
        return 0;
Quoted 4 lines
Quoted 3 lines

Why loose the return value? My code lets it propagate. It is potentially non-zero.

No, it never is. Look at the code. That is the whole point.

Of course I looked at ftwdt010_wdt_start() and saw it always returning
0. By "potentially" I meant it returning errors too in the future.

Quoted 13 lines
Quoted 4 lines
Quoted 3 lines

Also, did you make sure that interrupt support does not interfer with restart ? We don't want to get an interrupt when the watchdog fires due to a call to the restart handler.

Quoted 8 lines

No, I did not test watchdog interrupt on my hardware (don't' know yet how to set it up correctly). I only tested that restart restarts the hardware as expected.
Now that I think of it, it may be more precise to do gwdt->has_irq = false;
before calling ftwdt010_wdt_start()
So that WDCR_WDINTR flag will not be set and the chip will not trigger an interrupt.

Quoted 3 lines

In that case I'd rather see a separate function which is called from both ftwdt010_wdt_start() and the restart function and has timeout and the interrupt flag as parameters. That would also address the never-happening error return.

OK. Submitting a new patch.