zhhyu7 opened a new pull request, #21766:
URL: https://github.com/apache/nuttx/pull/21766

   ## Summary
   
   Centralise the lifecycle of `socket_conn_s::s_lock` and fix two call sites   
                                                                                
                                               
   that left the mutex uninitialised.                                           
                                                                                
                                               
                                                      
   - **utils: Add conn_init/conn_uninit and replace direct s_lock ops**    
     Many transport modules initialised `s_lock` by calling                     
                                                                                
                                               
     `nxrmutex_init()/nxrmutex_destroy()` directly, duplicating the same code.
     Add inline `conn_init()/conn_uninit()` helpers in `net/utils/utils.h` and
     use them in can, icmp, icmpv6, local, pkt, tcp, udp and usrsock, so the
     lock lifecycle lives in one place.
   
   - **net/netlink: initialize socket connection in netlink_alloc**
     `netlink_alloc()` returned a connection whose `socket_conn_s` was never
     initialised, so `s_lock` ran as zeroed memory on first use. Initialise it
     with `conn_init()`.
   
   - **nuttx/net: init/uninit s_lock when alloc/free socket_conn_s struct**
     `rpmsg_socket_alloc()/rpmsg_socket_free()` never set up or destroyed
     `s_lock`. Initialise/destroy it with `conn_init()/conn_uninit()`.
   
   This is a refactor plus two lock-initialisation fixes; there is no change in
   external behaviour for connections that were already initialised correctly.
   
   ## Impact
   
   - No API or configuration change. `conn_init()/conn_uninit()` are internal
     inline helpers in `net/utils/utils.h`.
   - netlink and rpmsg sockets now run with a properly initialised `s_lock`
     instead of a zero-initialised mutex.
   
   ## Testing
   
   Built and run on the simulator (flat build) with the network stack enabled.
   
   Build:
   - `./tools/configure.sh sim:dynconns` (TCP, UDP, ICMP, ICMPv6, PKT, LOCAL,
     NETLINK enabled) — `make` completes, `nuttx` links.
   - `./tools/checkpatch.sh -c -m -g HEAD~3..HEAD` — passes for all 3 commits.
   
   Runtime (sim:tcploop config, loopback device, exercises the tcp/udp conn
   alloc + conn_init path):
   
   TCP (tcpclient, TCP loopback over ::1):
   
       nsh> tcpclient
       server: Accepting connections on port 5471
       Connecting to IPv6 Address: ::100
       client: Connected
       server: Connection accepted -- receiving
   
   UDP (loopback datagram over 127.0.0.1):
   
       nsh> ifconfig
       lo  Link encap:Local Loopback at RUNNING mtu 1518
           inet addr:127.0.0.1  Mask:255.0.0.0
       nsh> udploop
       udploop: received 'udp-loopback-hello' (18 bytes) from 127.0.0.1:4758
       udploop: UDP loopback PASS


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to