diff mbox series

[12/13] dump: make range overlap check more readable

Message ID 20240722040742.11513-13-yaoxt.fnst@fujitsu.com (mailing list archive)
State New, archived
Headers show
Series make range overlap check more readable | expand

Commit Message

Xingtao Yao (Fujitsu) July 22, 2024, 4:07 a.m. UTC
use ranges_overlap() instead of open-coding the overlap check to improve
the readability of the code.

Signed-off-by: Yao Xingtao <yaoxt.fnst@fujitsu.com>
---
 dump/dump.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

Comments

Marc-André Lureau July 22, 2024, 7:01 a.m. UTC | #1
On Mon, Jul 22, 2024 at 8:10 AM Yao Xingtao <yaoxt.fnst@fujitsu.com> wrote:

> use ranges_overlap() instead of open-coding the overlap check to improve
> the readability of the code.
>
> Signed-off-by: Yao Xingtao <yaoxt.fnst@fujitsu.com>
>

Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>


> ---
>  dump/dump.c | 12 ++++++++----
>  1 file changed, 8 insertions(+), 4 deletions(-)
>
> diff --git a/dump/dump.c b/dump/dump.c
> index 84064d890d2c..45e84428aea5 100644
> --- a/dump/dump.c
> +++ b/dump/dump.c
> @@ -30,6 +30,7 @@
>  #include "migration/blocker.h"
>  #include "hw/core/cpu.h"
>  #include "win_dump.h"
> +#include "qemu/range.h"
>
>  #include <zlib.h>
>  #ifdef CONFIG_LZO
> @@ -574,8 +575,10 @@ static void get_offset_range(hwaddr phys_addr,
>
>      QTAILQ_FOREACH(block, &s->guest_phys_blocks.head, next) {
>          if (dump_has_filter(s)) {
> -            if (block->target_start >= s->filter_area_begin +
> s->filter_area_length ||
> -                block->target_end <= s->filter_area_begin) {
> +            if (!ranges_overlap(block->target_start,
> +                                block->target_end - block->target_start,
> +                                s->filter_area_begin,
> +                                s->filter_area_length)) {
>                  /* This block is out of the range */
>                  continue;
>              }
> @@ -734,8 +737,9 @@ int64_t dump_filtered_memblock_start(GuestPhysBlock
> *block,
>  {
>      if (filter_area_length) {
>          /* return -1 if the block is not within filter area */
> -        if (block->target_start >= filter_area_start + filter_area_length
> ||
> -            block->target_end <= filter_area_start) {
> +        if (!ranges_overlap(block->target_start,
> +                            block->target_end - block->target_start,
> +                            filter_area_start, filter_area_length)) {
>              return -1;
>          }
>
> --
> 2.41.0
>
>
diff mbox series

Patch

diff --git a/dump/dump.c b/dump/dump.c
index 84064d890d2c..45e84428aea5 100644
--- a/dump/dump.c
+++ b/dump/dump.c
@@ -30,6 +30,7 @@ 
 #include "migration/blocker.h"
 #include "hw/core/cpu.h"
 #include "win_dump.h"
+#include "qemu/range.h"
 
 #include <zlib.h>
 #ifdef CONFIG_LZO
@@ -574,8 +575,10 @@  static void get_offset_range(hwaddr phys_addr,
 
     QTAILQ_FOREACH(block, &s->guest_phys_blocks.head, next) {
         if (dump_has_filter(s)) {
-            if (block->target_start >= s->filter_area_begin + s->filter_area_length ||
-                block->target_end <= s->filter_area_begin) {
+            if (!ranges_overlap(block->target_start,
+                                block->target_end - block->target_start,
+                                s->filter_area_begin,
+                                s->filter_area_length)) {
                 /* This block is out of the range */
                 continue;
             }
@@ -734,8 +737,9 @@  int64_t dump_filtered_memblock_start(GuestPhysBlock *block,
 {
     if (filter_area_length) {
         /* return -1 if the block is not within filter area */
-        if (block->target_start >= filter_area_start + filter_area_length ||
-            block->target_end <= filter_area_start) {
+        if (!ranges_overlap(block->target_start,
+                            block->target_end - block->target_start,
+                            filter_area_start, filter_area_length)) {
             return -1;
         }