diff mbox

[1/3] rdma: don't use negative index to array

Message ID d046deff608a5a5592688b1a672fae5c8b71afc1.1375415452.git.yamahata@private.email.ne.jp
State New
Headers show

Commit Message

Isaku Yamahata Aug. 2, 2013, 3:56 a.m. UTC
Cc: Michael R. Hines <mrhines@us.ibm.com>
Signed-off-by: Isaku Yamahata <yamahata@private.email.ne.jp>
---
 migration-rdma.c |   27 +++++++++++++++------------
 1 file changed, 15 insertions(+), 12 deletions(-)

Comments

mrhines@linux.vnet.ibm.com Aug. 2, 2013, 1:28 p.m. UTC | #1
On 08/01/2013 11:56 PM, Isaku Yamahata wrote:
> Cc: Michael R. Hines <mrhines@us.ibm.com>
> Signed-off-by: Isaku Yamahata <yamahata@private.email.ne.jp>
> ---
>   migration-rdma.c |   27 +++++++++++++++------------
>   1 file changed, 15 insertions(+), 12 deletions(-)
>
> diff --git a/migration-rdma.c b/migration-rdma.c
> index 4828738..edbae9f 100644
> --- a/migration-rdma.c
> +++ b/migration-rdma.c
> @@ -1931,10 +1931,21 @@ static int qemu_rdma_write_flush(QEMUFile *f, RDMAContext *rdma)
>   static inline int qemu_rdma_buffer_mergable(RDMAContext *rdma,
>                       uint64_t offset, uint64_t len)
>   {
> -    RDMALocalBlock *block =
> -        &(rdma->local_ram_blocks.block[rdma->current_index]);
> -    uint8_t *host_addr = block->local_host_addr + (offset - block->offset);
> -    uint8_t *chunk_end = ram_chunk_end(block, rdma->current_chunk);
> +    RDMALocalBlock *block;
> +    uint8_t *host_addr;
> +    uint8_t *chunk_end;
> +
> +    if (rdma->current_index < 0) {
> +        return 0;
> +    }
> +
> +    if (rdma->current_chunk < 0) {
> +        return 0;
> +    }
> +
> +    block = &(rdma->local_ram_blocks.block[rdma->current_index]);
> +    host_addr = block->local_host_addr + (offset - block->offset);
> +    chunk_end = ram_chunk_end(block, rdma->current_chunk);
>
>       if (rdma->current_length == 0) {
>           return 0;
> @@ -1947,10 +1958,6 @@ static inline int qemu_rdma_buffer_mergable(RDMAContext *rdma,
>           return 0;
>       }
>
> -    if (rdma->current_index < 0) {
> -        return 0;
> -    }
> -
>       if (offset < block->offset) {
>           return 0;
>       }
> @@ -1959,10 +1966,6 @@ static inline int qemu_rdma_buffer_mergable(RDMAContext *rdma,
>           return 0;
>       }
>
> -    if (rdma->current_chunk < 0) {
> -        return 0;
> -    }
> -
>       if ((host_addr + len) > chunk_end) {
>           return 0;
>       }

Reviewed-by: Michael R. Hines <mrhines@us.ibm.com>
diff mbox

Patch

diff --git a/migration-rdma.c b/migration-rdma.c
index 4828738..edbae9f 100644
--- a/migration-rdma.c
+++ b/migration-rdma.c
@@ -1931,10 +1931,21 @@  static int qemu_rdma_write_flush(QEMUFile *f, RDMAContext *rdma)
 static inline int qemu_rdma_buffer_mergable(RDMAContext *rdma,
                     uint64_t offset, uint64_t len)
 {
-    RDMALocalBlock *block =
-        &(rdma->local_ram_blocks.block[rdma->current_index]);
-    uint8_t *host_addr = block->local_host_addr + (offset - block->offset);
-    uint8_t *chunk_end = ram_chunk_end(block, rdma->current_chunk);
+    RDMALocalBlock *block;
+    uint8_t *host_addr;
+    uint8_t *chunk_end;
+
+    if (rdma->current_index < 0) {
+        return 0;
+    }
+
+    if (rdma->current_chunk < 0) {
+        return 0;
+    }
+
+    block = &(rdma->local_ram_blocks.block[rdma->current_index]);
+    host_addr = block->local_host_addr + (offset - block->offset);
+    chunk_end = ram_chunk_end(block, rdma->current_chunk);
 
     if (rdma->current_length == 0) {
         return 0;
@@ -1947,10 +1958,6 @@  static inline int qemu_rdma_buffer_mergable(RDMAContext *rdma,
         return 0;
     }
 
-    if (rdma->current_index < 0) {
-        return 0;
-    }
-
     if (offset < block->offset) {
         return 0;
     }
@@ -1959,10 +1966,6 @@  static inline int qemu_rdma_buffer_mergable(RDMAContext *rdma,
         return 0;
     }
 
-    if (rdma->current_chunk < 0) {
-        return 0;
-    }
-
     if ((host_addr + len) > chunk_end) {
         return 0;
     }