浏览代码

lib: sbi: Fix is_region_valid()

When order is equal to __riscv_xlen, the shift operation will not perform
any operation, which will cause reg->base & (BIT(reg->order) - 1) to always
be 0, and the condition has not been established.

This patch fixes this bug.

Signed-off-by: Xiang W <wxjstz@126.com>
Reviewed-by: Anup Patel <anup@brainfault.org>
Xiang W 1 年之前
父节点
当前提交
fc82e84329
共有 1 个文件被更改,包括 3 次插入0 次删除
  1. 3 0
      lib/sbi/sbi_domain.c

+ 3 - 0
lib/sbi/sbi_domain.c

@@ -146,6 +146,9 @@ static bool is_region_valid(const struct sbi_domain_memregion *reg)
 	if (reg->order < 3 || __riscv_xlen < reg->order)
 		return FALSE;
 
+	if (reg->order == __riscv_xlen && reg->base != 0)
+		return FALSE;
+
 	if (reg->base & (BIT(reg->order) - 1))
 		return FALSE;