drivers/optee: Return error if optee_recv return prematurely

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
This commit is contained in:
Xiang Xiao 2023-10-23 08:24:38 +08:00 committed by Xiang Xiao
parent a074a572af
commit 7b2dbcf50a

View file

@ -291,24 +291,21 @@ static int optee_from_msg_param(FAR struct tee_ioctl_param *params,
return 0; return 0;
} }
static ssize_t optee_recv(FAR struct socket *psock, FAR void *msg, static int optee_recv(FAR struct socket *psock, FAR void *msg, size_t size)
size_t size)
{ {
size_t remain = size; while (size > 0)
while (remain)
{ {
ssize_t n = psock_recv(psock, msg, remain, 0); ssize_t n = psock_recv(psock, msg, size, 0);
if (n <= 0) if (n <= 0)
{ {
return remain == size ? n : size - remain; return n < 0 ? n : -EIO;
} }
remain -= n; size -= n;
msg = (FAR char *)msg + n; msg = (FAR char *)msg + n;
} }
return size; return 0;
} }
static int optee_send_recv(FAR struct socket *psocket, static int optee_send_recv(FAR struct socket *psocket,