This is an automated email from the ASF dual-hosted git repository.

xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit 8331ae62a83235e2af8783d53f45622a6f3d4c4b
Author: wangjianyu3 <[email protected]>
AuthorDate: Thu Apr 3 12:36:58 2025 +0800

    drivers/sensors/gnss: Protect userlist with upper lock.
    
    gnss_push_data() walked upper->userlist while holding bufferlock,
    but the user list is added to and removed from in gnss_open() and
    gnss_close() under upper->lock, so the walk could race with a user
    being opened or closed.
    
    Release bufferlock after the circular buffer is updated and take
    upper->lock while notifying the users.
    
    Signed-off-by: wangjianyu3 <[email protected]>
---
 drivers/sensors/gnss_uorb.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/sensors/gnss_uorb.c b/drivers/sensors/gnss_uorb.c
index c8cff7c5110..6daaff37cb4 100644
--- a/drivers/sensors/gnss_uorb.c
+++ b/drivers/sensors/gnss_uorb.c
@@ -673,13 +673,15 @@ static void gnss_push_data(FAR void *priv, FAR const void 
*data,
     }
 
   circbuf_overwrite(&upper->buffer, data, bytes);
+  nxmutex_unlock(&upper->bufferlock);
 
+  nxmutex_lock(&upper->lock);
   list_for_every_entry(&upper->userlist, user, struct gnss_user_s, node)
     {
       poll_notify(&user->fds, 1, POLLIN);
     }
 
-  nxmutex_unlock(&upper->bufferlock);
+  nxmutex_unlock(&upper->lock);
 
   nxsem_get_value(&upper->buffersem, &semcount);
   while (semcount++ <= 0)

Reply via email to