* [PATCH 0/8] Fix -Wunused-result warnings by checking return values
@ 2025-07-12 13:42 Cheng-Yang Chou
2025-07-12 13:42 ` [PATCH 1/8] rt-utils.c: Suppress warning Cheng-Yang Chou
` (8 more replies)
0 siblings, 9 replies; 15+ messages in thread
From: Cheng-Yang Chou @ 2025-07-12 13:42 UTC (permalink / raw)
To: williams, jkacur; +Cc: linux-rt-users, jserv, yphbchou0911
This patch series adds proper error checking to functions such as write(),
ftruncate(), and system(), whose return values were previously ignored.
These warnings were treated as errors under -Werror due to the
__attribute__((warn_unused_result)) annotation. Instead of suppressing
them with compiler flags, this series addresses each call site directly
to improve code robustness and clarity.
A full list of compiler warnings fixed in this series is available at:
https://gist.github.com/EricccTaiwan/a78d6f1950d3cba27be757e405b6626a
Tested on Ubuntu 25.04 (GCC 14.2.0, glibc 2.41).
Thanks.
-chengyang
---
Cheng-Yang Chou (8):
rt-utils.c: Suppress warning
pmqtest.c: Suppress warning
ptsematest.c: Suppress warning
rt-migrate-test.c: Suppress warning
cyclicdeadline.c: Suppress warning
deadline_test.c: Suppress warning
sigwaittest.c: Suppress warning
svsematest.c: Suppress warning
src/lib/rt-utils.c | 9 +++++--
src/pmqtest/pmqtest.c | 6 ++++-
src/ptsematest/ptsematest.c | 6 ++++-
src/rt-migrate-test/rt-migrate-test.c | 5 +++-
src/sched_deadline/cyclicdeadline.c | 32 +++++++++++++++++++----
src/sched_deadline/deadline_test.c | 37 +++++++++++++++++++++++----
src/sigwaittest/sigwaittest.c | 13 ++++++++--
src/svsematest/svsematest.c | 13 ++++++++--
8 files changed, 102 insertions(+), 19 deletions(-)
--
2.48.1
^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH 1/8] rt-utils.c: Suppress warning
2025-07-12 13:42 [PATCH 0/8] Fix -Wunused-result warnings by checking return values Cheng-Yang Chou
@ 2025-07-12 13:42 ` Cheng-Yang Chou
2025-07-25 18:04 ` John Kacur
2025-07-12 13:42 ` [PATCH 2/8] pmqtest.c: " Cheng-Yang Chou
` (7 subsequent siblings)
8 siblings, 1 reply; 15+ messages in thread
From: Cheng-Yang Chou @ 2025-07-12 13:42 UTC (permalink / raw)
To: williams, jkacur; +Cc: linux-rt-users, jserv, yphbchou0911
Signed-off-by: Cheng-Yang Chou <yphbchou0911@gmail.com>
---
src/lib/rt-utils.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/src/lib/rt-utils.c b/src/lib/rt-utils.c
index 6bbd25a..18e515f 100644
--- a/src/lib/rt-utils.c
+++ b/src/lib/rt-utils.c
@@ -465,6 +465,7 @@ void tracemark(char *fmt, ...)
{
va_list ap;
int len;
+ int ret;
/* bail out if we're not tracing */
/* or if the kernel doesn't support trace_mark */
@@ -476,10 +477,14 @@ void tracemark(char *fmt, ...)
va_end(ap);
/* write the tracemark message */
- write(tracemark_fd, tracebuf, len);
+ ret = write(tracemark_fd, tracebuf, len);
+ if (ret != len)
+ warn("tracemark write failed");
/* now stop any trace */
- write(trace_fd, "0\n", 2);
+ ret = write(trace_fd, "0\n", 2);
+ if (ret != 2)
+ warn("trace stop write failed");
}
void enable_trace_mark(void)
--
2.48.1
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH 2/8] pmqtest.c: Suppress warning
2025-07-12 13:42 [PATCH 0/8] Fix -Wunused-result warnings by checking return values Cheng-Yang Chou
2025-07-12 13:42 ` [PATCH 1/8] rt-utils.c: Suppress warning Cheng-Yang Chou
@ 2025-07-12 13:42 ` Cheng-Yang Chou
2025-07-25 18:07 ` John Kacur
2025-07-12 13:42 ` [PATCH 3/8] ptsematest.c: " Cheng-Yang Chou
` (6 subsequent siblings)
8 siblings, 1 reply; 15+ messages in thread
From: Cheng-Yang Chou @ 2025-07-12 13:42 UTC (permalink / raw)
To: williams, jkacur; +Cc: linux-rt-users, jserv, yphbchou0911
Signed-off-by: Cheng-Yang Chou <yphbchou0911@gmail.com>
---
src/pmqtest/pmqtest.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/src/pmqtest/pmqtest.c b/src/pmqtest/pmqtest.c
index 04e36a1..eb20baa 100644
--- a/src/pmqtest/pmqtest.c
+++ b/src/pmqtest/pmqtest.c
@@ -75,6 +75,7 @@ void *pmqthread(void *param)
int policy = SCHED_FIFO;
struct sched_param schedp;
struct timespec ts;
+ int ret;
memset(&schedp, 0, sizeof(schedp));
schedp.sched_priority = par->priority;
@@ -189,7 +190,10 @@ void *pmqthread(void *param)
int tracing_enabled =
open(tracing_enabled_file, O_WRONLY);
if (tracing_enabled >= 0) {
- write(tracing_enabled, "0", 1);
+ ret = write(tracing_enabled, "0", 1);
+ if (ret < 0)
+ fatal("Could not write to %s: %s\n",
+ tracing_enabled_file, strerror(errno));
close(tracing_enabled);
} else
fatal("Could not access %s\n", tracing_enabled_file);
--
2.48.1
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH 3/8] ptsematest.c: Suppress warning
2025-07-12 13:42 [PATCH 0/8] Fix -Wunused-result warnings by checking return values Cheng-Yang Chou
2025-07-12 13:42 ` [PATCH 1/8] rt-utils.c: Suppress warning Cheng-Yang Chou
2025-07-12 13:42 ` [PATCH 2/8] pmqtest.c: " Cheng-Yang Chou
@ 2025-07-12 13:42 ` Cheng-Yang Chou
2025-07-25 18:09 ` John Kacur
2025-07-12 13:42 ` [PATCH 4/8] rt-migrate-test.c: " Cheng-Yang Chou
` (5 subsequent siblings)
8 siblings, 1 reply; 15+ messages in thread
From: Cheng-Yang Chou @ 2025-07-12 13:42 UTC (permalink / raw)
To: williams, jkacur; +Cc: linux-rt-users, jserv, yphbchou0911
Signed-off-by: Cheng-Yang Chou <yphbchou0911@gmail.com>
---
src/ptsematest/ptsematest.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/src/ptsematest/ptsematest.c b/src/ptsematest/ptsematest.c
index d211669..787909c 100644
--- a/src/ptsematest/ptsematest.c
+++ b/src/ptsematest/ptsematest.c
@@ -62,6 +62,7 @@ void *semathread(void *param)
cpu_set_t mask;
int policy = SCHED_FIFO;
struct sched_param schedp;
+ int ret;
memset(&schedp, 0, sizeof(schedp));
schedp.sched_priority = par->priority;
@@ -112,7 +113,10 @@ void *semathread(void *param)
int tracing_enabled =
open(tracing_enabled_file, O_WRONLY);
if (tracing_enabled >= 0) {
- write(tracing_enabled, "0", 1);
+ ret = write(tracing_enabled, "0", 1);
+ if (ret < 0)
+ fatal("Could not write to %s: %s\n",
+ tracing_enabled_file, strerror(errno));
close(tracing_enabled);
} else
fatal("Could not access %s\n",
--
2.48.1
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH 4/8] rt-migrate-test.c: Suppress warning
2025-07-12 13:42 [PATCH 0/8] Fix -Wunused-result warnings by checking return values Cheng-Yang Chou
` (2 preceding siblings ...)
2025-07-12 13:42 ` [PATCH 3/8] ptsematest.c: " Cheng-Yang Chou
@ 2025-07-12 13:42 ` Cheng-Yang Chou
2025-07-25 18:10 ` John Kacur
2025-07-12 13:42 ` [PATCH 5/8] cyclicdeadline.c: " Cheng-Yang Chou
` (4 subsequent siblings)
8 siblings, 1 reply; 15+ messages in thread
From: Cheng-Yang Chou @ 2025-07-12 13:42 UTC (permalink / raw)
To: williams, jkacur; +Cc: linux-rt-users, jserv, yphbchou0911
Signed-off-by: Cheng-Yang Chou <yphbchou0911@gmail.com>
---
src/rt-migrate-test/rt-migrate-test.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/src/rt-migrate-test/rt-migrate-test.c b/src/rt-migrate-test/rt-migrate-test.c
index 8afe083..d7c0bf3 100644
--- a/src/rt-migrate-test/rt-migrate-test.c
+++ b/src/rt-migrate-test/rt-migrate-test.c
@@ -61,6 +61,7 @@ static void ftrace_write(const char *fmt, ...)
{
va_list ap;
int n;
+ int ret;
if (mark_fd < 0)
return;
@@ -69,7 +70,9 @@ static void ftrace_write(const char *fmt, ...)
n = vsnprintf(buff, BUFSIZ, fmt, ap);
va_end(ap);
- write(mark_fd, buff, n);
+ ret = write(mark_fd, buff, n);
+ if (ret < 0)
+ perror("ftrace_write failed");
}
#define nano2sec(nan) (nan / 1000000000ULL)
--
2.48.1
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH 5/8] cyclicdeadline.c: Suppress warning
2025-07-12 13:42 [PATCH 0/8] Fix -Wunused-result warnings by checking return values Cheng-Yang Chou
` (3 preceding siblings ...)
2025-07-12 13:42 ` [PATCH 4/8] rt-migrate-test.c: " Cheng-Yang Chou
@ 2025-07-12 13:42 ` Cheng-Yang Chou
2025-07-12 13:42 ` [PATCH 6/8] deadline_test.c: " Cheng-Yang Chou
` (3 subsequent siblings)
8 siblings, 0 replies; 15+ messages in thread
From: Cheng-Yang Chou @ 2025-07-12 13:42 UTC (permalink / raw)
To: williams, jkacur; +Cc: linux-rt-users, jserv, yphbchou0911
Signed-off-by: Cheng-Yang Chou <yphbchou0911@gmail.com>
---
src/sched_deadline/cyclicdeadline.c | 32 ++++++++++++++++++++++++-----
1 file changed, 27 insertions(+), 5 deletions(-)
diff --git a/src/sched_deadline/cyclicdeadline.c b/src/sched_deadline/cyclicdeadline.c
index 04e61ed..f1a0ba0 100644
--- a/src/sched_deadline/cyclicdeadline.c
+++ b/src/sched_deadline/cyclicdeadline.c
@@ -206,6 +206,7 @@ static void ftrace_write(char *buf, const char *fmt, ...)
{
va_list ap;
int n;
+ int ret;
if (mark_fd < 0)
return;
@@ -214,7 +215,9 @@ static void ftrace_write(char *buf, const char *fmt, ...)
n = my_vsprintf(buf, BUFSIZ, fmt, ap);
va_end(ap);
- write(mark_fd, buf, n);
+ ret = write(mark_fd, buf, n);
+ if (ret < 0)
+ perror("ftrace write failed");
}
static void setup_ftrace_marker(void)
@@ -448,6 +451,10 @@ static int mount_cpuset(void)
if (fd < 0)
return fd;
ret = write(fd, "0", 2);
+ if (ret < 0) {
+ close(fd);
+ return ret;
+ }
close(fd);
return 0;
@@ -634,7 +641,14 @@ static void destroy_cpuset(const char *name, int print)
sprintf(buf, "%d", pid);
if (print)
printf("Moving %d out of %s\n", pid, name);
- write(fd, buf, strlen(buf));
+ ret = write(fd, buf, strlen(buf));
+ if (ret < 0 && errno == ENOSPC) {
+ fclose(fp);
+ close(fd);
+ fatal("Cannot move tasks out of cpuset %s\n", name);
+ }
+
+
}
fclose(fp);
close(fd);
@@ -656,19 +670,24 @@ static void destroy_cpuset(const char *name, int print)
static void teardown(void)
{
int fd;
+ int ret;
if (all_cpus)
return;
fd = open_cpuset(CPUSET_PATH, "cpuset.cpu_exclusive");
if (fd >= 0) {
- write(fd, "0", 2);
+ ret = write(fd, "0", 2);
+ if (ret < 0)
+ perror("cpuset.cpu_exclusive");
close(fd);
}
fd = open_cpuset(CPUSET_PATH, "cpuset.sched_load_balance");
if (fd >= 0) {
- write(fd, "1", 2);
+ ret = write(fd, "1", 2);
+ if (ret < 0)
+ perror("cpuset.sched_load_balance");
close(fd);
}
@@ -1164,6 +1183,7 @@ int main(int argc, char **argv)
int nr_cpus;
int i;
int c;
+ int ret;
rt_init(argc, argv);
@@ -1387,7 +1407,9 @@ int main(int argc, char **argv)
CPUSET_FL_CLONE_CHILDREN |
CPUSET_FL_TASKS, pids);
- system("cat /sys/fs/cgroup/cpuset/my_cpuset/tasks");
+ ret = system("cat /sys/fs/cgroup/cpuset/my_cpuset/tasks");
+ if (ret < 0)
+ perror("system call failed");
}
debug(debug_enable, "main thread %d\n", gettid());
--
2.48.1
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH 6/8] deadline_test.c: Suppress warning
2025-07-12 13:42 [PATCH 0/8] Fix -Wunused-result warnings by checking return values Cheng-Yang Chou
` (4 preceding siblings ...)
2025-07-12 13:42 ` [PATCH 5/8] cyclicdeadline.c: " Cheng-Yang Chou
@ 2025-07-12 13:42 ` Cheng-Yang Chou
2025-07-12 13:42 ` [PATCH 7/8] sigwaittest.c: " Cheng-Yang Chou
` (2 subsequent siblings)
8 siblings, 0 replies; 15+ messages in thread
From: Cheng-Yang Chou @ 2025-07-12 13:42 UTC (permalink / raw)
To: williams, jkacur; +Cc: linux-rt-users, jserv, yphbchou0911
Signed-off-by: Cheng-Yang Chou <yphbchou0911@gmail.com>
---
src/sched_deadline/deadline_test.c | 37 ++++++++++++++++++++++++++----
1 file changed, 32 insertions(+), 5 deletions(-)
diff --git a/src/sched_deadline/deadline_test.c b/src/sched_deadline/deadline_test.c
index ca2da47..4f9a6a6 100644
--- a/src/sched_deadline/deadline_test.c
+++ b/src/sched_deadline/deadline_test.c
@@ -325,6 +325,7 @@ static void ftrace_write(char *buf, const char *fmt, ...)
{
va_list ap;
int n;
+ int ret;
if (mark_fd < 0)
return;
@@ -333,7 +334,9 @@ static void ftrace_write(char *buf, const char *fmt, ...)
n = my_vsprintf(buf, BUFSIZ, fmt, ap);
va_end(ap);
- write(mark_fd, buf, n);
+ ret = write(mark_fd, buf, n);
+ if (ret < 0)
+ perror("ftrace write failed");
}
/**
@@ -626,6 +629,10 @@ static int mount_cpuset(void)
if (fd < 0)
return fd;
ret = write(fd, "0", 2);
+ if (ret < 0) {
+ close(fd);
+ return ret;
+ }
close(fd);
return 0;
@@ -875,7 +882,19 @@ static void destroy_cpuset(const char *name, int print)
sprintf(buf, "%d", pid);
if (print)
printf("Moving %d out of %s\n", pid, name);
- write(fd, buf, strlen(buf));
+ ret = write(fd, buf, strlen(buf));
+ if(ret<0 && errno == ENOSPC) {
+ /*
+ * If we get ENOSPC, then we have a problem, as it
+ * means that the cpuset is full, and we cannot move
+ * the tasks out of it.
+ */
+ fclose(fp);
+ close(fd);
+ fprintf(stderr, "Failed to move %d out of %s\n", pid, name);
+ perror("write");
+ return;
+ }
}
fclose(fp);
close(fd);
@@ -910,16 +929,21 @@ static void destroy_cpuset(const char *name, int print)
static void teardown(void)
{
int fd;
+ int ret;
fd = open_cpuset(CPUSET_PATH, "cpuset.cpu_exclusive");
if (fd >= 0) {
- write(fd, "0", 2);
+ ret = write(fd, "0", 2);
+ if (ret < 0)
+ perror("cpuset.cpu_exclusive");
close(fd);
}
fd = open_cpuset(CPUSET_PATH, "cpuset.sched_load_balance");
if (fd >= 0) {
- write(fd, "1", 2);
+ ret = write(fd, "1", 2);
+ if (ret < 0)
+ perror("cpuset.sched_load_balance");
close(fd);
}
@@ -1790,6 +1814,7 @@ int main(int argc, char **argv)
int rt_task = 0;
int i;
int c;
+ int ret;
cpu_count = sysconf(_SC_NPROCESSORS_CONF);
if (cpu_count < 1) {
@@ -2041,7 +2066,9 @@ int main(int argc, char **argv)
exit(-1);
}
- system("cat /sys/fs/cgroup/cpuset/my_cpuset/tasks");
+ ret = system("cat /sys/fs/cgroup/cpuset/my_cpuset/tasks");
+ if (ret < 0)
+ perror("system call failed");
}
pthread_barrier_wait(&barrier);
--
2.48.1
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH 7/8] sigwaittest.c: Suppress warning
2025-07-12 13:42 [PATCH 0/8] Fix -Wunused-result warnings by checking return values Cheng-Yang Chou
` (5 preceding siblings ...)
2025-07-12 13:42 ` [PATCH 6/8] deadline_test.c: " Cheng-Yang Chou
@ 2025-07-12 13:42 ` Cheng-Yang Chou
2025-07-12 13:42 ` [PATCH 8/8] svsematest.c: " Cheng-Yang Chou
2025-07-25 18:16 ` [PATCH 0/8] Fix -Wunused-result warnings by checking return values John Kacur
8 siblings, 0 replies; 15+ messages in thread
From: Cheng-Yang Chou @ 2025-07-12 13:42 UTC (permalink / raw)
To: williams, jkacur; +Cc: linux-rt-users, jserv, yphbchou0911
Signed-off-by: Cheng-Yang Chou <yphbchou0911@gmail.com>
---
src/sigwaittest/sigwaittest.c | 13 +++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)
diff --git a/src/sigwaittest/sigwaittest.c b/src/sigwaittest/sigwaittest.c
index 026cc81..3944b54 100644
--- a/src/sigwaittest/sigwaittest.c
+++ b/src/sigwaittest/sigwaittest.c
@@ -72,6 +72,7 @@ void *semathread(void *param)
cpu_set_t mask;
int policy = SCHED_FIFO;
struct sched_param schedp;
+ int ret;
memset(&schedp, 0, sizeof(schedp));
schedp.sched_priority = par->priority;
@@ -168,7 +169,10 @@ void *semathread(void *param)
int tracing_enabled =
open(tracing_enabled_file, O_WRONLY);
if (tracing_enabled >= 0) {
- write(tracing_enabled, "0", 1);
+ ret = write(tracing_enabled, "0", 1);
+ if (ret < 0)
+ fatal("Could not write to %s: %s\n",
+ tracing_enabled_file, strerror(errno));
close(tracing_enabled);
} else
fatal("Could not access %s\n",
@@ -489,7 +493,12 @@ int main(int argc, char *argv[])
fprintf(stderr, "Could not create shared memory\n");
return 1;
}
- ftruncate(shmem, totalsize);
+ if (ftruncate(shmem, totalsize) == -1) {
+ perror("ftruncate failed");
+ close(shmem);
+ shm_unlink("/sigwaittest");
+ return 1;
+ }
param = mmap(0, totalsize, PROT_READ|PROT_WRITE, MAP_SHARED,
shmem, 0);
if (param == MAP_FAILED) {
--
2.48.1
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH 8/8] svsematest.c: Suppress warning
2025-07-12 13:42 [PATCH 0/8] Fix -Wunused-result warnings by checking return values Cheng-Yang Chou
` (6 preceding siblings ...)
2025-07-12 13:42 ` [PATCH 7/8] sigwaittest.c: " Cheng-Yang Chou
@ 2025-07-12 13:42 ` Cheng-Yang Chou
2025-07-25 18:16 ` [PATCH 0/8] Fix -Wunused-result warnings by checking return values John Kacur
8 siblings, 0 replies; 15+ messages in thread
From: Cheng-Yang Chou @ 2025-07-12 13:42 UTC (permalink / raw)
To: williams, jkacur; +Cc: linux-rt-users, jserv, yphbchou0911
Signed-off-by: Cheng-Yang Chou <yphbchou0911@gmail.com>
---
src/svsematest/svsematest.c | 13 +++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)
diff --git a/src/svsematest/svsematest.c b/src/svsematest/svsematest.c
index f3cddf8..bdc82bc 100644
--- a/src/svsematest/svsematest.c
+++ b/src/svsematest/svsematest.c
@@ -84,6 +84,7 @@ void *semathread(void *param)
struct sched_param schedp;
struct sembuf sb = { 0, 0, 0};
sigset_t sigset;
+ int ret;
sigemptyset(&sigset);
pthread_sigmask(SIG_SETMASK, &sigset, NULL);
@@ -175,7 +176,10 @@ void *semathread(void *param)
int tracing_enabled =
open(tracing_enabled_file, O_WRONLY);
if (tracing_enabled >= 0) {
- write(tracing_enabled, "0", 1);
+ ret = write(tracing_enabled, "0", 1);
+ if (ret < 0)
+ fatal("Could not write to %s: %s\n",
+ tracing_enabled_file, strerror(errno));
close(tracing_enabled);
} else
fatal("Could not access %s\n",
@@ -544,7 +548,12 @@ int main(int argc, char *argv[])
fprintf(stderr, "Could not create shared memory\n");
return 1;
}
- ftruncate(shmem, totalsize);
+ if (ftruncate(shmem, totalsize) == -1) {
+ perror("ftruncate failed");
+ close(shmem);
+ shm_unlink("/sigwaittest");
+ return 1;
+ }
param = mmap(0, totalsize, PROT_READ|PROT_WRITE, MAP_SHARED,
shmem, 0);
if (param == MAP_FAILED) {
--
2.48.1
^ permalink raw reply related [flat|nested] 15+ messages in thread
* Re: [PATCH 1/8] rt-utils.c: Suppress warning
2025-07-12 13:42 ` [PATCH 1/8] rt-utils.c: Suppress warning Cheng-Yang Chou
@ 2025-07-25 18:04 ` John Kacur
0 siblings, 0 replies; 15+ messages in thread
From: John Kacur @ 2025-07-25 18:04 UTC (permalink / raw)
To: Cheng-Yang Chou; +Cc: williams, linux-rt-users, jserv
On Sat, 12 Jul 2025, Cheng-Yang Chou wrote:
> Signed-off-by: Cheng-Yang Chou <yphbchou0911@gmail.com>
> ---
> src/lib/rt-utils.c | 9 +++++++--
> 1 file changed, 7 insertions(+), 2 deletions(-)
>
> diff --git a/src/lib/rt-utils.c b/src/lib/rt-utils.c
> index 6bbd25a..18e515f 100644
> --- a/src/lib/rt-utils.c
> +++ b/src/lib/rt-utils.c
> @@ -465,6 +465,7 @@ void tracemark(char *fmt, ...)
> {
> va_list ap;
> int len;
> + int ret;
>
> /* bail out if we're not tracing */
> /* or if the kernel doesn't support trace_mark */
> @@ -476,10 +477,14 @@ void tracemark(char *fmt, ...)
> va_end(ap);
>
> /* write the tracemark message */
> - write(tracemark_fd, tracebuf, len);
> + ret = write(tracemark_fd, tracebuf, len);
> + if (ret != len)
> + warn("tracemark write failed");
>
> /* now stop any trace */
> - write(trace_fd, "0\n", 2);
> + ret = write(trace_fd, "0\n", 2);
> + if (ret != 2)
> + warn("trace stop write failed");
> }
>
> void enable_trace_mark(void)
> --
> 2.48.1
>
>
Signed-off-by: John Kacur <jkacur@redhat.com>
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH 2/8] pmqtest.c: Suppress warning
2025-07-12 13:42 ` [PATCH 2/8] pmqtest.c: " Cheng-Yang Chou
@ 2025-07-25 18:07 ` John Kacur
0 siblings, 0 replies; 15+ messages in thread
From: John Kacur @ 2025-07-25 18:07 UTC (permalink / raw)
To: Cheng-Yang Chou; +Cc: williams, linux-rt-users, jserv
On Sat, 12 Jul 2025, Cheng-Yang Chou wrote:
> Signed-off-by: Cheng-Yang Chou <yphbchou0911@gmail.com>
> ---
> src/pmqtest/pmqtest.c | 6 +++++-
> 1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/src/pmqtest/pmqtest.c b/src/pmqtest/pmqtest.c
> index 04e36a1..eb20baa 100644
> --- a/src/pmqtest/pmqtest.c
> +++ b/src/pmqtest/pmqtest.c
> @@ -75,6 +75,7 @@ void *pmqthread(void *param)
> int policy = SCHED_FIFO;
> struct sched_param schedp;
> struct timespec ts;
> + int ret;
>
> memset(&schedp, 0, sizeof(schedp));
> schedp.sched_priority = par->priority;
> @@ -189,7 +190,10 @@ void *pmqthread(void *param)
> int tracing_enabled =
> open(tracing_enabled_file, O_WRONLY);
> if (tracing_enabled >= 0) {
> - write(tracing_enabled, "0", 1);
> + ret = write(tracing_enabled, "0", 1);
> + if (ret < 0)
> + fatal("Could not write to %s: %s\n",
> + tracing_enabled_file, strerror(errno));
> close(tracing_enabled);
> } else
> fatal("Could not access %s\n", tracing_enabled_file);
> --
> 2.48.1
>
>
>
Signed-off-by: John Kacur <jkacur@redhat.com>
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH 3/8] ptsematest.c: Suppress warning
2025-07-12 13:42 ` [PATCH 3/8] ptsematest.c: " Cheng-Yang Chou
@ 2025-07-25 18:09 ` John Kacur
0 siblings, 0 replies; 15+ messages in thread
From: John Kacur @ 2025-07-25 18:09 UTC (permalink / raw)
To: Cheng-Yang Chou; +Cc: williams, linux-rt-users, jserv
On Sat, 12 Jul 2025, Cheng-Yang Chou wrote:
> Signed-off-by: Cheng-Yang Chou <yphbchou0911@gmail.com>
> ---
> src/ptsematest/ptsematest.c | 6 +++++-
> 1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/src/ptsematest/ptsematest.c b/src/ptsematest/ptsematest.c
> index d211669..787909c 100644
> --- a/src/ptsematest/ptsematest.c
> +++ b/src/ptsematest/ptsematest.c
> @@ -62,6 +62,7 @@ void *semathread(void *param)
> cpu_set_t mask;
> int policy = SCHED_FIFO;
> struct sched_param schedp;
> + int ret;
>
> memset(&schedp, 0, sizeof(schedp));
> schedp.sched_priority = par->priority;
> @@ -112,7 +113,10 @@ void *semathread(void *param)
> int tracing_enabled =
> open(tracing_enabled_file, O_WRONLY);
> if (tracing_enabled >= 0) {
> - write(tracing_enabled, "0", 1);
> + ret = write(tracing_enabled, "0", 1);
> + if (ret < 0)
> + fatal("Could not write to %s: %s\n",
> + tracing_enabled_file, strerror(errno));
> close(tracing_enabled);
> } else
> fatal("Could not access %s\n",
> --
> 2.48.1
>
>
>
Signed-off-by: John Kacur <jkacur@redhat.com>
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH 4/8] rt-migrate-test.c: Suppress warning
2025-07-12 13:42 ` [PATCH 4/8] rt-migrate-test.c: " Cheng-Yang Chou
@ 2025-07-25 18:10 ` John Kacur
0 siblings, 0 replies; 15+ messages in thread
From: John Kacur @ 2025-07-25 18:10 UTC (permalink / raw)
To: Cheng-Yang Chou; +Cc: williams, linux-rt-users, jserv
On Sat, 12 Jul 2025, Cheng-Yang Chou wrote:
> Signed-off-by: Cheng-Yang Chou <yphbchou0911@gmail.com>
> ---
> src/rt-migrate-test/rt-migrate-test.c | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/src/rt-migrate-test/rt-migrate-test.c b/src/rt-migrate-test/rt-migrate-test.c
> index 8afe083..d7c0bf3 100644
> --- a/src/rt-migrate-test/rt-migrate-test.c
> +++ b/src/rt-migrate-test/rt-migrate-test.c
> @@ -61,6 +61,7 @@ static void ftrace_write(const char *fmt, ...)
> {
> va_list ap;
> int n;
> + int ret;
>
> if (mark_fd < 0)
> return;
> @@ -69,7 +70,9 @@ static void ftrace_write(const char *fmt, ...)
> n = vsnprintf(buff, BUFSIZ, fmt, ap);
> va_end(ap);
>
> - write(mark_fd, buff, n);
> + ret = write(mark_fd, buff, n);
> + if (ret < 0)
> + perror("ftrace_write failed");
> }
>
> #define nano2sec(nan) (nan / 1000000000ULL)
> --
> 2.48.1
>
>
>
Signed-off-by: John Kacur <jkacur@redhat.com>
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH 0/8] Fix -Wunused-result warnings by checking return values
2025-07-12 13:42 [PATCH 0/8] Fix -Wunused-result warnings by checking return values Cheng-Yang Chou
` (7 preceding siblings ...)
2025-07-12 13:42 ` [PATCH 8/8] svsematest.c: " Cheng-Yang Chou
@ 2025-07-25 18:16 ` John Kacur
2025-07-25 18:20 ` Cheng-Yang Chou
8 siblings, 1 reply; 15+ messages in thread
From: John Kacur @ 2025-07-25 18:16 UTC (permalink / raw)
To: Cheng-Yang Chou; +Cc: williams, linux-rt-users, jserv
On Sat, 12 Jul 2025, Cheng-Yang Chou wrote:
> This patch series adds proper error checking to functions such as write(),
> ftruncate(), and system(), whose return values were previously ignored.
>
> These warnings were treated as errors under -Werror due to the
> __attribute__((warn_unused_result)) annotation. Instead of suppressing
> them with compiler flags, this series addresses each call site directly
> to improve code robustness and clarity.
>
> A full list of compiler warnings fixed in this series is available at:
> https://gist.github.com/EricccTaiwan/a78d6f1950d3cba27be757e405b6626a
>
> Tested on Ubuntu 25.04 (GCC 14.2.0, glibc 2.41).
>
> Thanks.
>
> -chengyang
>
> ---
>
> Cheng-Yang Chou (8):
> rt-utils.c: Suppress warning
> pmqtest.c: Suppress warning
> ptsematest.c: Suppress warning
> rt-migrate-test.c: Suppress warning
> cyclicdeadline.c: Suppress warning
> deadline_test.c: Suppress warning
> sigwaittest.c: Suppress warning
> svsematest.c: Suppress warning
>
> src/lib/rt-utils.c | 9 +++++--
> src/pmqtest/pmqtest.c | 6 ++++-
> src/ptsematest/ptsematest.c | 6 ++++-
> src/rt-migrate-test/rt-migrate-test.c | 5 +++-
> src/sched_deadline/cyclicdeadline.c | 32 +++++++++++++++++++----
> src/sched_deadline/deadline_test.c | 37 +++++++++++++++++++++++----
> src/sigwaittest/sigwaittest.c | 13 ++++++++--
> src/svsematest/svsematest.c | 13 ++++++++--
> 8 files changed, 102 insertions(+), 19 deletions(-)
>
> --
> 2.48.1
>
>
>
The code is generally okay, but I noticed after I signed off on a few,
that none of your commits have commit messages.
Please run checkpatch from the kernel on your patches and fix the
appropriate warnings and resend.
John Kacur
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH 0/8] Fix -Wunused-result warnings by checking return values
2025-07-25 18:16 ` [PATCH 0/8] Fix -Wunused-result warnings by checking return values John Kacur
@ 2025-07-25 18:20 ` Cheng-Yang Chou
0 siblings, 0 replies; 15+ messages in thread
From: Cheng-Yang Chou @ 2025-07-25 18:20 UTC (permalink / raw)
To: John Kacur; +Cc: williams, linux-rt-users, jserv
On Fri, Jul 25, 2025 at 02:16:55PM -0400, John Kacur wrote:
> The code is generally okay, but I noticed after I signed off on a few,
> that none of your commits have commit messages.
>
> Please run checkpatch from the kernel on your patches and fix the
> appropriate warnings and resend.
>
> John Kacur
>
Got it, I'll send a v2 patch.
Thanks for the heads-up!
Thanks,
-chengyang
^ permalink raw reply [flat|nested] 15+ messages in thread
end of thread, other threads:[~2025-07-25 18:21 UTC | newest]
Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-12 13:42 [PATCH 0/8] Fix -Wunused-result warnings by checking return values Cheng-Yang Chou
2025-07-12 13:42 ` [PATCH 1/8] rt-utils.c: Suppress warning Cheng-Yang Chou
2025-07-25 18:04 ` John Kacur
2025-07-12 13:42 ` [PATCH 2/8] pmqtest.c: " Cheng-Yang Chou
2025-07-25 18:07 ` John Kacur
2025-07-12 13:42 ` [PATCH 3/8] ptsematest.c: " Cheng-Yang Chou
2025-07-25 18:09 ` John Kacur
2025-07-12 13:42 ` [PATCH 4/8] rt-migrate-test.c: " Cheng-Yang Chou
2025-07-25 18:10 ` John Kacur
2025-07-12 13:42 ` [PATCH 5/8] cyclicdeadline.c: " Cheng-Yang Chou
2025-07-12 13:42 ` [PATCH 6/8] deadline_test.c: " Cheng-Yang Chou
2025-07-12 13:42 ` [PATCH 7/8] sigwaittest.c: " Cheng-Yang Chou
2025-07-12 13:42 ` [PATCH 8/8] svsematest.c: " Cheng-Yang Chou
2025-07-25 18:16 ` [PATCH 0/8] Fix -Wunused-result warnings by checking return values John Kacur
2025-07-25 18:20 ` Cheng-Yang Chou
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).