lib: sbi: Prevent target domain same as the current

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@126.com>
Reviewed-by: Anup Patel <anup@brainfault.org>
Link: https://lore.kernel.org/r/20250903044619.394019-4-wxjstz@126.com
Signed-off-by: Anup Patel <anup@brainfault.org>
This commit is contained in:
Xiang W
2025-09-03 12:46:04 +08:00
committed by Anup Patel
parent 38c31ffb8f
commit e3eb59a396

View File

@@ -193,6 +193,10 @@ int sbi_domain_context_enter(struct sbi_domain *dom)
struct hart_context *dom_ctx; struct hart_context *dom_ctx;
struct hart_context *ctx = hart_context_thishart_get(); struct hart_context *ctx = hart_context_thishart_get();
/* Target domain must not be same as the 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 * If it's first time to call `enter` on the current hart, no
* context allocated before. Allocate context for each valid * context allocated before. Allocate context for each valid