From 8f154bb7d119c00c8a5219c5fd0cb5b8448e1b2a Mon Sep 17 00:00:00 2001 From: Jens Wiklander Date: Mon, 26 Jun 2017 12:55:31 +0200 Subject: [PATCH] [review v3] core: REE FS: close dirfile on error - Failure from get_dirh() results in *dirh = NULL - put_dirh() with dirh == NULL is ignored put_dirh() after failing get_dirh() isn't needed, but harmless if done since dirh will be NULL. Signed-off-by: Jens Wiklander --- core/tee/tee_ree_fs.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/core/tee/tee_ree_fs.c b/core/tee/tee_ree_fs.c index f10c7fef7f9..9ad3dbf7ed0 100644 --- a/core/tee/tee_ree_fs.c +++ b/core/tee/tee_ree_fs.c @@ -534,13 +534,15 @@ static void close_dirh(struct tee_fs_dirfile_dirh **dirh) static TEE_Result get_dirh(struct tee_fs_dirfile_dirh **dirh) { - ree_fs_dirh_refcount++; if (!ree_fs_dirh) { TEE_Result res = open_dirh(&ree_fs_dirh); - if (res) + if (res) { + *dirh = NULL; return res; + } } + ree_fs_dirh_refcount++; assert(ree_fs_dirh); assert(ree_fs_dirh_refcount); *dirh = ree_fs_dirh; @@ -550,6 +552,7 @@ static TEE_Result get_dirh(struct tee_fs_dirfile_dirh **dirh) static void put_dirh_primitive(bool close) { assert(ree_fs_dirh_refcount); + assert(ree_fs_dirh); ree_fs_dirh_refcount--; if (!ree_fs_dirh_refcount || close) @@ -558,8 +561,10 @@ static void put_dirh_primitive(bool close) static void put_dirh(struct tee_fs_dirfile_dirh *dirh, bool close) { - assert(!dirh || dirh == ree_fs_dirh); - put_dirh_primitive(close); + if (dirh) { + assert(dirh == ree_fs_dirh); + put_dirh_primitive(close); + } } static TEE_Result ree_fs_open(struct tee_pobj *po, size_t *size,