net/local: Add local_freectl to avoid the code duplicaton

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
This commit is contained in:
Xiang Xiao 2024-02-28 14:05:59 +08:00 committed by Alan Carvalho de Assis
parent c7a513b182
commit 61d9394366

View File

@ -58,6 +58,18 @@
****************************************************************************/ ****************************************************************************/
#ifdef CONFIG_NET_LOCAL_SCM #ifdef CONFIG_NET_LOCAL_SCM
static void local_freectl(FAR struct local_conn_s *conn, int count)
{
FAR struct local_conn_s *peer = conn->lc_peer;
while (count-- > 0)
{
file_close(peer->lc_cfps[--peer->lc_cfpcount]);
kmm_free(peer->lc_cfps[peer->lc_cfpcount]);
peer->lc_cfps[peer->lc_cfpcount] = NULL;
}
}
static int local_sendctl(FAR struct local_conn_s *conn, static int local_sendctl(FAR struct local_conn_s *conn,
FAR struct msghdr *msg) FAR struct msghdr *msg)
{ {
@ -71,7 +83,6 @@ static int local_sendctl(FAR struct local_conn_s *conn,
int i = 0; int i = 0;
net_lock(); net_lock();
peer = conn->lc_peer; peer = conn->lc_peer;
if (peer == NULL) if (peer == NULL)
{ {
@ -124,19 +135,11 @@ static int local_sendctl(FAR struct local_conn_s *conn,
} }
net_unlock(); net_unlock();
return count; return count;
fail: fail:
while (i-- > 0) local_freectl(conn, i);
{
file_close(peer->lc_cfps[--peer->lc_cfpcount]);
kmm_free(peer->lc_cfps[peer->lc_cfpcount]);
peer->lc_cfps[peer->lc_cfpcount] = NULL;
}
net_unlock(); net_unlock();
return ret; return ret;
} }
#endif /* CONFIG_NET_LOCAL_SCM */ #endif /* CONFIG_NET_LOCAL_SCM */
@ -423,14 +426,7 @@ ssize_t local_sendmsg(FAR struct socket *psock, FAR struct msghdr *msg,
if (len < 0 && count > 0) if (len < 0 && count > 0)
{ {
net_lock(); net_lock();
local_freectl(conn, count);
while (count-- > 0)
{
file_close(conn->lc_cfps[--conn->lc_cfpcount]);
kmm_free(conn->lc_cfps[conn->lc_cfpcount]);
conn->lc_cfps[conn->lc_cfpcount] = NULL;
}
net_unlock(); net_unlock();
} }
#endif #endif