xen/arm: tee: Fix MISRA findings
cover xen/arm: tee: Fix MISRA findings
This series fixes two MISRA findings in the arm/tee mediators.
1. Rename a local variable in FF-A partition-info handling to avoid shadowing the global ffa_vm_count (Rule 5.3 report).
2. Add/document default switch labels in OP-TEE paths to satisfy Rule 16.4 checks.
This serie is based on "xen/arm: ffa: Add PARTITION_INFO_GET_REGS support" which is pending for merge in the tree so it must not be merged before it !!
The following pipeline executed on top of this serie shows that there are no findings anymore in xen/arch/arm/tee:
https://gitlab.com/xen-project/people/bmarquis/xen-ffa-research/-/pipelines/2395186683
Bertrand Marquis (2):
xen/arm: ffa: Fix local ffa_vm_count shadowing xen/arm: optee: Add MISRA-compliant switch default labels
xen/arch/arm/tee/ffa_partinfo.c | 14 +++++++------- xen/arch/arm/tee/optee.c | 11 +++++++++++ 2 files changed, 18 insertions(+), 7 deletions(-)
Signature · 1 line
2.52.0
PATCH 1/2 xen/arm: ffa: Fix local ffa_vm_count shadowing
ffa_handle_partition_info_get() declares a local variable named ffa_vm_count, which hides the global atomic ffa_vm_count declared in ffa_private.h.
This triggered the ECLAIR Rule 5.3 finding "non-compliant local variable `ffa_vm_count'".
Rename the local counters to vm_count and sp_count and update their uses.
No functional changes.
--- xen/arch/arm/tee/ffa_partinfo.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
xen/arch/arm/tee/ffa_partinfo.c +7 -7
@@ -346,7 +346,7 @@ void ffa_handle_partition_info_get(struct cpu_user_regs *regs)uint32_t dst_size =0 ;size_t buf_size;void *dst_buf, *end_buf; -uint32_t ffa_vm_count =0 , ffa_sp_count =0 ; +uint32_t vm_count =0 , sp_count =0 ; ffa_uuid_set(&uuid, get_user_reg(regs, 1),
@@ -380,7 +380,7 @@ void ffa_handle_partition_info_get(struct cpu_user_regs *regs)if (ffa_fw_supports_fid (FFA_PARTITION_INFO_GET ) ) { - ret =ffa_get_sp_count (uuid, &ffa_sp_count); + ret =ffa_get_sp_count (uuid, &sp_count);if ( ret ) goto out; }
@@ -391,7 +391,7 @@ void ffa_handle_partition_info_get(struct cpu_user_regs *regs)*/ if (ffa_uuid_is_nil (uuid) ) { - ffa_vm_count =get_ffa_vm_count (); + vm_count =get_ffa_vm_count ();/* * Workaround for Linux FF-A Driver not accepting to have its own
@@ -401,7 +401,7 @@ void ffa_handle_partition_info_get(struct cpu_user_regs *regs)* the requester endpoint information should be included or not */ if (ACCESS_ONCE (ctx->guest_vers) <FFA_VERSION_1_2 ) - ffa_vm_count -=1 ; + vm_count -=1 ; } goto out;
@@ -429,14 +429,14 @@ void ffa_handle_partition_info_get(struct cpu_user_regs *regs)if (ffa_fw_supports_fid (FFA_PARTITION_INFO_GET ) ) { - ret =ffa_get_sp_partinfo (uuid, &ffa_sp_count, &dst_buf, end_buf, + ret =ffa_get_sp_partinfo (uuid, &sp_count, &dst_buf, end_buf, dst_size);if ( ret ) goto out_rx_release; } - ret =ffa_get_vm_partinfo (uuid,0 , &ffa_vm_count, &dst_buf, end_buf, + ret =ffa_get_vm_partinfo (uuid,0 , &vm_count, &dst_buf, end_buf, dst_size); out_rx_release:
@@ -451,7 +451,7 @@ out:if ( flags ||ACCESS_ONCE (ctx->guest_vers) ==FFA_VERSION_1_0 ) dst_size =0 ; -ffa_set_regs_success (regs, ffa_sp_count + ffa_vm_count, dst_size); +ffa_set_regs_success (regs, sp_count + vm_count, dst_size); } }
Signature · 1 line
2.52.0
Re: [PATCH 1/2] xen/arm: ffa: Fix local ffa_vm_count shadowing
Quoted 7 lines · Bertrand Marquis
ffa_handle_partition_info_get()declares a local variable namedffa_vm_count, which hides the global atomicffa_vm_countdeclared inffa_private.h.This triggered the ECLAIR Rule 5.3 finding "non-compliant local variable `ffa_vm_count'".
Quoted 6 lines
Rename the local counters to
vm_countandsp_countand update their uses.No functional changes.
Signed-off-by Bertrand Marquis <[email protected]>
~Michal
Re: [PATCH 1/2] xen/arm: ffa: Fix local ffa_vm_count shadowing
In reply to Bertrand MarquisQuoted 11 lines · Bertrand Marquis
ffa_handle_partition_info_get()declares a local variable namedffa_vm_count, which hides the global atomicffa_vm_countdeclared inffa_private.h.This triggered the ECLAIR Rule 5.3 finding "non-compliant local variable `ffa_vm_count'".
Rename the local counters to
vm_countandsp_countand update their uses.
Quoted 6 lines
No functional changes.
Signed-off-by Bertrand Marquis <[email protected]>--- xen/arch/arm/tee/ffa_partinfo.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
Cheers,
Jens
PATCH 2/2 xen/arm: optee: Add MISRA-compliant switch default labels
In reply to Bertrand Marquisoptee.c has several switch statements over integer-valued OP-TEE fields without a default label, and two default clauses that only contain break. This triggers MISRA C Rule 16.4 findings.
Add explicit default labels to all reported switches and document the intentional no-op defaults with rationale comments. The new default paths preserve the existing behavior:
- unsupported parameter attribute types are ignored;
- non-handled RPC commands require no post-processing in Xen;
- unknown RPC function IDs are resumed unchanged.
No functional changes.
--- xen/arch/arm/tee/optee.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
xen/arch/arm/tee/optee.c +11 -0
@@ -897,6 +897,9 @@ static int translate_params(struct optee_domain *ctx,case OPTEE_MSG_ATTR_TYPE_RMEM_OUTPUT :case OPTEE_MSG_ATTR_TYPE_RMEM_INOUT :continue ; +default : +/* Ignore unsupported parameter type. */ +continue ; } }
@@ -1027,6 +1030,9 @@ static void copy_std_request_back(struct optee_domain *ctx,case OPTEE_MSG_ATTR_TYPE_RMEM_INPUT :case OPTEE_MSG_ATTR_TYPE_TMEM_INPUT :continue ; +default : +/* No output fields to copy for unsupported parameter type. */ +continue ; } }
@@ -1050,6 +1056,7 @@ static void free_shm_buffers(struct optee_domain *ctx,free_optee_shm_buf (ctx, arg->params[i].u.tmem.shm_ref);break ;default : +/* No temporary SHM buffer to free for other parameter types. */ break ; } }
@@ -1503,6 +1510,7 @@ static void handle_rpc_cmd(struct optee_domain *ctx, struct cpu_user_regs *regs,case OPTEE_RPC_CMD_SHM_FREE :break ;default : +/* Other RPC commands need no Xen-side post-processing here. */ break ; } }
@@ -1591,6 +1599,9 @@ static void handle_rpc(struct optee_domain *ctx, struct cpu_user_regs *regs)case OPTEE_SMC_RPC_FUNC_CMD :handle_rpc_cmd (ctx, regs, call);return ; +default : +/* Resume the call unchanged for unknown RPC function IDs. */ +break ; } do_call_with_arg(ctx, call, regs, OPTEE_SMC_CALL_RETURN_FROM_RPC,
Signature · 1 line
2.52.0
Re: [PATCH 2/2] xen/arm: optee: Add MISRA-compliant switch default labels
Quoted 11 lines · Bertrand Marquis
optee.chas several switch statements over integer-valued OP-TEE fields without a default label, and two default clauses that only contain break. This triggers MISRA C Rule 16.4 findings.Add explicit default labels to all reported switches and document the intentional no-op defaults with rationale comments. The new default paths preserve the existing behavior:
- unsupported parameter attribute types are ignored;
- non-handled RPC commands require no post-processing in Xen;
- unknown RPC function IDs are resumed unchanged.
Quoted 3 lines
No functional changes.
Signed-off-by Bertrand Marquis <[email protected]>
~Michal
Re: [PATCH 2/2] xen/arm: optee: Add MISRA-compliant switch default labels
In reply to Bertrand MarquisHi Bertrand,
Quoted 12 lines · Bertrand Marquis
optee.chas several switch statements over integer-valued OP-TEE fields without a default label, and two default clauses that only contain break. This triggers MISRA C Rule 16.4 findings.Add explicit default labels to all reported switches and document the intentional no-op defaults with rationale comments. The new default paths preserve the existing behavior:
- unsupported parameter attribute types are ignored;
- non-handled RPC commands require no post-processing in Xen;
- unknown RPC function IDs are resumed unchanged.
Quoted 6 lines
No functional changes.
Signed-off-by Bertrand Marquis <[email protected]>--- xen/arch/arm/tee/optee.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
Looks good.
Cheers,
Jens