From 4b430a76785d630e399e60466fdc66cec3a74805 Mon Sep 17 00:00:00 2001 From: John Kacur Date: Thu, 14 Aug 2014 16:03:07 +0200 Subject: cyclictest: Always print an err message if write of 0 to cpu-dma_latency fails In set_latency_target() there are some paths that don't print an error message even when a write of 0 to /dev/cpu_dma_latency fails. This patch does the following - always print an error message if the write to /dev/cpu_dma_latency fails - Fix the error check with the write call. (a return of 0 or -1 indicate problems - rename ret to err since this function is void and returns no value - use err_msg_n instead of printf (which also prints to stderr) Signed-off-by: John Kacur --- src/cyclictest/cyclictest.c | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/src/cyclictest/cyclictest.c b/src/cyclictest/cyclictest.c index 01dfc75..64f1764 100644 --- a/src/cyclictest/cyclictest.c +++ b/src/cyclictest/cyclictest.c @@ -233,20 +233,30 @@ static int32_t latency_target_value = 0; static void set_latency_target(void) { struct stat s; - int ret; + int err; - if (stat("/dev/cpu_dma_latency", &s) == 0) { - latency_target_fd = open("/dev/cpu_dma_latency", O_RDWR); - if (latency_target_fd == -1) - return; - ret = write(latency_target_fd, &latency_target_value, 4); - if (ret == 0) { - printf("# error setting cpu_dma_latency to %d!: %s\n", latency_target_value, strerror(errno)); - close(latency_target_fd); - return; - } - printf("# /dev/cpu_dma_latency set to %dus\n", latency_target_value); + errno = 0; + err = stat("/dev/cpu_dma_latency", &s); + if (err == -1) { + err_msg_n(errno, "WARN: stat /dev/cpu_dma_latency failed"); + return; + } + + errno = 0; + latency_target_fd = open("/dev/cpu_dma_latency", O_RDWR); + if (latency_target_fd == -1) { + err_msg_n(errno, "WARN: open /dev/cpu_dma_latency"); + return; + } + + errno = 0; + err = write(latency_target_fd, &latency_target_value, 4); + if (err < 1) { + err_msg_n(errno, "# error setting cpu_dma_latency to %d!", latency_target_value); + close(latency_target_fd); + return; } + printf("# /dev/cpu_dma_latency set to %dus\n", latency_target_value); } -- cgit 1.2.3-korg