From a67db28fd9cf19c8548d65f428b2a8dc2d048bbd Mon Sep 17 00:00:00 2001 From: Mike Pattrick Date: Mon, 9 Sep 2024 00:54:59 -0400 Subject: [PATCH] dpif-netdev: Remove undefined integer division. 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. Acked-by: Simon Horman Signed-off-by: Mike Pattrick Signed-off-by: Eelco Chaudron --- lib/dpif-netdev.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c index f6d6d01cf..3d262463f 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"); }