Skip to content

Commit c3b31bc

Browse files
Ron EldorRon Eldor
authored andcommitted
Add Mbed TLS Platform module errors
1. Add error codes for platform setup \ teardown. 2. Reassign `reference_count` to 0 after terminating platform, and remove condition for 0
1 parent ca94a49 commit c3b31bc

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

features/cryptocell/FEATURE_CRYPTOCELL310/TARGET_MCU_NRF52840/crypto_platform.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ int crypto_platform_setup( crypto_platform_ctx *ctx )
3434
NRF_CRYPTOCELL->ENABLE = 1;
3535

3636
if( SaSi_LibInit( &rndState, &rndWorkBuff ) != 0 )
37-
return ( -1 );
37+
return ( MBEDTLS_PLATFORM_HW_FAILED );
3838

3939
return ( 0 );
4040
}

features/mbedtls/platform/inc/platform_mbed.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,6 @@
2424
#if defined(MBEDTLS_CONFIG_HW_SUPPORT)
2525
#include "mbedtls_device.h"
2626
#endif
27+
28+
#define MBEDTLS_PLATFORM_INVALID_DATA -0x0080
29+
#define MBEDTLS_PLATFORM_HW_FAILED -0x0082

features/mbedtls/platform/src/platform_alt.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ int mbedtls_platform_setup( mbedtls_platform_context *ctx )
2727
{
2828
int ret = 0;
2929
if( ctx == NULL )
30-
return ( -1 );
30+
return ( MBEDTLS_PLATFORM_INVALID_DATA );
3131

3232
reference_count++;
3333

@@ -44,15 +44,13 @@ void mbedtls_platform_teardown( mbedtls_platform_context *ctx )
4444
if( ctx == NULL )
4545
return;
4646

47-
if( reference_count == 0 )
48-
return;
49-
5047
reference_count--;
5148

52-
if( reference_count == 0 )
49+
if( reference_count <= 0 )
5350
{
5451
/* call platform specific code to terminate crypto driver*/
5552
crypto_platform_terminate( &ctx->platform_impl_ctx );
53+
reference_count = 0;
5654
}
5755
}
5856

0 commit comments

Comments
 (0)