With NDEBUG, all assertions are just ignoring the result of the
condition and this is causing build warnings when the condition
is a result of a function marked with OVS_WARN_UNUSED_RESULT:
lib/dp-packet.c: In function 'dp_packet_ol_send_prepare':
lib/dp-packet.c:580:28:
error: ignoring return value of 'dp_packet_l4_proto_sctp' declared
with attribute 'warn_unused_result' [-Werror=unused-result]
580 | ovs_assert(dp_packet_l4_proto_sctp(p));
./include/openvswitch/util.h:58:40:
note: in definition of macro 'ovs_assert'
58 | #define ovs_assert(CONDITION) ((void) (CONDITION))
| ^~~~~~~~~
lib/dp-packet.c:621:24:
error: ignoring return value of 'dp_packet_inner_l4_proto_sctp'
declared with attribute 'warn_unused_result' [-Werror=unused-result]
621 | ovs_assert(dp_packet_inner_l4_proto_sctp(p));
./include/openvswitch/util.h:58:40:
note: in definition of macro 'ovs_assert'
58 | #define ovs_assert(CONDITION) ((void) (CONDITION))
| ^~~~~~~~~
lib/dp-packet.c:634:20:
error: ignoring return value of 'dp_packet_l4_proto_udp' declared
with attribute 'warn_unused_result' [-Werror=unused-result]
634 | ovs_assert(dp_packet_l4_proto_udp(p));
./include/openvswitch/util.h:58:40:
note: in definition of macro 'ovs_assert'
58 | #define ovs_assert(CONDITION) ((void) (CONDITION))
| ^~~~~~~~~
cc1: all warnings being treated as errors
Let's export the ignore() function as ovs_ignore() and use it for
the ovs_assert in case of NDEBUG build. This will silence the
warnings.
Most files already import "util.h", so there is no need to add
the public "openvswitch/util.h" as well.
Fixes: 3daf04a4c56d ("dp-packet: Rework IP checksum offloads.")
Signed-off-by: Ilya Maximets <[email protected]>
---
include/openvswitch/util.h | 6 +++++-
lib/async-append-aio.c | 4 ++--
lib/daemon-unix.c | 2 +-
lib/fatal-signal.c | 8 ++++----
lib/latch-unix.c | 3 ++-
lib/pcap-file.c | 6 +++---
lib/process.c | 2 +-
lib/util.c | 4 ++--
lib/util.h | 2 --
lib/vlog.c | 4 ++--
ovsdb/log.c | 2 +-
tests/oss-fuzz/flow_extract_target.c | 7 ++++---
tests/oss-fuzz/miniflow_target.c | 2 +-
tests/test-ccmap.c | 4 ++--
tests/test-cmap.c | 16 ++++++++--------
tests/test-id-fpool.c | 18 +++++++++---------
16 files changed, 47 insertions(+), 43 deletions(-)
diff --git a/include/openvswitch/util.h b/include/openvswitch/util.h
index 8e6c46a85..eabfc5870 100644
--- a/include/openvswitch/util.h
+++ b/include/openvswitch/util.h
@@ -44,6 +44,10 @@ const char *ovs_get_program_version(void);
: (X) <= UINT_MAX / (Y) ? (unsigned int) (X) * (unsigned int) (Y) \
: UINT_MAX)
+/* A special function that is intended to explicitly ignore results of
+ * functions marked with __attribute__((warn_unused_result)), if necessary. */
+void ovs_ignore(bool);
+
/* Like the standard assert macro, except:
*
* - Writes the failure message to the log.
@@ -55,7 +59,7 @@ const char *ovs_get_program_version(void);
? (void) 0 \
: ovs_assert_failure(OVS_SOURCE_LOCATOR, __func__, #CONDITION))
#else
-#define ovs_assert(CONDITION) ((void) (CONDITION))
+#define ovs_assert ovs_ignore
#endif
OVS_NO_RETURN void ovs_assert_failure(const char *, const char *, const char
*);
diff --git a/lib/async-append-aio.c b/lib/async-append-aio.c
index 23430a455..55d49e51b 100644
--- a/lib/async-append-aio.c
+++ b/lib/async-append-aio.c
@@ -105,7 +105,7 @@ async_append_wait(struct async_append *ap)
}
aio_suspend(&p, 1, NULL);
} else {
- ignore(aio_return(aiocb));
+ ovs_ignore(aio_return(aiocb));
ap->aiocb_tail++;
byteq_advance_tail(&ap->byteq, aiocb->aio_nbytes);
n++;
@@ -143,7 +143,7 @@ async_append_write(struct async_append *ap, const void
*data_, size_t size)
aiocb->aio_sigevent.sigev_notify = SIGEV_NONE;
if (aio_write(aiocb) == -1) {
async_append_flush(ap);
- ignore(write(ap->fd, data, size));
+ ovs_ignore(write(ap->fd, data, size));
return;
}
diff --git a/lib/daemon-unix.c b/lib/daemon-unix.c
index 6d02aceeb..86adc9c19 100644
--- a/lib/daemon-unix.c
+++ b/lib/daemon-unix.c
@@ -531,7 +531,7 @@ daemonize_post_detach(void)
{
if (detach) {
if (chdir_) {
- ignore(chdir("/"));
+ ovs_ignore(chdir("/"));
}
close_standard_fds();
}
diff --git a/lib/fatal-signal.c b/lib/fatal-signal.c
index 953150074..ff9c021db 100644
--- a/lib/fatal-signal.c
+++ b/lib/fatal-signal.c
@@ -244,8 +244,8 @@ send_backtrace_to_monitor(void)
}
if (monitor) {
- ignore(write(daemonize_fd, unw_bt,
- dep * sizeof(struct unw_backtrace)));
+ ovs_ignore(write(daemonize_fd, unw_bt,
+ dep * sizeof(struct unw_backtrace)));
} else {
/* Since there is no monitor daemon running, write backtrace
* in current process.
@@ -295,7 +295,7 @@ send_backtrace_to_monitor(void)
backtrace_capture(&bt);
if (monitor && daemonize_fd > -1) {
- ignore(write(daemonize_fd, &bt, sizeof bt));
+ ovs_ignore(write(daemonize_fd, &bt, sizeof bt));
} else {
int log_fd = vlog_get_log_file_fd_unsafe();
@@ -332,7 +332,7 @@ fatal_signal_handler(int sig_nr)
send_backtrace_to_monitor();
raise(sig_nr);
}
- ignore(write(signal_fds[1], "", 1));
+ ovs_ignore(write(signal_fds[1], "", 1));
#else
SetEvent(wevent);
#endif
diff --git a/lib/latch-unix.c b/lib/latch-unix.c
index c62bb024b..5f1c1cb88 100644
--- a/lib/latch-unix.c
+++ b/lib/latch-unix.c
@@ -21,6 +21,7 @@
#include <poll.h>
#include <unistd.h>
#include "openvswitch/poll-loop.h"
+#include "openvswitch/util.h"
#include "socket-util.h"
/* Initializes 'latch' as initially unset. */
@@ -63,7 +64,7 @@ latch_poll(struct latch *latch)
void
latch_set(struct latch *latch)
{
- ignore(write(latch->fds[1], "", 1));
+ ovs_ignore(write(latch->fds[1], "", 1));
}
/* Returns true if 'latch' is set, false otherwise. Does not reset 'latch'
diff --git a/lib/pcap-file.c b/lib/pcap-file.c
index 0c2fed776..8e4d6b3dd 100644
--- a/lib/pcap-file.c
+++ b/lib/pcap-file.c
@@ -174,7 +174,7 @@ ovs_pcap_write_header(struct pcap_file *p_file)
ph.sigfigs = 0;
ph.snaplen = 1518;
ph.network = 1; /* Ethernet */
- ignore(fwrite(&ph, sizeof ph, 1, p_file->file));
+ ovs_ignore(fwrite(&ph, sizeof ph, 1, p_file->file));
fflush(p_file->file);
}
@@ -292,8 +292,8 @@ ovs_pcap_write(struct pcap_file *p_file, struct dp_packet
*buf)
prh.ts_subsec = tv.tv_usec;
prh.incl_len = dp_packet_size(buf);
prh.orig_len = dp_packet_size(buf);
- ignore(fwrite(&prh, sizeof prh, 1, p_file->file));
- ignore(fwrite(data_dp, dp_packet_size(buf), 1, p_file->file));
+ ovs_ignore(fwrite(&prh, sizeof prh, 1, p_file->file));
+ ovs_ignore(fwrite(data_dp, dp_packet_size(buf), 1, p_file->file));
fflush(p_file->file);
}
diff --git a/lib/process.c b/lib/process.c
index 78de4b8df..b5ec02823 100644
--- a/lib/process.c
+++ b/lib/process.c
@@ -627,5 +627,5 @@ process_search_path(const char *name)
static void
sigchld_handler(int signr OVS_UNUSED)
{
- ignore(write(fds[1], "", 1));
+ ovs_ignore(write(fds[1], "", 1));
}
diff --git a/lib/util.c b/lib/util.c
index 890c606b5..a6da1e481 100644
--- a/lib/util.c
+++ b/lib/util.c
@@ -734,7 +734,7 @@ ctl_timeout_setup(unsigned int secs)
char *env = getenv("OVS_CTL_TIMEOUT");
if (env && env[0]) {
- ignore(str_to_uint(env, 10, &secs));
+ ovs_ignore(str_to_uint(env, 10, &secs));
}
}
if (secs) {
@@ -1317,7 +1317,7 @@ follow_symlinks(const char *filename)
* __attribute__((warn_unused_result)) and you genuinely want to ignore
* its return value. (Note that every scalar type can be implicitly
* converted to bool.) */
-void ignore(bool x OVS_UNUSED) { }
+void ovs_ignore(bool x OVS_UNUSED) { }
/* Returns an appropriate delimiter for inserting just before the 0-based item
* 'index' in a list that has 'total' items in it. */
diff --git a/lib/util.h b/lib/util.h
index c1fd120bc..ef993626a 100644
--- a/lib/util.h
+++ b/lib/util.h
@@ -270,8 +270,6 @@ char *abs_file_name(const char *dir, const char *file_name);
bool is_file_name_absolute(const char *);
char *follow_symlinks(const char *filename);
-
-void ignore(bool x OVS_UNUSED);
/* Bitwise tests. */
diff --git a/lib/vlog.c b/lib/vlog.c
index 806ba1a41..e6cea7e54 100644
--- a/lib/vlog.c
+++ b/lib/vlog.c
@@ -663,7 +663,7 @@ vlog_direct_write_to_log_file_unsafe(const char *s)
OVS_NO_THREAD_SAFETY_ANALYSIS
{
if (log_fd >= 0) {
- ignore(write(log_fd, s, strlen(s)));
+ ovs_ignore(write(log_fd, s, strlen(s)));
}
}
@@ -1228,7 +1228,7 @@ vlog_valist(const struct vlog_module *module, enum
vlog_level level,
async_append_flush(log_writer);
}
} else {
- ignore(write(log_fd, s.string, s.length));
+ ovs_ignore(write(log_fd, s.string, s.length));
}
}
ovs_mutex_unlock(&log_file_mutex);
diff --git a/ovsdb/log.c b/ovsdb/log.c
index 0c3577119..86d6bdc24 100644
--- a/ovsdb/log.c
+++ b/ovsdb/log.c
@@ -651,7 +651,7 @@ ovsdb_log_write(struct ovsdb_log *file, const struct json
*json)
/* Remove any partially written data, ignoring errors since there is
* nothing further we can do. */
- ignore(ftruncate(fileno(file->stream), file->offset));
+ ovs_ignore(ftruncate(fileno(file->stream), file->offset));
file->error = ovsdb_io_error(error, "%s: write failed",
file->display_name);
diff --git a/tests/oss-fuzz/flow_extract_target.c
b/tests/oss-fuzz/flow_extract_target.c
index 84a6c317d..72025e6ce 100644
--- a/tests/oss-fuzz/flow_extract_target.c
+++ b/tests/oss-fuzz/flow_extract_target.c
@@ -7,6 +7,7 @@
#include "openvswitch/ofp-match.h"
#include "openvswitch/ofp-print.h"
#include "openvswitch/match.h"
+#include "openvswitch/util.h"
#include "classifier-private.h"
static void
@@ -24,7 +25,7 @@ test_flow_hash(const struct flow *flow)
hash = flow_hash_fields(flow, NX_HASH_FIELDS_NW_SRC, hash);
hash = flow_hash_fields(flow, NX_HASH_FIELDS_NW_DST, hash);
hash = flow_hash_fields(flow, NX_HASH_FIELDS_SYMMETRIC_L3, hash);
- ignore(hash);
+ ovs_ignore(hash);
}
static void
@@ -57,12 +58,12 @@ LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
/* Parse TCP flags. */
if (dp_packet_size(&packet) >= ETH_HEADER_LEN) {
uint16_t tcp_flags = parse_tcp_flags(&packet, NULL, NULL, NULL);
- ignore(tcp_flags);
+ ovs_ignore(tcp_flags);
}
/* Count headers. */
int count = flow_count_vlan_headers(&flow);
- ignore(count);
+ ovs_ignore(count);
/* Extract metadata. */
struct match flow_metadata;
diff --git a/tests/oss-fuzz/miniflow_target.c b/tests/oss-fuzz/miniflow_target.c
index 50b8b0e64..2f41ff980 100644
--- a/tests/oss-fuzz/miniflow_target.c
+++ b/tests/oss-fuzz/miniflow_target.c
@@ -103,7 +103,7 @@ test_miniflow(struct flow *flow)
/* Obtain miniflow hash. */
uint32_t hash = miniflow_hash_5tuple(miniflow, 0);
- ignore(hash);
+ ovs_ignore(hash);
/* Check that the flow equals its miniflow. */
for (i = 0; i < FLOW_MAX_VLAN_HEADERS; i++) {
diff --git a/tests/test-ccmap.c b/tests/test-ccmap.c
index dcc4a6fd6..5fcb9df38 100644
--- a/tests/test-ccmap.c
+++ b/tests/test-ccmap.c
@@ -212,12 +212,12 @@ search_ccmap(void *aux_)
}
ovs_mutex_unlock(&aux->mutex);
} else {
- ignore(ccmap_find(aux->ccmap, hash));
+ ovs_ignore(ccmap_find(aux->ccmap, hash));
}
}
} else {
for (i = 0; i < n_elems; i++) {
- ignore(ccmap_find(aux->ccmap, hash_int(i, 0)));
+ ovs_ignore(ccmap_find(aux->ccmap, hash_int(i, 0)));
}
}
return NULL;
diff --git a/tests/test-cmap.c b/tests/test-cmap.c
index 588a5dea6..3fe5ef964 100644
--- a/tests/test-cmap.c
+++ b/tests/test-cmap.c
@@ -342,12 +342,12 @@ search_cmap(void *aux_)
}
ovs_mutex_unlock(&aux->mutex);
} else {
- ignore(find(aux->cmap, i));
+ ovs_ignore(find(aux->cmap, i));
}
}
} else {
for (i = 0; i < n_elems; i++) {
- ignore(find(aux->cmap, i));
+ ovs_ignore(find(aux->cmap, i));
}
}
return NULL;
@@ -378,7 +378,7 @@ benchmark_cmap(void)
/* Iteration. */
xgettimeofday(&start);
CMAP_FOR_EACH (e, node, &cmap) {
- ignore(e);
+ ovs_ignore(e);
}
printf("cmap iterate: %5d ms\n", elapsed(&start));
@@ -438,7 +438,7 @@ find_batch(const struct cmap *cmap, const int value)
CMAP_NODE_FOR_EACH (e, node, nodes[i]) {
if (OVS_LIKELY(e->value == value + i)) {
- ignore(e); /* Found result. */
+ ovs_ignore(e); /* Found result. */
break;
}
}
@@ -498,7 +498,7 @@ benchmark_cmap_batched(void)
/* Iteration. */
xgettimeofday(&start);
CMAP_FOR_EACH (e, node, &cmap) {
- ignore(e);
+ ovs_ignore(e);
}
printf("cmap iterate: %5d ms\n", elapsed(&start));
@@ -570,13 +570,13 @@ search_hmap(void *aux_)
fat_rwlock_unlock(&aux->fatlock);
} else {
fat_rwlock_rdlock(&aux->fatlock);
- ignore(hfind(aux->hmap, i));
+ ovs_ignore(hfind(aux->hmap, i));
fat_rwlock_unlock(&aux->fatlock);
}
}
} else {
for (i = 0; i < n_elems; i++) {
- ignore(hfind(aux->hmap, i));
+ ovs_ignore(hfind(aux->hmap, i));
}
}
return NULL;
@@ -606,7 +606,7 @@ benchmark_hmap(void)
xgettimeofday(&start);
HMAP_FOR_EACH (e, node, &hmap) {
- ignore(e);
+ ovs_ignore(e);
}
printf("hmap iterate: %5d ms\n", elapsed(&start));
diff --git a/tests/test-id-fpool.c b/tests/test-id-fpool.c
index 7bdb8154d..0f28796ed 100644
--- a/tests/test-id-fpool.c
+++ b/tests/test-id-fpool.c
@@ -276,7 +276,7 @@ id_fpool_thread(void *aux_)
start = running_time_ms;
for (i = 0; i < n_ids_per_thread; i++) {
- ignore(id_fpool_new_id(aux->pool, tid, &th_ids[i]));
+ ovs_ignore(id_fpool_new_id(aux->pool, tid, &th_ids[i]));
}
thread_working_ms[tid] = elapsed(&start);
@@ -298,9 +298,9 @@ id_fpool_thread(void *aux_)
start = running_time_ms;
for (i = 0; i < n_ids_per_thread; i++) {
- ignore(id_fpool_new_id(aux->pool, tid, &th_ids[i]));
+ ovs_ignore(id_fpool_new_id(aux->pool, tid, &th_ids[i]));
id_fpool_free_id(aux->pool, tid, th_ids[i]);
- ignore(id_fpool_new_id(aux->pool, tid, &th_ids[i]));
+ ovs_ignore(id_fpool_new_id(aux->pool, tid, &th_ids[i]));
}
thread_working_ms[tid] = elapsed(&start);
@@ -320,10 +320,10 @@ id_fpool_thread(void *aux_)
if (elapsed(&start) >= TIMEOUT_MS) {
break;
}
- ignore(id_fpool_new_id(aux->pool, tid, &th_ids[i]));
+ ovs_ignore(id_fpool_new_id(aux->pool, tid, &th_ids[i]));
swap_u32(&th_ids[i], &th_ids[random_range(i + 1)]);
id_fpool_free_id(aux->pool, tid, th_ids[i]);
- ignore(id_fpool_new_id(aux->pool, tid, &th_ids[i]));
+ ovs_ignore(id_fpool_new_id(aux->pool, tid, &th_ids[i]));
}
thread_working_ms[tid] = elapsed(&start);
@@ -431,9 +431,9 @@ id_pool_thread(void *aux_)
start = running_time_ms;
for (i = 0; i < n_ids_per_thread; i++) {
ovs_mutex_lock(aux->lock);
- ignore(id_pool_alloc_id(aux->pool, &th_ids[i]));
+ ovs_ignore(id_pool_alloc_id(aux->pool, &th_ids[i]));
id_pool_free_id(aux->pool, th_ids[i]);
- ignore(id_pool_alloc_id(aux->pool, &th_ids[i]));
+ ovs_ignore(id_pool_alloc_id(aux->pool, &th_ids[i]));
ovs_mutex_unlock(aux->lock);
}
thread_working_ms[tid] = elapsed(&start);
@@ -457,10 +457,10 @@ id_pool_thread(void *aux_)
break;
}
ovs_mutex_lock(aux->lock);
- ignore(id_pool_alloc_id(aux->pool, &th_ids[i]));
+ ovs_ignore(id_pool_alloc_id(aux->pool, &th_ids[i]));
swap_u32(&th_ids[i], &th_ids[random_range(i + 1)]);
id_pool_free_id(aux->pool, th_ids[i]);
- ignore(id_pool_alloc_id(aux->pool, &th_ids[i]));
+ ovs_ignore(id_pool_alloc_id(aux->pool, &th_ids[i]));
ovs_mutex_unlock(aux->lock);
}
thread_working_ms[tid] = elapsed(&start);
--
2.51.0
_______________________________________________
dev mailing list
[email protected]
https://mail.openvswitch.org/mailman/listinfo/ovs-dev