imx: cmd_dek: Fix Uninitialized pointer read
authorYe Li <ye.li@nxp.com>
Thu, 15 Jun 2023 10:09:10 +0000 (18:09 +0800)
committerStefano Babic <sbabic@denx.de>
Thu, 13 Jul 2023 09:29:40 +0000 (11:29 +0200)
Fix Coverity (CID 21143558).
When tee_shm_register returns failure, the shm_input pointer is
invalid, should not free it. Same issue also exists on registering
shm_output.

Reviewed-by: Peng Fan <peng.fan@nxp.com>
Signed-off-by: Ye Li <ye.li@nxp.com>
Signed-off-by: Peng Fan <peng.fan@nxp.com>
arch/arm/mach-imx/cmd_dek.c

index d77a49d..0be9df5 100644 (file)
@@ -101,6 +101,7 @@ static int blob_encap_dek(u32 src_addr, u32 dst_addr, u32 len)
                               0x0, &shm_output);
        if (ret < 0) {
                printf("Cannot register output shared memory 0x%X\n", ret);
+               tee_shm_free(shm_input);
                goto error;
        }
 
@@ -122,11 +123,11 @@ static int blob_encap_dek(u32 src_addr, u32 dst_addr, u32 len)
        if (ret < 0)
                printf("Cannot generate Blob with PTA DEK Blob 0x%X\n", ret);
 
-error:
        /* Free shared memory */
        tee_shm_free(shm_input);
        tee_shm_free(shm_output);
 
+error:
        /* Close session */
        ret = tee_close_session(dev, arg.session);
        if (ret < 0)