diff mbox series

[ovs-dev,v3,2/8] dpif-netdev: Remove undefined integer division.

Message ID 20240909045505.236657-3-mkp@redhat.com
State Accepted, archived
Commit a67db28fd9cf19c8548d65f428b2a8dc2d048bbd
Delegated to: Eelco Chaudron
Headers show
Series Address clang analyze warnings. | expand

Checks

Context Check Description
ovsrobot/apply-robot success apply and check: success
ovsrobot/github-robot-_Build_and_Test success github build: passed

Commit Message

Mike Pattrick Sept. 9, 2024, 4:54 a.m. UTC
Clang analyzer will complain about floating point operations conducted
with integer types as rounding is undefined. In pmd_info_show_rxq() a
percentage was calculated inside uint64 integers instead of a floating
pointer variable for a user visible message. This issue can be resolved
simply by casting to double while dividing.

Signed-off-by: Mike Pattrick <mkp@redhat.com>
---
 lib/dpif-netdev.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

Comments

Eelco Chaudron Sept. 10, 2024, 9:56 a.m. UTC | #1
On 9 Sep 2024, at 6:54, Mike Pattrick wrote:

> Clang analyzer will complain about floating point operations conducted
> with integer types as rounding is undefined. In pmd_info_show_rxq() a
> percentage was calculated inside uint64 integers instead of a floating
> pointer variable for a user visible message. This issue can be resolved
> simply by casting to double while dividing.
>
> Signed-off-by: Mike Pattrick <mkp@redhat.com>

Thanks for sending out the v3, the changes look good to me.

Cheers,

Eelco

Acked-by: Eelco Chaudron <echaudro@redhat.com>
Simon Horman Sept. 11, 2024, 9:25 a.m. UTC | #2
On Mon, Sep 09, 2024 at 12:54:59AM -0400, Mike Pattrick wrote:
> Clang analyzer will complain about floating point operations conducted
> with integer types as rounding is undefined. In pmd_info_show_rxq() a
> percentage was calculated inside uint64 integers instead of a floating
> pointer variable for a user visible message. This issue can be resolved
> simply by casting to double while dividing.
> 
> Signed-off-by: Mike Pattrick <mkp@redhat.com>

Acked-by: Simon Horman <horms@ovn.org>
diff mbox series

Patch

diff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c
index f0594e5f5..d12e716b6 100644
--- a/lib/dpif-netdev.c
+++ b/lib/dpif-netdev.c
@@ -942,9 +942,9 @@  pmd_info_show_rxq(struct ds *reply, struct dp_netdev_pmd_thread *pmd,
                                         ? "(enabled) " : "(disabled)");
             ds_put_format(reply, "  pmd usage: ");
             if (total_pmd_cycles) {
-                ds_put_format(reply, "%2"PRIu64"",
-                              rxq_proc_cycles * 100 / total_pmd_cycles);
-                ds_put_cstr(reply, " %");
+                ds_put_format(reply, "%2.0f %%",
+                              (double) (rxq_proc_cycles * 100) /
+                              total_pmd_cycles);
             } else {
                 ds_put_format(reply, "%s", "NOT AVAIL");
             }
@@ -959,8 +959,10 @@  pmd_info_show_rxq(struct ds *reply, struct dp_netdev_pmd_thread *pmd,
                 if (total_rxq_proc_cycles < busy_pmd_cycles) {
                     overhead_cycles = busy_pmd_cycles - total_rxq_proc_cycles;
                 }
-                ds_put_format(reply, "%2"PRIu64" %%",
-                              overhead_cycles * 100 / total_pmd_cycles);
+
+                ds_put_format(reply, "%2.0f %%",
+                              (double) (overhead_cycles * 100) /
+                              total_pmd_cycles);
             } else {
                 ds_put_cstr(reply, "NOT AVAIL");
             }