diff mbox series

[06/13] aspeed_smc: make range overlap check more readable

Message ID 20240722040742.11513-7-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>
---
 hw/ssi/aspeed_smc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Philippe Mathieu-Daudé July 22, 2024, 7:11 a.m. UTC | #1
On 22/7/24 06:07, Yao Xingtao via 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>
> ---
>   hw/ssi/aspeed_smc.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Tested-by: Philippe Mathieu-Daudé <philmd@linaro.org>
diff mbox series

Patch

diff --git a/hw/ssi/aspeed_smc.c b/hw/ssi/aspeed_smc.c
index 49205ab76d38..cdca359e1d88 100644
--- a/hw/ssi/aspeed_smc.c
+++ b/hw/ssi/aspeed_smc.c
@@ -31,6 +31,7 @@ 
 #include "qemu/error-report.h"
 #include "qapi/error.h"
 #include "qemu/units.h"
+#include "qemu/range.h"
 #include "trace.h"
 
 #include "hw/irq.h"
@@ -246,8 +247,7 @@  static bool aspeed_smc_flash_overlap(const AspeedSMCState *s,
 
         asc->reg_to_segment(s, s->regs[R_SEG_ADDR0 + i], &seg);
 
-        if (new->addr + new->size > seg.addr &&
-            new->addr < seg.addr + seg.size) {
+        if (ranges_overlap(new->addr, new->size, seg.addr, seg.size)) {
             aspeed_smc_error("new segment CS%d [ 0x%"
                              HWADDR_PRIx" - 0x%"HWADDR_PRIx" ] overlaps with "
                              "CS%d [ 0x%"HWADDR_PRIx" - 0x%"HWADDR_PRIx" ]",