Skip to content

Commit e9ea828

Browse files
committed
core: tz avoid memory leak and minor fix
1. Introduce tee_core_free to make it pair with tee_core_alloc: tz_tee_probe may fail, and we need to free resource that requested by tee_core_alloc 2. Correct tz_tee_probe failure handle sequence 3. Move value assign for tee->shm_flags and tee->test to tee_core.c "struct tee" settings should not in tz driver, but in core driver. 4. if sess is NULL, should call tee_put(tee) Signed-off-by: Peng Fan <[email protected]> Reviewed-by: Pascal Brand <[email protected]> Tested-by: Pascal Brand <[email protected]> (QEMU)
1 parent 68aff83 commit e9ea828

File tree

4 files changed

+19
-7
lines changed

4 files changed

+19
-7
lines changed

armtz/tee_tz_drv.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1194,9 +1194,6 @@ static int tz_tee_init(struct platform_device *pdev)
11941194
#endif
11951195
#endif
11961196

1197-
tee->shm_flags = TEEC_MEM_INPUT | TEEC_MEM_OUTPUT;
1198-
tee->test = 0;
1199-
12001197
ptee->started = false;
12011198
ptee->sess_id = 0xAB000000;
12021199
mutex_init(&ptee->mutex);
@@ -1257,11 +1254,11 @@ static int tz_tee_probe(struct platform_device *pdev)
12571254

12581255
ret = tz_tee_init(pdev);
12591256
if (ret)
1260-
goto bail1;
1257+
goto bail0;
12611258

12621259
ret = tee_core_add(tee);
12631260
if (ret)
1264-
goto bail0;
1261+
goto bail1;
12651262

12661263
#ifdef _TEE_DEBUG
12671264
pr_debug("- tee=%p, id=%d, iminor=%d\n", tee, tee->id,
@@ -1272,6 +1269,7 @@ static int tz_tee_probe(struct platform_device *pdev)
12721269
bail1:
12731270
tz_tee_deinit(pdev);
12741271
bail0:
1272+
tee_core_free(tee);
12751273
return ret;
12761274
}
12771275

core/tee_core.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -449,13 +449,25 @@ struct tee *tee_core_alloc(struct device *dev, char *name, int id,
449449
INIT_LIST_HEAD(&tee->list_rpc_shm);
450450

451451
tee->state = TEE_OFFLINE;
452+
tee->shm_flags = TEEC_MEM_INPUT | TEEC_MEM_OUTPUT;
453+
tee->test = 0;
452454

453455
tee_supp_init(tee);
454456

455457
return tee;
456458
}
457459
EXPORT_SYMBOL(tee_core_alloc);
458460

461+
int tee_core_free(struct tee *tee)
462+
{
463+
if (tee) {
464+
tee_supp_deinit(tee);
465+
devm_kfree(tee->dev, tee);
466+
}
467+
return 0;
468+
}
469+
EXPORT_SYMBOL(tee_core_free);
470+
459471
int tee_core_add(struct tee *tee)
460472
{
461473
int rc = 0;
@@ -496,8 +508,6 @@ int tee_core_del(struct tee *tee)
496508
pr_info("TEE Core: Destroy the misc device \"%s\" (id=%d)\n",
497509
dev_name(tee->miscdev.this_device), tee->id);
498510

499-
tee_supp_deinit(tee);
500-
501511
tee_cleanup_sysfs(tee);
502512
tee_delete_debug_dir(tee);
503513

@@ -508,6 +518,8 @@ int tee_core_del(struct tee *tee)
508518
}
509519
}
510520

521+
tee_core_free(tee);
522+
511523
return 0;
512524
}
513525
EXPORT_SYMBOL(tee_core_del);

core/tee_session.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,7 @@ struct tee_session *tee_session_create_and_open(struct tee_context *ctx,
415415
if (!sess) {
416416
dev_err(_DEV(tee), "%s: tee_session allocation() failed\n",
417417
__func__);
418+
tee_put(tee);
418419
return ERR_PTR(-ENOMEM);
419420
}
420421

include/linux/tee_core.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ int tee_core_del(struct tee *tee);
184184

185185
struct tee *tee_core_alloc(struct device *dev, char *name, int id,
186186
const struct tee_ops *ops, size_t len);
187+
int tee_core_free(struct tee *tee);
187188

188189
struct tee_ops {
189190
struct module *owner;

0 commit comments

Comments
 (0)