From 2275c976020f7ec8124f0f00a8d57debb7888bc4 Mon Sep 17 00:00:00 2001 From: JacobBarthelmeh Date: Sat, 6 Mar 2021 14:21:44 +0700 Subject: [PATCH] check ret of lock and adjust return type --- wolfcrypt/src/port/caam/caam_qnx.c | 4 ++-- wolfcrypt/src/port/caam/wolfcaam_init.c | 7 +++++-- wolfcrypt/src/port/caam/wolfcaam_qnx.c | 9 ++++++--- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/wolfcrypt/src/port/caam/caam_qnx.c b/wolfcrypt/src/port/caam/caam_qnx.c index 334bbbd2a..435390df2 100644 --- a/wolfcrypt/src/port/caam/caam_qnx.c +++ b/wolfcrypt/src/port/caam/caam_qnx.c @@ -89,7 +89,7 @@ int CAAM_SET_BASEADDR() /* convert a virtual address to a physical address * returns the physical address on success */ -unsigned int CAAM_ADR_TO_PHYSICAL(void* in, int inSz) +CAAM_ADDRESS CAAM_ADR_TO_PHYSICAL(void* in, int inSz) { off64_t ofst = 0; int ret, count = 0;; @@ -112,7 +112,7 @@ unsigned int CAAM_ADR_TO_PHYSICAL(void* in, int inSz) count++; } while (ret != 0 && ret == -1 && count < 5); - return (int)ofst; + return (CAAM_ADDRESS)ofst; } diff --git a/wolfcrypt/src/port/caam/wolfcaam_init.c b/wolfcrypt/src/port/caam/wolfcaam_init.c index 00a118b32..3a0b5e7c6 100644 --- a/wolfcrypt/src/port/caam/wolfcaam_init.c +++ b/wolfcrypt/src/port/caam/wolfcaam_init.c @@ -224,16 +224,19 @@ word32 wc_caamReadRegister(word32 reg) return (word32)out; } -void wc_caamWriteRegister(word32 reg, word32 value) + +/* returns 0 on success */ +int wc_caamWriteRegister(word32 reg, word32 value) { if (caam == NULLIODevice) { WOLFSSL_MSG("Error CAAM IODevice not found! Bad password?"); - return; + return -1; } if (WriteIODeviceRegister(caam, reg, value) != Success) { WOLFSSL_MSG("Error writing to register\n"); } + return 0; } #endif diff --git a/wolfcrypt/src/port/caam/wolfcaam_qnx.c b/wolfcrypt/src/port/caam/wolfcaam_qnx.c index f71514b0a..741e3700c 100644 --- a/wolfcrypt/src/port/caam/wolfcaam_qnx.c +++ b/wolfcrypt/src/port/caam/wolfcaam_qnx.c @@ -328,9 +328,12 @@ int SynchronousSendRequest(int type, unsigned int args[4], CAAM_BUFFER *buf, return -1; } - wc_LockMutex(&caamMutex); - ret = devctlv(caamFd, cmd, inIdx, outIdx, in, out, NULL); - wc_UnLockMutex(&caamMutex); + ret = wc_LockMutex(&caamMutex); + if (ret == 0) { + ret = devctlv(caamFd, cmd, inIdx, outIdx, in, out, NULL); + wc_UnLockMutex(&caamMutex); + } + if (ret != 0) { if (ret == EFAULT) { WOLFSSL_MSG("bad address on one of the in/out buffers");