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 9155f08c149f2e6add4a72a94e70e5b140ac3baa
Author: yukangzhi <[email protected]>
AuthorDate: Thu Jun 19 18:20:59 2025 +0800

    drivers/note: Fix data address alignment trap cause by sched_note_add.
    
    Solve the problem of address misalignment exception triggered
    when sched_note_add parses note data.
    
    Assisted-by: Kiro:claude-opus-5-5
    Signed-off-by: yukangzhi <[email protected]>
---
 drivers/note/note_driver.c      | 8 ++++++--
 drivers/note/noterpmsg_driver.c | 6 +++---
 2 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/drivers/note/note_driver.c b/drivers/note/note_driver.c
index bf6af9c7337..007034ee13e 100644
--- a/drivers/note/note_driver.c
+++ b/drivers/note/note_driver.c
@@ -628,8 +628,12 @@ void sched_note_add(FAR const void *data, size_t len)
           note_add(*driver, note, notelen);
         }
 
-      data = (FAR void *)((uintptr_t)data + notelen);
-      len -= notelen;
+      /* The note data from note rpmsg is aligned. When parsing
+       * the data, it is necessary to align the notelen.
+       */
+
+      data = (FAR void *)((uintptr_t)data + NOTE_ALIGN(notelen));
+      len -= NOTE_ALIGN(notelen);
     }
 }
 #endif
diff --git a/drivers/note/noterpmsg_driver.c b/drivers/note/noterpmsg_driver.c
index 414ebfa3e5d..d9b6b779590 100644
--- a/drivers/note/noterpmsg_driver.c
+++ b/drivers/note/noterpmsg_driver.c
@@ -202,7 +202,7 @@ static void noterpmsg_add(FAR struct note_driver_s *driver,
   flags = spin_lock_irqsave_notrace(&drv->lock);
 
   space = CONFIG_DRIVERS_NOTERPMSG_BUFSIZE - noterpmsg_length(drv);
-  if (space < notelen)
+  if (space < NOTE_ALIGN(notelen))
     {
       if (!up_interrupt_context() && !sched_idletask())
         {
@@ -218,7 +218,7 @@ static void noterpmsg_add(FAR struct note_driver_s *driver,
               space = CONFIG_DRIVERS_NOTERPMSG_BUFSIZE -
                       noterpmsg_length(drv);
             }
-          while (space < notelen);
+          while (space < NOTE_ALIGN(notelen));
         }
     }
 
@@ -228,7 +228,7 @@ static void noterpmsg_add(FAR struct note_driver_s *driver,
   memcpy(drv->buffer + drv->head, note, space);
   memcpy(drv->buffer, note + space, notelen - space);
 
-  drv->head = noterpmsg_next(drv, drv->head, notelen);
+  drv->head = noterpmsg_next(drv, drv->head, NOTE_ALIGN(notelen));
 
   if (work_available(&drv->work))
     {

Reply via email to