diff mbox series

[ovs-dev,v2,5/8] sflow: Fix check for disabled receive time.

Message ID da77a27215a45ee666035db2eae577e050b20f29.1716896375.git.echaudro@redhat.com
State Changes Requested
Headers show
Series Coverity fixes. | expand

Checks

Context Check Description
ovsrobot/apply-robot warning apply and check: warning
ovsrobot/github-robot-_Build_and_Test success github build: passed
ovsrobot/intel-ovs-compilation success test: success

Commit Message

Eelco Chaudron May 28, 2024, 11:39 a.m. UTC
Changed sFlowRcvrTimeout to a uint32_t to avoid time_t warnings
reported by Coverity. A uint32_t is more than large enough as
this is a (seconds) tick counter and OVS is not even using this.

Fixes: c72e245a0e2c ("Add InMon's sFlow Agent library to the build system.")
Signed-off-by: Eelco Chaudron <echaudro@redhat.com>
--
Note that this checkpatch reports an 'Improper whitespace
around control block' error on this patch + some warnings.
But I did not want to change the code style in this entire file.
---
 lib/sflow_api.h              | 6 +++---
 lib/sflow_receiver.c         | 7 ++++---
 ofproto/ofproto-dpif-sflow.c | 2 +-
 3 files changed, 8 insertions(+), 7 deletions(-)

Comments

Ilya Maximets May 28, 2024, 7:22 p.m. UTC | #1
On 5/28/24 13:39, Eelco Chaudron wrote:
> Changed sFlowRcvrTimeout to a uint32_t to avoid time_t warnings
> reported by Coverity. A uint32_t is more than large enough as
> this is a (seconds) tick counter and OVS is not even using this.
> 
> Fixes: c72e245a0e2c ("Add InMon's sFlow Agent library to the build system.")
> Signed-off-by: Eelco Chaudron <echaudro@redhat.com>
> --
> Note that this checkpatch reports an 'Improper whitespace
> around control block' error on this patch + some warnings.
> But I did not want to change the code style in this entire file.
> ---
>  lib/sflow_api.h              | 6 +++---
>  lib/sflow_receiver.c         | 7 ++++---
>  ofproto/ofproto-dpif-sflow.c | 2 +-
>  3 files changed, 8 insertions(+), 7 deletions(-)

Acked-by: Ilya Maximets <i.maximets@ovn.org>
diff mbox series

Patch

diff --git a/lib/sflow_api.h b/lib/sflow_api.h
index f4bfa5ead..b884a6a7d 100644
--- a/lib/sflow_api.h
+++ b/lib/sflow_api.h
@@ -97,7 +97,7 @@  typedef struct _SFLReceiver {
     struct _SFLReceiver *nxt;
     /* MIB fields */
     char *sFlowRcvrOwner;
-    time_t sFlowRcvrTimeout;
+    u_int32_t sFlowRcvrTimeout;
     u_int32_t sFlowRcvrMaximumDatagramSize;
     SFLAddress sFlowRcvrAddress;
     u_int32_t sFlowRcvrPort;
@@ -251,8 +251,8 @@  SFLSampler *sfl_agent_getSamplerByIfIndex(SFLAgent *agent, u_int32_t ifIndex);
 /* receiver */
 char *      sfl_receiver_get_sFlowRcvrOwner(SFLReceiver *receiver);
 void        sfl_receiver_set_sFlowRcvrOwner(SFLReceiver *receiver, char *sFlowRcvrOwner);
-time_t      sfl_receiver_get_sFlowRcvrTimeout(SFLReceiver *receiver);
-void        sfl_receiver_set_sFlowRcvrTimeout(SFLReceiver *receiver, time_t sFlowRcvrTimeout);
+u_int32_t   sfl_receiver_get_sFlowRcvrTimeout(SFLReceiver *receiver);
+void        sfl_receiver_set_sFlowRcvrTimeout(SFLReceiver *receiver, u_int32_t sFlowRcvrTimeout);
 u_int32_t   sfl_receiver_get_sFlowRcvrMaximumDatagramSize(SFLReceiver *receiver);
 void        sfl_receiver_set_sFlowRcvrMaximumDatagramSize(SFLReceiver *receiver, u_int32_t sFlowRcvrMaximumDatagramSize);
 SFLAddress *sfl_receiver_get_sFlowRcvrAddress(SFLReceiver *receiver);
diff --git a/lib/sflow_receiver.c b/lib/sflow_receiver.c
index 4162518e3..3c5aec897 100644
--- a/lib/sflow_receiver.c
+++ b/lib/sflow_receiver.c
@@ -102,10 +102,10 @@  void sfl_receiver_set_sFlowRcvrOwner(SFLReceiver *receiver, char *sFlowRcvrOwner
 	reset(receiver);
     }
 }
-time_t sfl_receiver_get_sFlowRcvrTimeout(SFLReceiver *receiver) {
+u_int32_t sfl_receiver_get_sFlowRcvrTimeout(SFLReceiver *receiver) {
     return receiver->sFlowRcvrTimeout;
 }
-void sfl_receiver_set_sFlowRcvrTimeout(SFLReceiver *receiver, time_t sFlowRcvrTimeout) {
+void sfl_receiver_set_sFlowRcvrTimeout(SFLReceiver *receiver, u_int32_t sFlowRcvrTimeout) {
     receiver->sFlowRcvrTimeout =sFlowRcvrTimeout;
 }
 u_int32_t sfl_receiver_get_sFlowRcvrMaximumDatagramSize(SFLReceiver *receiver) {
@@ -146,7 +146,8 @@  void sfl_receiver_tick(SFLReceiver *receiver)
     // if there are any samples to send, flush them now
     if(receiver->sampleCollector.numSamples > 0) sendSample(receiver);
     // check the timeout
-    if(receiver->sFlowRcvrTimeout && (u_int32_t)receiver->sFlowRcvrTimeout != 0xFFFFFFFF) {
+    if(receiver->sFlowRcvrTimeout
+       && receiver->sFlowRcvrTimeout != UINT32_MAX) {
 	// count down one tick and reset if we reach 0
 	if(--receiver->sFlowRcvrTimeout == 0) reset(receiver);
     }
diff --git a/ofproto/ofproto-dpif-sflow.c b/ofproto/ofproto-dpif-sflow.c
index 4a68e9b94..80405b68a 100644
--- a/ofproto/ofproto-dpif-sflow.c
+++ b/ofproto/ofproto-dpif-sflow.c
@@ -808,7 +808,7 @@  dpif_sflow_set_options(struct dpif_sflow *ds,
 
     receiver = sfl_agent_addReceiver(ds->sflow_agent);
     sfl_receiver_set_sFlowRcvrOwner(receiver, "Open vSwitch sFlow");
-    sfl_receiver_set_sFlowRcvrTimeout(receiver, 0xffffffff);
+    sfl_receiver_set_sFlowRcvrTimeout(receiver, UINT32_MAX);
 
     /* Set the sampling_rate down in the datapath. */
     ds->probability = MAX(1, UINT32_MAX / ds->options->sampling_rate);