nuttx/net/local
dongjiuzhu1 d1bc2800e3 net/local: simplify file descriptor passing using shared filep references
This commit removes unnecessary file duplication and memory allocation when
passing file descriptors through Unix domain sockets, leveraging the new
filep reference counting framework.

Background:
With the new filep framework, file structures (filep) can be safely shared
across processes using reference counting. When passing file descriptors
through SCM_RIGHTS control messages on local sockets, the previous
implementation unnecessarily duplicated the entire file structure.

Changes:

1. In local_sendctl() (sender side):
   - Removed allocation of filep2 structure (kmm_zalloc)
   - Removed file_dup2() call that copied the file structure
   - Now directly stores the original filep with its reference count
   - Eliminates memory allocation overhead and potential failure points

2. In local_recvctl() (receiver side):
   - Changed from file_close() + kmm_free() to file_put()
   - file_put() properly decrements reference count and handles cleanup
   - Consistent with the new filep reference counting model

3. In local_freectl() (cleanup on error):
   - Changed from file_close() + kmm_free() to file_put()
   - Ensures proper reference count management during error paths

Technical Details:
The new filep framework ensures that:
- Multiple file descriptors across different processes can reference the
  same underlying filep structure safely
- Reference counting (via file_get/file_put) manages lifetime correctly
- The underlying file object is only released when all references are gone

This change is safe because file_dup() in the receiver already calls
file_get() internally to increment the reference count for the new fd,
so the filep remains valid after the sender calls file_put().

Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2025-12-31 02:29:46 +08:00
..
CMakeLists.txt net: migrate to SPDX identifier 2024-09-12 01:08:11 +08:00
Kconfig net/local: rename NET_LOCAL_VFS_PATH to follow linux 2023-01-04 20:50:38 +08:00
local.h Remove duplicate includes across multiple files 2025-01-09 23:30:23 +08:00
local_accept.c style: fix spelling in code comments and strings 2025-05-23 10:48:41 +08:00
local_bind.c net: migrate to SPDX identifier 2024-09-12 01:08:11 +08:00
local_conn.c style: fix spelling in code comments and strings 2025-05-23 10:48:41 +08:00
local_connect.c net/local: fix the return address is incorrect when accept 2024-10-11 01:31:20 +08:00
local_fifo.c net/local: fix the return address is incorrect when accept 2024-10-11 01:31:20 +08:00
local_listen.c net: migrate to SPDX identifier 2024-09-12 01:08:11 +08:00
local_netpoll.c net: migrate to SPDX identifier 2024-09-12 01:08:11 +08:00
local_recvmsg.c net/local: simplify file descriptor passing using shared filep references 2025-12-31 02:29:46 +08:00
local_recvutils.c net: migrate to SPDX identifier 2024-09-12 01:08:11 +08:00
local_release.c local_sock: fix accept use-after-free 2024-10-09 18:16:01 +08:00
local_sendmsg.c net/local: simplify file descriptor passing using shared filep references 2025-12-31 02:29:46 +08:00
local_sendpacket.c net: migrate to SPDX identifier 2024-09-12 01:08:11 +08:00
local_sockif.c net/ioctl: add a socket interface for ioctl 2025-12-29 14:38:15 +08:00
Make.defs net: migrate to SPDX identifier 2024-09-12 01:08:11 +08:00