diff options
| author | Xiang W <[email protected]> | 2025-09-03 12:46:02 +0800 |
|---|---|---|
| committer | Anup Patel <[email protected]> | 2025-10-06 14:28:38 +0530 |
| commit | f7d060c26a7a3c691e29dc0d89957a6ff4e1cb31 (patch) | |
| tree | b48bcb6ffbc17eb4b7c8b44ccc7f3816e4bb2731 /lib | |
| parent | 5de8c1d49983ada5daa68fc01979526f510d8063 (diff) | |
lib: sbi: Add error handling to switch_to_next_domain_context
Add error handling to switch_to_next_domain_context to ensure
legal input. When switching contexts, ensure that the target to
be switched is different from the current one.
Signed-off-by: Xiang W <[email protected]>
Reviewed-by: Anup Patel <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Anup Patel <[email protected]>
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/sbi/sbi_domain_context.c | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/lib/sbi/sbi_domain_context.c b/lib/sbi/sbi_domain_context.c index fb04d81d..fffb6a48 100644 --- a/lib/sbi/sbi_domain_context.c +++ b/lib/sbi/sbi_domain_context.c @@ -92,17 +92,23 @@ static void hart_context_set(struct sbi_domain *dom, u32 hartindex, * * @param ctx pointer to the current HART context * @param dom_ctx pointer to the target domain context + * + * @return 0 on success and negative error code on failure */ -static void switch_to_next_domain_context(struct hart_context *ctx, +static int switch_to_next_domain_context(struct hart_context *ctx, struct hart_context *dom_ctx) { u32 hartindex = current_hartindex(); struct sbi_trap_context *trap_ctx; - struct sbi_domain *current_dom = ctx->dom; - struct sbi_domain *target_dom = dom_ctx->dom; + struct sbi_domain *current_dom, *target_dom; struct sbi_scratch *scratch = sbi_scratch_thishart_ptr(); unsigned int pmp_count = sbi_hart_pmp_count(scratch); + if (!ctx || !dom_ctx || ctx == dom_ctx) + return SBI_EINVAL; + + current_dom = ctx->dom; + target_dom = dom_ctx->dom; /* Assign current hart to target domain */ spin_lock(¤t_dom->assigned_harts_lock); sbi_hartmask_clear_hartindex(hartindex, ¤t_dom->assigned_harts); @@ -156,6 +162,7 @@ static void switch_to_next_domain_context(struct hart_context *ctx, else sbi_hsm_hart_stop(scratch, true); } + return 0; } int sbi_domain_context_enter(struct sbi_domain *dom) @@ -170,9 +177,7 @@ int sbi_domain_context_enter(struct sbi_domain *dom) /* Update target context's previous context to indicate the caller */ dom_ctx->prev_ctx = ctx; - switch_to_next_domain_context(ctx, dom_ctx); - - return 0; + return switch_to_next_domain_context(ctx, dom_ctx); } int sbi_domain_context_exit(void) @@ -226,9 +231,7 @@ int sbi_domain_context_exit(void) if (!dom_ctx) dom_ctx = hart_context_get(&root, hartindex); - switch_to_next_domain_context(ctx, dom_ctx); - - return 0; + return switch_to_next_domain_context(ctx, dom_ctx); } int sbi_domain_context_init(void) |
