[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 10/13] block/vhdx: make range overlap check more readable
From: |
Yao Xingtao |
Subject: |
[PATCH 10/13] block/vhdx: make range overlap check more readable |
Date: |
Mon, 22 Jul 2024 00:07:39 -0400 |
use range_overlaps_range() instead of open-coding the overlap check to improve
the readability of the code.
Signed-off-by: Yao Xingtao <yaoxt.fnst@fujitsu.com>
---
block/vhdx.c | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/block/vhdx.c b/block/vhdx.c
index 5aa1a1350626..c31661b946b6 100644
--- a/block/vhdx.c
+++ b/block/vhdx.c
@@ -32,6 +32,7 @@
#include "qapi/qmp/qdict.h"
#include "qapi/qobject-input-visitor.h"
#include "qapi/qapi-visit-block-core.h"
+#include "qemu/range.h"
/* Options for VHDX creation */
@@ -231,15 +232,16 @@ void vhdx_guid_generate(MSGUID *guid)
static int vhdx_region_check(BDRVVHDXState *s, uint64_t start, uint64_t length)
{
int ret = 0;
- uint64_t end;
VHDXRegionEntry *r;
+ Range range1, range2;
- end = start + length;
+ range_init_nofail(&range1, start, length);
QLIST_FOREACH(r, &s->regions, entries) {
- if (!((start >= r->end) || (end <= r->start))) {
+ range_init_nofail(&range2, r->start, r->end - r->start);
+ if (range_overlaps_range(&range1, &range2)) {
error_report("VHDX region %" PRIu64 "-%" PRIu64 " overlaps with "
- "region %" PRIu64 "-%." PRIu64, start, end, r->start,
- r->end);
+ "region %" PRIu64 "-%." PRIu64, start, start + length,
+ r->start, r->end);
ret = -EINVAL;
goto exit;
}
--
2.41.0
- [PATCH 00/13] make range overlap check more readable, Yao Xingtao, 2024/07/22
- [PATCH 01/13] range: Make ranges_overlap() return bool, Yao Xingtao, 2024/07/22
- [PATCH 02/13] arm/boot: make range overlap check more readable, Yao Xingtao, 2024/07/22
- [PATCH 04/13] cxl/mailbox: make range overlap check more readable, Yao Xingtao, 2024/07/22
- [PATCH 13/13] block/qcow2-cluster: make range overlap check more readable, Yao Xingtao, 2024/07/22
- [PATCH 05/13] display/sm501: make range overlap check more readable, Yao Xingtao, 2024/07/22
- [PATCH 10/13] block/vhdx: make range overlap check more readable,
Yao Xingtao <=
- [PATCH 06/13] aspeed_smc: make range overlap check more readable, Yao Xingtao, 2024/07/22
- [PATCH 08/13] sparc/ldst_helper: make range overlap check more readable, Yao Xingtao, 2024/07/22
- [PATCH 11/13] crypto/block-luks: make range overlap check more readable, Yao Xingtao, 2024/07/22
- [PATCH 09/13] system/memory_mapping: make range overlap check more readable, Yao Xingtao, 2024/07/22