2828 */
2929int tee_context_dump (struct tee * tee , char * buff , size_t len )
3030{
31- struct list_head * ptrCtx , * ptrSess , * ptrShm ;
31+ struct list_head * ptr_ctx , * ptr_sess , * ptr_shm ;
3232 struct tee_context * ctx ;
3333 struct tee_session * sess ;
3434 struct tee_shm * shm ;
@@ -39,74 +39,75 @@ int tee_context_dump(struct tee *tee, char *buff, size_t len)
3939
4040 BUG_ON (!tee );
4141
42- if (len < 80 )
42+ if (len < 80 || list_empty ( & tee -> list_ctx ) )
4343 return 0 ;
4444
4545 mutex_lock (& tee -> lock );
46- if (!list_empty (& tee -> list_ctx )) {
47- list_for_each (ptrCtx , & tee -> list_ctx ) {
48- ctx = list_entry (ptrCtx , struct tee_context , entry );
46+
47+ list_for_each (ptr_ctx , & tee -> list_ctx ) {
48+ ctx = list_entry (ptr_ctx , struct tee_context , entry );
49+
50+ pos += sprintf (buff + pos ,
51+ "[%02d] ctx=%p (refcount=%d) (usr=%d)" ,
52+ i , ctx ,
53+ (int )atomic_read (& ctx -> refcount .
54+ refcount ),
55+ ctx -> usr_client );
56+ pos += sprintf (buff + pos , "name=\"%s\" (tgid=%d)\n" ,
57+ ctx -> name ,
58+ ctx -> tgid );
59+ if ((len - pos ) < 80 ) {
60+ pos = 0 ;
61+ goto out ;
62+ }
63+
64+ if (list_empty (& ctx -> list_sess ))
65+ goto out ;
66+
67+ j = 0 ;
68+ list_for_each (ptr_sess , & ctx -> list_sess ) {
69+ sess = list_entry (ptr_sess ,
70+ struct tee_session ,
71+ entry );
4972
5073 pos += sprintf (buff + pos ,
51- "[%02d] ctx=%p (refcount=%d) (usr=%d) "
52- "name=\"%s\" (tgid=%d)\n" ,
53- i , ctx ,
54- (int )atomic_read (& ctx -> refcount .
55- refcount ),
56- ctx -> usr_client , ctx -> name , ctx -> tgid );
74+ "[%02d.%d] sess=%p sessid=%08x\n" ,
75+ i , j , sess ,
76+ sess -> sessid );
5777
5878 if ((len - pos ) < 80 ) {
5979 pos = 0 ;
6080 goto out ;
6181 }
6282
63- j = 0 ;
64- if (!list_empty (& ctx -> list_sess )) {
65- list_for_each (ptrSess , & ctx -> list_sess ) {
66- sess = list_entry (ptrSess ,
67- struct tee_session ,
68- entry );
69-
70- pos += sprintf (buff + pos ,
71- " [%02d.%d] sess=%p sessid=%08x\n" ,
72- i , j , sess ,
73- sess -> sessid );
74-
75- if ((len - pos ) < 80 ) {
76- pos = 0 ;
77- goto out ;
78- }
79-
80- j ++ ;
81- }
82- }
83+ j ++ ;
84+ }
85+
86+ if (list_empty (& ctx -> list_shm ))
87+ goto out ;
88+
89+ j = 0 ;
90+ list_for_each (ptr_shm , & ctx -> list_shm ) {
91+ shm = list_entry (ptr_shm , struct tee_shm , entry );
8392
84- j = 0 ;
85- if (!list_empty (& ctx -> list_shm )) {
86- list_for_each (ptrShm , & ctx -> list_shm ) {
87- shm =
88- list_entry (ptrShm , struct tee_shm ,
89- entry );
90-
91- pos += sprintf (buff + pos ,
92- " [%02d.%d] shm=%p paddr=%pad "
93- "kaddr=%p s=%zu(%zu)\n" ,
94- i , j , shm ,
95- & shm -> paddr ,
96- shm -> kaddr ,
97- shm -> size_req ,
98- shm -> size_alloc );
99-
100- if ((len - pos ) < 80 ) {
101- pos = 0 ;
102- goto out ;
103- }
104-
105- j ++ ;
106- }
93+ pos += sprintf (buff + pos ,
94+ "[%02d.%d] shm=%p paddr=%p kaddr=%p" ,
95+ i , j , shm ,
96+ & shm -> paddr ,
97+ shm -> kaddr );
98+ pos += sprintf (buff + pos ,
99+ " s=%zu(%zu)\n" ,
100+ shm -> size_req ,
101+ shm -> size_alloc );
102+ if ((len - pos ) < 80 ) {
103+ pos = 0 ;
104+ goto out ;
107105 }
108- i ++ ;
106+
107+ j ++ ;
109108 }
109+
110+ i ++ ;
110111 }
111112
112113out :
@@ -200,6 +201,7 @@ void tee_context_get(struct tee_context *ctx)
200201static int is_in_list (struct tee * tee , struct list_head * entry )
201202{
202203 int present = 1 ;
204+
203205 mutex_lock (& tee -> lock );
204206 if ((entry -> next == LIST_POISON1 ) && (entry -> prev == LIST_POISON2 ))
205207 present = 0 ;
@@ -216,6 +218,7 @@ void tee_context_put(struct tee_context *ctx)
216218{
217219 struct tee_context * _ctx = ctx ;
218220 struct tee * tee ;
221+
219222 BUG_ON (!ctx || !ctx -> tee );
220223 tee = ctx -> tee ;
221224
@@ -249,6 +252,7 @@ int tee_context_copy_from_client(const struct tee_context *ctx,
249252 void * dest , const void * src , size_t size )
250253{
251254 int res = 0 ;
255+
252256 if (dest && src && (size > 0 )) {
253257 if (ctx -> usr_client )
254258 res = copy_from_user (dest , src , size );
@@ -259,22 +263,25 @@ int tee_context_copy_from_client(const struct tee_context *ctx,
259263}
260264
261265struct tee_shm * tee_context_alloc_shm_tmp (struct tee_context * ctx ,
262- size_t size , const void * data ,
266+ size_t size , const void * src ,
263267 int type )
264268{
265269 struct tee_shm * shm ;
266270
267271 type &= (TEEC_MEM_INPUT | TEEC_MEM_OUTPUT );
268272
269- shm = tee_shm_alloc (ctx , size , TEE_SHM_MAPPED | TEE_SHM_TEMP | type );
273+ shm = tee_shm_alloc (ctx -> tee , size ,
274+ TEE_SHM_MAPPED | TEE_SHM_TEMP | type );
270275 if (IS_ERR_OR_NULL (shm )) {
271276 dev_err (_DEV (ctx -> tee ), "%s: buffer allocation failed (%ld)\n" ,
272277 __func__ , PTR_ERR (shm ));
273278 return shm ;
274279 }
275280
276- if (shm && (type & TEEC_MEM_INPUT )) {
277- if (tee_context_copy_from_client (ctx , shm -> kaddr , data , size )) {
281+ shm -> ctx = ctx ;
282+
283+ if (type & TEEC_MEM_INPUT ) {
284+ if (tee_context_copy_from_client (ctx , shm -> kaddr , src , size )) {
278285 dev_err (_DEV (ctx -> tee ),
279286 "%s: tee_context_copy_from_client failed\n" ,
280287 __func__ );
0 commit comments