Skip to contentSkip to conversation

Documentation/watchdog: check return value for magic close

PATCH In review Arnd Bergmann 3 participants 3 messages Jul 19, 2016 – Jul 22, 2016

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 Documentation/watchdog: check return value for magic close

A recent commit added a write to the watchdog test code for doing the "magic close", but that caused a compile-time warning:

Documentation/watchdog/src/watchdog-test.c: In function ‘main’:
Documentation/watchdog/src/watchdog-test.c:94:5: warning: ignoring return value of ‘write’, declared with attribute warn_unused_result [-Wunused-result]

This changes the code to print a runtime warning if the write fails.

Fixes 5a2d3de19602 ("Documentation/watchdog: add support for magic close to watchdog-test")

---
v2: fix typo as pointed out by both Guenter Roeck and Randy Dunlap

---
 Documentation/watchdog/src/watchdog-test.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)
Documentation/watchdog/src/watchdog-test.c +11 -3
index c69153913722..6983d05097e2 100644
@@ -2,6 +2,7 @@
  * Watchdog Driver Test Program
  */
 
+#include <errno.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -35,9 +36,13 @@ static void keep_alive(void)
 
 static void term(int sig)
 {
-    write(fd, &v, 1);
+    int ret = write(fd, &v, 1);
+
     close(fd);
-    printf("\nStopping watchdog ticks...\n");
+    if (ret < 0)
+	printf("\nStopping watchdog ticks failed (%d)...\n", errno);
+    else
+	printf("\nStopping watchdog ticks...\n");
     exit(0);
 }
 
@@ -45,6 +50,7 @@ int main(int argc, char *argv[])
 {
     int flags;
     unsigned int ping_rate = 1;
+    int ret;
 
     setbuf(stdout, NULL);
 
@@ -91,7 +97,9 @@ int main(int argc, char *argv[])
 	sleep(ping_rate);
     }
 end:
-    write(fd, &v, 1);
+    ret = write(fd, &v, 1);
+    if (ret < 0)
+	printf("Stopping watchdog ticks failed (%d)...\n", errno);
     close(fd);
     return 0;
 }
Signature · 1 line
2.9.0
maintainer Reviewed-by on v2 1/1
#1 lore raw
Quoted 10 lines · Arnd Bergmann

A recent commit added a write to the watchdog test code for doing the "magic close", but that caused a compile-time warning:

Documentation/watchdog/src/watchdog-test.c: In function ‘main’:
Documentation/watchdog/src/watchdog-test.c:94:5: warning: ignoring return value of ‘write’, declared with attribute warn_unused_result [-Wunused-result]

This changes the code to print a runtime warning if the write fails.

Fixes 5a2d3de19602 ("Documentation/watchdog: add support for magic close to watchdog-test")
Quoted 54 lines

---
v2: fix typo as pointed out by both Guenter Roeck and Randy Dunlap

---
  Documentation/watchdog/src/watchdog-test.c | 14 +++++++++++---
  1 file changed, 11 insertions(+), 3 deletions(-)
Documentation/watchdog/src/watchdog-test.c +11 -3
index c69153913722..6983d05097e2 100644
@@ -2,6 +2,7 @@
   * Watchdog Driver Test Program
   */
 
+#include <errno.h>
  #include <stdio.h>
  #include <stdlib.h>
  #include <string.h>
@@ -35,9 +36,13 @@ static void keep_alive(void)
 
  static void term(int sig)
  {
-    write(fd, &v, 1);
+    int ret = write(fd, &v, 1);
+
      close(fd);
-    printf("\nStopping watchdog ticks...\n");
+    if (ret < 0)
+	printf("\nStopping watchdog ticks failed (%d)...\n", errno);
+    else
+	printf("\nStopping watchdog ticks...\n");
      exit(0);
  }
 
@@ -45,6 +50,7 @@ int main(int argc, char *argv[])
  {
      int flags;
      unsigned int ping_rate = 1;
+    int ret;
 
      setbuf(stdout, NULL);
 
@@ -91,7 +97,9 @@ int main(int argc, char *argv[])
  	sleep(ping_rate);
      }
  end:
-    write(fd, &v, 1);
+    ret = write(fd, &v, 1);
+    if (ret < 0)
+	printf("Stopping watchdog ticks failed (%d)...\n", errno);
      close(fd);
      return 0;
  }
Acked-by on v2 1/1
#2 lore raw
In reply to Arnd Bergmann
Quoted 10 lines · Arnd Bergmann

A recent commit added a write to the watchdog test code for doing the "magic close", but that caused a compile-time warning:

Documentation/watchdog/src/watchdog-test.c: In function ‘main’:
Documentation/watchdog/src/watchdog-test.c:94:5: warning: ignoring return value of ‘write’, declared with attribute warn_unused_result [-Wunused-result]

This changes the code to print a runtime warning if the write fails.

Fixes 5a2d3de19602 ("Documentation/watchdog: add support for magic close to watchdog-test")

Thanks for this patch. I don't know why I didn't notice the warnings before.

Signature · 3 lines
Qualcomm Datacenter Technologies, Inc. as an affiliate of Qualcomm
Technologies, Inc.  Qualcomm Technologies, Inc. is a member of the
Code Aurora Forum, a Linux Foundation Collaborative Project.