[PATCH 3/3] lib: sbi: Prevent target domain same as the current

Xiang W wxjstz at 126.com
Tue Sep 2 21:46:04 PDT 2025


Add error handling code to sbi_domain_context_enter to prevent the
target domain from being the same as the current domain.

Signed-off-by: Xiang W <wxjstz at 126.com>
---
 lib/sbi/sbi_domain_context.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/lib/sbi/sbi_domain_context.c b/lib/sbi/sbi_domain_context.c
index 992aad35..eead3987 100644
--- a/lib/sbi/sbi_domain_context.c
+++ b/lib/sbi/sbi_domain_context.c
@@ -191,6 +191,9 @@ int sbi_domain_context_enter(struct sbi_domain *dom)
 	struct hart_context *dom_ctx;
 	struct hart_context *ctx = hart_context_thishart_get();
 
+	/* target domain must not equal current domain */
+	if (!dom || dom == sbi_domain_thishart_ptr())
+		return SBI_EINVAL;
 	/*
 	 * If it's first time to call `enter` on the current hart, no
 	 * context allocated before. Allocate context for each valid
-- 
2.47.2




More information about the opensbi mailing list