bf143f
From bb55fde4d8ca587e2ef52ce58a0c22e4d66a08dc Mon Sep 17 00:00:00 2001
bf143f
From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= <marcandre.lureau@redhat.com>
bf143f
Date: Thu, 25 Aug 2022 12:40:12 +0400
bf143f
Subject: [PATCH 30/42] dump: simplify a bit kdump get_next_page()
bf143f
MIME-Version: 1.0
bf143f
Content-Type: text/plain; charset=UTF-8
bf143f
Content-Transfer-Encoding: 8bit
bf143f
bf143f
RH-Author: Cédric Le Goater <clg@redhat.com>
bf143f
RH-MergeRequest: 226: s390: Enhanced Interpretation for PCI Functions and Secure Execution guest dump
bf143f
RH-Bugzilla: 1664378 2043909
bf143f
RH-Acked-by: Thomas Huth <thuth@redhat.com>
bf143f
RH-Acked-by: Cornelia Huck <cohuck@redhat.com>
bf143f
RH-Acked-by: Jon Maloy <jmaloy@redhat.com>
bf143f
RH-Commit: [30/41] 417ac19fa96036e0242f40121ac6e87a9f3f70ba
bf143f
bf143f
This should be functionally equivalent, but slightly easier to read,
bf143f
with simplified paths and checks at the end of the function.
bf143f
bf143f
The following patch is a major rewrite to get rid of the assert().
bf143f
bf143f
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
bf143f
Reviewed-by: David Hildenbrand <david@redhat.com>
bf143f
(cherry picked from commit 08df343874fcddd260021a04ce3c5a34f2c48164)
bf143f
Signed-off-by: Cédric Le Goater <clg@redhat.com>
bf143f
---
bf143f
 dump/dump.c | 21 ++++++++-------------
bf143f
 1 file changed, 8 insertions(+), 13 deletions(-)
bf143f
bf143f
diff --git a/dump/dump.c b/dump/dump.c
bf143f
index c2c1341ad7..1c49232390 100644
bf143f
--- a/dump/dump.c
bf143f
+++ b/dump/dump.c
bf143f
@@ -1133,17 +1133,11 @@ static bool get_next_page(GuestPhysBlock **blockptr, uint64_t *pfnptr,
bf143f
     if (!block) {
bf143f
         block = QTAILQ_FIRST(&s->guest_phys_blocks.head);
bf143f
         *blockptr = block;
bf143f
-        assert((block->target_start & ~target_page_mask) == 0);
bf143f
-        assert((block->target_end & ~target_page_mask) == 0);
bf143f
-        *pfnptr = dump_paddr_to_pfn(s, block->target_start);
bf143f
-        if (bufptr) {
bf143f
-            *bufptr = block->host_addr;
bf143f
-        }
bf143f
-        return true;
bf143f
+        addr = block->target_start;
bf143f
+    } else {
bf143f
+        addr = dump_pfn_to_paddr(s, *pfnptr + 1);
bf143f
     }
bf143f
-
bf143f
-    *pfnptr = *pfnptr + 1;
bf143f
-    addr = dump_pfn_to_paddr(s, *pfnptr);
bf143f
+    assert(block != NULL);
bf143f
 
bf143f
     if ((addr >= block->target_start) &&
bf143f
         (addr + s->dump_info.page_size <= block->target_end)) {
bf143f
@@ -1155,12 +1149,13 @@ static bool get_next_page(GuestPhysBlock **blockptr, uint64_t *pfnptr,
bf143f
         if (!block) {
bf143f
             return false;
bf143f
         }
bf143f
-        assert((block->target_start & ~target_page_mask) == 0);
bf143f
-        assert((block->target_end & ~target_page_mask) == 0);
bf143f
-        *pfnptr = dump_paddr_to_pfn(s, block->target_start);
bf143f
+        addr = block->target_start;
bf143f
         buf = block->host_addr;
bf143f
     }
bf143f
 
bf143f
+    assert((block->target_start & ~target_page_mask) == 0);
bf143f
+    assert((block->target_end & ~target_page_mask) == 0);
bf143f
+    *pfnptr = dump_paddr_to_pfn(s, addr);
bf143f
     if (bufptr) {
bf143f
         *bufptr = buf;
bf143f
     }
bf143f
-- 
bf143f
2.37.3
bf143f