diff options
author | Jens Wiklander | 2018-10-29 05:41:35 -0500 |
---|---|---|
committer | Tom Rini | 2018-11-01 09:02:43 -0500 |
commit | c091dc7dad8cd64c7e185d8af267ed2ef40af8dc (patch) | |
tree | be88e01a66d114155bac6065d30fa7faf081d851 /test | |
parent | be6eb2393131b3c0668df3f04868c56c3bb39702 (diff) | |
download | u-boot-c091dc7dad8cd64c7e185d8af267ed2ef40af8dc.tar.gz u-boot-c091dc7dad8cd64c7e185d8af267ed2ef40af8dc.tar.xz u-boot-c091dc7dad8cd64c7e185d8af267ed2ef40af8dc.zip |
test: tee: fix resource leak in dm_test_tee()
Fixes possible resource leak in dm_test_tee() reported by Coverity.
Reported-by: Coverity (CID: 184175)
Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
Diffstat (limited to 'test')
-rw-r--r-- | test/dm/tee.c | 35 |
1 files changed, 26 insertions, 9 deletions
diff --git a/test/dm/tee.c b/test/dm/tee.c index 13e3f4003a..22f05a4219 100644 --- a/test/dm/tee.c +++ b/test/dm/tee.c | |||
@@ -49,7 +49,12 @@ static int match(struct tee_version_data *vers, const void *data) | |||
49 | return vers->gen_caps & TEE_GEN_CAP_GP; | 49 | return vers->gen_caps & TEE_GEN_CAP_GP; |
50 | } | 50 | } |
51 | 51 | ||
52 | static int dm_test_tee(struct unit_test_state *uts) | 52 | struct test_tee_vars { |
53 | struct tee_shm *reg_shm; | ||
54 | struct tee_shm *alloc_shm; | ||
55 | }; | ||
56 | |||
57 | static int test_tee(struct unit_test_state *uts, struct test_tee_vars *vars) | ||
53 | { | 58 | { |
54 | struct tee_version_data vers; | 59 | struct tee_version_data vers; |
55 | struct udevice *dev; | 60 | struct udevice *dev; |
@@ -57,8 +62,6 @@ static int dm_test_tee(struct unit_test_state *uts) | |||
57 | u32 session = 0; | 62 | u32 session = 0; |
58 | int rc; | 63 | int rc; |
59 | u8 data[128]; | 64 | u8 data[128]; |
60 | struct tee_shm *reg_shm; | ||
61 | struct tee_shm *alloc_shm; | ||
62 | 65 | ||
63 | dev = tee_find_device(NULL, match, NULL, &vers); | 66 | dev = tee_find_device(NULL, match, NULL, &vers); |
64 | ut_assert(dev); | 67 | ut_assert(dev); |
@@ -77,22 +80,36 @@ static int dm_test_tee(struct unit_test_state *uts) | |||
77 | ut_assert(!state->session); | 80 | ut_assert(!state->session); |
78 | 81 | ||
79 | ut_assert(!state->num_shms); | 82 | ut_assert(!state->num_shms); |
80 | rc = tee_shm_register(dev, data, sizeof(data), 0, ®_shm); | 83 | rc = tee_shm_register(dev, data, sizeof(data), 0, &vars->reg_shm); |
81 | ut_assert(!rc); | 84 | ut_assert(!rc); |
82 | ut_assert(state->num_shms == 1); | 85 | ut_assert(state->num_shms == 1); |
83 | 86 | ||
84 | rc = tee_shm_alloc(dev, 256, 0, &alloc_shm); | 87 | rc = tee_shm_alloc(dev, 256, 0, &vars->alloc_shm); |
85 | ut_assert(!rc); | 88 | ut_assert(!rc); |
86 | ut_assert(state->num_shms == 2); | 89 | ut_assert(state->num_shms == 2); |
87 | 90 | ||
88 | ut_assert(tee_shm_is_registered(reg_shm, dev)); | 91 | ut_assert(tee_shm_is_registered(vars->reg_shm, dev)); |
89 | ut_assert(tee_shm_is_registered(alloc_shm, dev)); | 92 | ut_assert(tee_shm_is_registered(vars->alloc_shm, dev)); |
90 | 93 | ||
91 | tee_shm_free(reg_shm); | 94 | tee_shm_free(vars->reg_shm); |
92 | tee_shm_free(alloc_shm); | 95 | vars->reg_shm = NULL; |
96 | tee_shm_free(vars->alloc_shm); | ||
97 | vars->alloc_shm = NULL; | ||
93 | ut_assert(!state->num_shms); | 98 | ut_assert(!state->num_shms); |
94 | 99 | ||
95 | return 0; | 100 | return 0; |
96 | } | 101 | } |
97 | 102 | ||
103 | static int dm_test_tee(struct unit_test_state *uts) | ||
104 | { | ||
105 | struct test_tee_vars vars = { NULL, NULL }; | ||
106 | int rc = test_tee(uts, &vars); | ||
107 | |||
108 | /* In case test_tee() asserts these may still remain allocated */ | ||
109 | tee_shm_free(vars.reg_shm); | ||
110 | tee_shm_free(vars.alloc_shm); | ||
111 | |||
112 | return rc; | ||
113 | } | ||
114 | |||
98 | DM_TEST(dm_test_tee, DM_TESTF_SCAN_FDT); | 115 | DM_TEST(dm_test_tee, DM_TESTF_SCAN_FDT); |