public inbox for qemu-devel@nongnu.org
 help / color / mirror / Atom feed
* [PATCH] migration: fix implicit integer division in migration_update_counters
@ 2026-03-16 13:45 Aadeshveer Singh
  2026-03-16 20:45 ` Peter Xu
  0 siblings, 1 reply; 2+ messages in thread
From: Aadeshveer Singh @ 2026-03-16 13:45 UTC (permalink / raw)
  To: qemu-devel; +Cc: peterx, farosas, Aadeshveer Singh

switchover_bw is a uint64_t, so switchover_bw / 1000 results in an
integer division. This value is then assigned to expected_bw_per_ms
which is of type double. This results in losing precision and is type
unsafe. Adding explicit cast ensures floating-point division.

Signed-off-by: Aadeshveer Singh <aadeshveer07@gmail.com>
---
 migration/migration.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/migration/migration.c b/migration/migration.c
index f949708629..7094080285 100644
--- a/migration/migration.c
+++ b/migration/migration.c
@@ -3134,7 +3134,7 @@ static void migration_update_counters(MigrationState *s,
          * If the user specified a switchover bandwidth, let's trust the
          * user so that can be more accurate than what we estimated.
          */
-        expected_bw_per_ms = switchover_bw / 1000;
+        expected_bw_per_ms = (double)switchover_bw / 1000;
     } else {
         /* If the user doesn't specify bandwidth, we use the estimated */
         expected_bw_per_ms = bandwidth;
-- 
2.53.0



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] migration: fix implicit integer division in migration_update_counters
  2026-03-16 13:45 [PATCH] migration: fix implicit integer division in migration_update_counters Aadeshveer Singh
@ 2026-03-16 20:45 ` Peter Xu
  0 siblings, 0 replies; 2+ messages in thread
From: Peter Xu @ 2026-03-16 20:45 UTC (permalink / raw)
  To: Aadeshveer Singh; +Cc: qemu-devel, farosas

On Mon, Mar 16, 2026 at 07:15:09PM +0530, Aadeshveer Singh wrote:
> switchover_bw is a uint64_t, so switchover_bw / 1000 results in an
> integer division. This value is then assigned to expected_bw_per_ms
> which is of type double. This results in losing precision and is type
> unsafe. Adding explicit cast ensures floating-point division.
> 
> Signed-off-by: Aadeshveer Singh <aadeshveer07@gmail.com>

Reviewed-by: Peter Xu <peterx@redhat.com>

Thanks,

> ---
>  migration/migration.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/migration/migration.c b/migration/migration.c
> index f949708629..7094080285 100644
> --- a/migration/migration.c
> +++ b/migration/migration.c
> @@ -3134,7 +3134,7 @@ static void migration_update_counters(MigrationState *s,
>           * If the user specified a switchover bandwidth, let's trust the
>           * user so that can be more accurate than what we estimated.
>           */
> -        expected_bw_per_ms = switchover_bw / 1000;
> +        expected_bw_per_ms = (double)switchover_bw / 1000;
>      } else {
>          /* If the user doesn't specify bandwidth, we use the estimated */
>          expected_bw_per_ms = bandwidth;
> -- 
> 2.53.0
> 

-- 
Peter Xu



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-03-16 20:46 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-16 13:45 [PATCH] migration: fix implicit integer division in migration_update_counters Aadeshveer Singh
2026-03-16 20:45 ` Peter Xu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox