struct tee_session *tee_session_create_and_open(struct tee_context *ctx, struct tee_cmd_io *cmd_io) { int ret = 0; struct tee_session *sess; struct tee *tee; BUG_ON(!ctx->tee); tee = ctx->tee; dev_dbg(_DEV(tee), "%s: >\n", __func__); ret = tee_get(tee); if (ret) return ERR_PTR(-EBUSY); sess = devm_kzalloc(_DEV(tee), sizeof(struct tee_session), GFP_KERNEL); if (!sess) { dev_err(_DEV(tee), "%s: tee_session allocation() failed\n", __func__); tee_put(tee); return ERR_PTR(-ENOMEM); } tee_context_get(ctx); sess->ctx = ctx; ret = tee_session_open_be(sess, cmd_io); mutex_lock(&tee->lock); if (ret || !sess->sessid || cmd_io->err) { dev_err(_DEV(tee), "%s: ERROR ret=%d (err=0x%08x, org=%d, sessid=0x%08x)\n", __func__, ret, cmd_io->err, cmd_io->origin, sess->sessid); tee_put(tee); tee_context_put(ctx); devm_kfree(_DEV(tee), sess); mutex_unlock(&tee->lock); if (ret) return ERR_PTR(ret); else return NULL; } tee_inc_stats(&tee->stats[TEE_STATS_SESSION_IDX]); list_add_tail(&sess->entry, &ctx->list_sess); mutex_unlock(&tee->lock); dev_dbg(_DEV(tee), "%s: < sess=%p\n", __func__, sess); return sess; }
struct tee_shm *tee_shm_alloc_from_rpc(struct tee *tee, size_t size) { struct tee_shm *shm; INMSG(); shm = tee_shm_alloc(tee, size, TEE_SHM_TEMP | TEE_SHM_FROM_RPC); if (IS_ERR_OR_NULL(shm)) { dev_err(_DEV(tee), "%s: buffer allocation failed (%ld)\n", __func__, PTR_ERR(shm)); goto out; } mutex_lock(&tee->lock); tee_inc_stats(&tee->stats[TEE_STATS_SHM_IDX]); list_add_tail(&shm->entry, &tee->list_rpc_shm); mutex_unlock(&tee->lock); shm->ctx = NULL; out: OUTMSGX(shm); return shm; }