From 076522d57a1de87008762ad5cf8bfb0f5e40bb6a Mon Sep 17 00:00:00 2001 From: Etienne Carriere Date: Wed, 20 Mar 2019 10:01:23 +0100 Subject: [PATCH] libteec: fix build warnings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix build warnings reported by the Buildroot team [1]: /home/thomas/projets/outputs/armv5-ctng-linux-gnueabi/build/optee-client-3.4.0/libteec/src/tee_client_api.c: In function 'TEEC_InitializeContext': /home/thomas/projets/outputs/armv5-ctng-linux-gnueabi/build/optee-client-3.4.0/libteec/src/tee_client_api.c:149:28: error: 'gen_caps' may be used uninitialized in this function [-Werror=maybe-uninitialized] ctx->reg_mem = gen_caps & TEE_GEN_CAP_REG_MEM; ^ /home/thomas/projets/buildroot/output/build/optee-client-3.4.0/libteec/src/tee_client_api.c: In function ‘TEEC_OpenSession’: /home/thomas/projets/buildroot/output/build/optee-client-3.4.0/libteec/src/tee_client_api.c:507:8: error: cast increases required alignment of target type [-Werror=cast-align] arg = (struct tee_ioctl_open_session_arg *)buf; ^ /home/thomas/projets/buildroot/output/build/optee-client-3.4.0/libteec/src/tee_client_api.c: In function ‘TEEC_InvokeCommand’: /home/thomas/projets/buildroot/output/build/optee-client-3.4.0/libteec/src/tee_client_api.c:581:8: error: cast increases required alignment of target type [-Werror=cast-align] arg = (struct tee_ioctl_invoke_arg *)buf; ^ [1] http://lists.busybox.net/pipermail/buildroot/2019-February/243437.html Reported-by: Thomas Petazzoni Signed-off-by: Etienne Carriere Tested-by: Jerome Forissier (HiKey960 32, 64) Reviewed-by: Jens Wiklander Upstream: https://github.com/OP-TEE/optee_client/commit/9dbc61b3767ab1c3dfd0a19af02926b92ae09247 --- libteec/src/tee_client_api.c | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/libteec/src/tee_client_api.c b/libteec/src/tee_client_api.c index 698092b..cf0b1f7 100644 --- a/libteec/src/tee_client_api.c +++ b/libteec/src/tee_client_api.c @@ -140,7 +140,7 @@ TEEC_Result TEEC_InitializeContext(const char *name, TEEC_Context *ctx) return TEEC_ERROR_BAD_PARAMETERS; for (n = 0; n < TEEC_MAX_DEV_SEQ; n++) { - uint32_t gen_caps; + uint32_t gen_caps = 0; snprintf(devname, sizeof(devname), "/dev/tee%zu", n); fd = teec_open_dev(devname, name, &gen_caps); @@ -481,10 +481,12 @@ TEEC_Result TEEC_OpenSession(TEEC_Context *ctx, TEEC_Session *session, uint32_t connection_method, const void *connection_data, TEEC_Operation *operation, uint32_t *ret_origin) { - uint64_t buf[(sizeof(struct tee_ioctl_open_session_arg) + - TEEC_CONFIG_PAYLOAD_REF_COUNT * - sizeof(struct tee_ioctl_param)) / - sizeof(uint64_t)] = { 0 }; + size_t p_sz = TEEC_CONFIG_PAYLOAD_REF_COUNT * + sizeof(struct tee_ioctl_param); + union { + struct tee_ioctl_open_session_arg arg; + uint8_t data[sizeof(struct tee_ioctl_open_session_arg) + p_sz]; + } buf; struct tee_ioctl_buf_data buf_data; struct tee_ioctl_open_session_arg *arg; struct tee_ioctl_param *params; @@ -493,6 +495,8 @@ TEEC_Result TEEC_OpenSession(TEEC_Context *ctx, TEEC_Session *session, TEEC_SharedMemory shm[TEEC_CONFIG_PAYLOAD_REF_COUNT]; int rc; + memset(&buf, 0, sizeof(buf)); + (void)&connection_data; if (!ctx || !session) { @@ -501,10 +505,10 @@ TEEC_Result TEEC_OpenSession(TEEC_Context *ctx, TEEC_Session *session, goto out; } - buf_data.buf_ptr = (uintptr_t)buf; + buf_data.buf_ptr = (uintptr_t)&buf; buf_data.buf_len = sizeof(buf); - arg = (struct tee_ioctl_open_session_arg *)buf; + arg = &buf.arg; arg->num_params = TEEC_CONFIG_PAYLOAD_REF_COUNT; params = (struct tee_ioctl_param *)(arg + 1); @@ -555,10 +559,12 @@ void TEEC_CloseSession(TEEC_Session *session) TEEC_Result TEEC_InvokeCommand(TEEC_Session *session, uint32_t cmd_id, TEEC_Operation *operation, uint32_t *error_origin) { - uint64_t buf[(sizeof(struct tee_ioctl_invoke_arg) + - TEEC_CONFIG_PAYLOAD_REF_COUNT * - sizeof(struct tee_ioctl_param)) / - sizeof(uint64_t)] = { 0 }; + size_t p_sz = TEEC_CONFIG_PAYLOAD_REF_COUNT * + sizeof(struct tee_ioctl_param); + union { + struct tee_ioctl_invoke_arg arg; + uint8_t data[sizeof(struct tee_ioctl_invoke_arg) + p_sz]; + } buf; struct tee_ioctl_buf_data buf_data; struct tee_ioctl_invoke_arg *arg; struct tee_ioctl_param *params; @@ -567,6 +573,8 @@ TEEC_Result TEEC_InvokeCommand(TEEC_Session *session, uint32_t cmd_id, TEEC_SharedMemory shm[TEEC_CONFIG_PAYLOAD_REF_COUNT]; int rc; + memset(&buf, 0, sizeof(buf)); + if (!session) { eorig = TEEC_ORIGIN_API; res = TEEC_ERROR_BAD_PARAMETERS; @@ -575,10 +583,10 @@ TEEC_Result TEEC_InvokeCommand(TEEC_Session *session, uint32_t cmd_id, bm_timestamp(); - buf_data.buf_ptr = (uintptr_t)buf; + buf_data.buf_ptr = (uintptr_t)&buf; buf_data.buf_len = sizeof(buf); - arg = (struct tee_ioctl_invoke_arg *)buf; + arg = &buf.arg; arg->num_params = TEEC_CONFIG_PAYLOAD_REF_COUNT; params = (struct tee_ioctl_param *)(arg + 1); -- 2.17.1