Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Acked-by: Timur Tabi <timur@codeaurora.org>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Wim Van Sebroeck <wim@iguana.be>

authored by

Arnd Bergmann and committed by
Wim Van Sebroeck
9dd8d5f8 e035d8f7

+11 -3
+11 -3
Documentation/watchdog/src/watchdog-test.c
··· 2 2 * Watchdog Driver Test Program 3 3 */ 4 4 5 + #include <errno.h> 5 6 #include <stdio.h> 6 7 #include <stdlib.h> 7 8 #include <string.h> ··· 36 35 37 36 static void term(int sig) 38 37 { 39 - write(fd, &v, 1); 38 + int ret = write(fd, &v, 1); 39 + 40 40 close(fd); 41 - printf("\nStopping watchdog ticks...\n"); 41 + if (ret < 0) 42 + printf("\nStopping watchdog ticks failed (%d)...\n", errno); 43 + else 44 + printf("\nStopping watchdog ticks...\n"); 42 45 exit(0); 43 46 } 44 47 ··· 50 45 { 51 46 int flags; 52 47 unsigned int ping_rate = 1; 48 + int ret; 53 49 54 50 setbuf(stdout, NULL); 55 51 ··· 97 91 sleep(ping_rate); 98 92 } 99 93 end: 100 - write(fd, &v, 1); 94 + ret = write(fd, &v, 1); 95 + if (ret < 0) 96 + printf("Stopping watchdog ticks failed (%d)...\n", errno); 101 97 close(fd); 102 98 return 0; 103 99 }