diff mbox

Fix integer overflow in block migration bandwidth calculation

Message ID OFBBFDA642.7A3B3819-ONC2257864.004A9649-C2257864.004C30B0@il.ibm.com
State New
Headers show

Commit Message

Avishay Traeger1 March 31, 2011, 1:52 p.m. UTC
block_mig_state.reads is an int, and multiplying by BLOCK_SIZE yielded a
negative number, resulting in a negative bandwidth (running on a 32-bit
machine).  Cast to avoid.

Signed-off-by: Avishay Traeger <avishay@il.ibm.com>
---
 block-migration.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)


 static int bmds_aio_inflight(BlkMigDevState *bmds, int64_t sector)
--
1.7.0.4

Comments

Kevin Wolf April 5, 2011, 12:54 p.m. UTC | #1
Am 31.03.2011 15:52, schrieb Avishay Traeger:
> 
> block_mig_state.reads is an int, and multiplying by BLOCK_SIZE yielded a
> negative number, resulting in a negative bandwidth (running on a 32-bit
> machine).  Cast to avoid.
> 
> Signed-off-by: Avishay Traeger <avishay@il.ibm.com>

This patch is corrupted by line wraps.

> ---
>  block-migration.c |    2 +-
>  1 files changed, 1 insertions(+), 1 deletions(-)
> 
> diff --git a/block-migration.c b/block-migration.c
> index 8218bac..ffc92ee 100644
> --- a/block-migration.c
> +++ b/block-migration.c
> @@ -140,7 +140,7 @@ static inline void add_avg_read_time(int64_t time)
>  static inline long double compute_read_bwidth(void)
>  {
>      assert(block_mig_state.total_time != 0);
> -    return  (block_mig_state.reads * BLOCK_SIZE)/
> block_mig_state.total_time;
> +    return  ((long long)block_mig_state.reads * BLOCK_SIZE)/
> block_mig_state.total_time;

This line exceeds 80 characters. While you're at it, you could add a
space before the /

Kevin
diff mbox

Patch

diff --git a/block-migration.c b/block-migration.c
index 8218bac..ffc92ee 100644
--- a/block-migration.c
+++ b/block-migration.c
@@ -140,7 +140,7 @@  static inline void add_avg_read_time(int64_t time)
 static inline long double compute_read_bwidth(void)
 {
     assert(block_mig_state.total_time != 0);
-    return  (block_mig_state.reads * BLOCK_SIZE)/
block_mig_state.total_time;
+    return  ((long long)block_mig_state.reads * BLOCK_SIZE)/
block_mig_state.total_time;
 }