Skip to content

Commit 1f5cee9

Browse files
Ron EldorRon Eldor
authored andcommitted
Address concurrency and style issues
1. Use atomic operations to increase and decrease counter. 2. Style fixes. Remove unused function declaration.
1 parent 4794389 commit 1f5cee9

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

features/mbedtls/platform/inc/platform_alt.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ typedef struct {
3636
mbedtls_platform_context;
3737

3838

39-
void mbedtls_platform_init( mbedtls_platform_context* ctx);
4039
/**
4140
* \brief This function performs any platform initialization operations,
4241
* needed for setting up cryptographic modules.

features/mbedtls/platform/src/platform_alt.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,19 @@
2020

2121
#include "mbedtls/platform.h"
2222
#if defined(MBEDTLS_PLATFORM_SETUP_TEARDOWN_ALT)
23-
mbedtls_platform_context ctx = {0};
23+
#include "mbed_critical.h"
24+
25+
mbedtls_platform_context ctx = { };
2426

2527
int mbedtls_platform_setup( mbedtls_platform_context *obsolete_ctx )
2628
{
2729
int ret = 0;
2830

29-
ctx.reference_count++;
31+
core_util_atomic_incr_u32( ( volatile uint32_t * )&ctx.reference_count, 1 );
3032

3133
if( ctx.reference_count == 1 )
3234
{
33-
/* call platform specific code to setup crypto driver*/
35+
/* call platform specific code to setup crypto driver */
3436
ret = crypto_platform_setup( &ctx.platform_impl_ctx );
3537
}
3638
return ( ret );
@@ -39,11 +41,10 @@ int mbedtls_platform_setup( mbedtls_platform_context *obsolete_ctx )
3941
void mbedtls_platform_teardown( mbedtls_platform_context *obsolete_ctx )
4042
{
4143

42-
ctx.reference_count--;
43-
44+
core_util_atomic_decr_u32( ( volatile uint32_t * )&ctx.reference_count, 1 );
4445
if( ctx.reference_count <= 0 )
4546
{
46-
/* call platform specific code to terminate crypto driver*/
47+
/* call platform specific code to terminate crypto driver */
4748
crypto_platform_terminate( &ctx.platform_impl_ctx );
4849
ctx.reference_count = 0;
4950
}

0 commit comments

Comments
 (0)