Skip to content

Commit

Permalink
[review v3] core: REE FS: close dirfile on error
Browse files Browse the repository at this point in the history
- 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 <jens.wiklander@linaro.org>
  • Loading branch information
jenswi-linaro committed Jun 26, 2017
1 parent a231bc9 commit 8f154bb
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions core/tee/tee_ree_fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)
Expand All @@ -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,
Expand Down

0 comments on commit 8f154bb

Please sign in to comment.