From 61d93943663fbba511ac9296a29d08ee016e67eb Mon Sep 17 00:00:00 2001 From: Xiang Xiao Date: Wed, 28 Feb 2024 14:05:59 +0800 Subject: [PATCH] net/local: Add local_freectl to avoid the code duplicaton Signed-off-by: Xiang Xiao --- net/local/local_sendmsg.c | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/net/local/local_sendmsg.c b/net/local/local_sendmsg.c index f0b999614a..748c93da9e 100644 --- a/net/local/local_sendmsg.c +++ b/net/local/local_sendmsg.c @@ -58,6 +58,18 @@ ****************************************************************************/ #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, FAR struct msghdr *msg) { @@ -71,7 +83,6 @@ static int local_sendctl(FAR struct local_conn_s *conn, int i = 0; net_lock(); - peer = conn->lc_peer; if (peer == NULL) { @@ -124,19 +135,11 @@ static int local_sendctl(FAR struct local_conn_s *conn, } net_unlock(); - return count; fail: - while (i-- > 0) - { - file_close(peer->lc_cfps[--peer->lc_cfpcount]); - kmm_free(peer->lc_cfps[peer->lc_cfpcount]); - peer->lc_cfps[peer->lc_cfpcount] = NULL; - } - + local_freectl(conn, i); net_unlock(); - return ret; } #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) { net_lock(); - - 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; - } - + local_freectl(conn, count); net_unlock(); } #endif