diff mbox series

[02/13] arm/boot: make range overlap check more readable

Message ID 20240722040742.11513-3-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/arm/boot.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

Comments

Philippe Mathieu-Daudé July 22, 2024, 6:54 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/arm/boot.c | 5 +++--
>   1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/hw/arm/boot.c b/hw/arm/boot.c
> index d480a7da02cf..a004a90e87be 100644
> --- a/hw/arm/boot.c
> +++ b/hw/arm/boot.c
> @@ -26,6 +26,7 @@
>   #include "qemu/config-file.h"
>   #include "qemu/option.h"
>   #include "qemu/units.h"
> +#include "qemu/range.h"
>   
>   /* Kernel boot protocol is specified in the kernel docs
>    * Documentation/arm/Booting and Documentation/arm64/booting.txt
> @@ -238,8 +239,8 @@ void arm_write_secure_board_setup_dummy_smc(ARMCPU *cpu,
>       assert((mvbar_addr & 0x1f) == 0 && (mvbar_addr >> 4) < 0x100);
>   
>       /* check that these blobs don't overlap */
> -    assert((mvbar_addr + sizeof(mvbar_blob) <= info->board_setup_addr)
> -          || (info->board_setup_addr + sizeof(board_setup_blob) <= mvbar_addr));
> +    assert(!ranges_overlap(mvbar_addr, sizeof(mvbar_blob),
> +           info->board_setup_addr, sizeof(board_setup_blob)));

Indentation is of, otherwise:
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Tested-by: Philippe Mathieu-Daudé <philmd@linaro.org>
diff mbox series

Patch

diff --git a/hw/arm/boot.c b/hw/arm/boot.c
index d480a7da02cf..a004a90e87be 100644
--- a/hw/arm/boot.c
+++ b/hw/arm/boot.c
@@ -26,6 +26,7 @@ 
 #include "qemu/config-file.h"
 #include "qemu/option.h"
 #include "qemu/units.h"
+#include "qemu/range.h"
 
 /* Kernel boot protocol is specified in the kernel docs
  * Documentation/arm/Booting and Documentation/arm64/booting.txt
@@ -238,8 +239,8 @@  void arm_write_secure_board_setup_dummy_smc(ARMCPU *cpu,
     assert((mvbar_addr & 0x1f) == 0 && (mvbar_addr >> 4) < 0x100);
 
     /* check that these blobs don't overlap */
-    assert((mvbar_addr + sizeof(mvbar_blob) <= info->board_setup_addr)
-          || (info->board_setup_addr + sizeof(board_setup_blob) <= mvbar_addr));
+    assert(!ranges_overlap(mvbar_addr, sizeof(mvbar_blob),
+           info->board_setup_addr, sizeof(board_setup_blob)));
 
     for (n = 0; n < ARRAY_SIZE(mvbar_blob); n++) {
         mvbar_blob[n] = tswap32(mvbar_blob[n]);