From 7671ed9615099d629c1b583f6a9f64842413917a Mon Sep 17 00:00:00 2001 From: Zhe Weng Date: Fri, 31 Mar 2023 16:09:37 +0800 Subject: [PATCH] usrsock_server: Raise error earlier for large sendto request It's better to raise error before client sends its (NIOVEC+1)th buffer (and release buffers held by server), otherwise the client may stuck at getting (NIOVEC+1)th tx buffer if NIOVEC is equal to rpmsg buffer num. Signed-off-by: Zhe Weng --- drivers/usrsock/usrsock_rpmsg_server.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/drivers/usrsock/usrsock_rpmsg_server.c b/drivers/usrsock/usrsock_rpmsg_server.c index 9fa81eab77..fd6b6baa6e 100644 --- a/drivers/usrsock/usrsock_rpmsg_server.c +++ b/drivers/usrsock/usrsock_rpmsg_server.c @@ -416,16 +416,19 @@ static int usrsock_rpmsg_sendto_handler(FAR struct rpmsg_endpoint *ept, } } - if (i == CONFIG_NET_USRSOCK_RPMSG_SERVER_NIOVEC) - { - ret = -ENOMEM; - goto out; - } - /* Partial packet ? continue to fetch */ if (priv->remain > 0) { + /* We've used the last I/O vector, cannot continue. */ + + if (i == CONFIG_NET_USRSOCK_RPMSG_SERVER_NIOVEC - 1) + { + nerr("ERROR: Request %d too large!\n", req->usockid); + ret = -ENOMEM; + goto out; + } + return 0; } else if (priv->remain < 0) @@ -461,11 +464,15 @@ static int usrsock_rpmsg_sendto_handler(FAR struct rpmsg_endpoint *ept, priv->remain = sizeof(*req) + req->addrlen + req->buflen - len; if (priv->remain > 0) { +#if CONFIG_NET_USRSOCK_RPMSG_SERVER_NIOVEC >= 2 priv->iov[0].iov_base = data; priv->iov[0].iov_len = len; rpmsg_hold_rx_buffer(ept, data); return 0; +#else + ret = -ENOMEM; +#endif } else {