diff --git a/drivers/note/note_driver.c b/drivers/note/note_driver.c index 70c8c2dd03..a710c4ee0f 100644 --- a/drivers/note/note_driver.c +++ b/drivers/note/note_driver.c @@ -585,10 +585,10 @@ static void note_record_taskname(pid_t pid, FAR const char *name) ti = (FAR struct note_taskname_info_s *) &g_note_taskname.buffer[g_note_taskname.head]; - ti->size = tilen; + ti->size = NOTE_ALIGN(tilen); ti->pid = pid; strlcpy(ti->name, name, namelen + 1); - g_note_taskname.head += tilen; + g_note_taskname.head += ti->size; } #endif diff --git a/drivers/note/noteram_driver.c b/drivers/note/noteram_driver.c index f6db8ee064..edd84d84a9 100644 --- a/drivers/note/noteram_driver.c +++ b/drivers/note/noteram_driver.c @@ -295,7 +295,7 @@ static void noteram_remove(FAR struct noteram_driver_s *drv) /* Get the length of the note at the tail index */ - length = drv->ni_buffer[tail]; + length = NOTE_ALIGN(drv->ni_buffer[tail]); DEBUGASSERT(length <= noteram_length(drv)); /* Increment the tail index to remove the entire note from the circular @@ -387,7 +387,7 @@ static ssize_t noteram_get(FAR struct noteram_driver_s *drv, remaining--; } - drv->ni_read = read; + drv->ni_read = NOTE_ALIGN(read); return notelen; } @@ -594,7 +594,7 @@ static void noteram_add(FAR struct note_driver_s *driver, space = space < notelen ? space : notelen; memcpy(drv->ni_buffer + head, note, space); memcpy(drv->ni_buffer, buf + space, notelen - space); - drv->ni_head = noteram_next(drv, head, notelen); + drv->ni_head = noteram_next(drv, head, NOTE_ALIGN(notelen)); spin_unlock_irqrestore_wo_note(&drv->lock, flags); } diff --git a/include/nuttx/sched_note.h b/include/nuttx/sched_note.h index eb0ce3d804..60063f2eac 100644 --- a/include/nuttx/sched_note.h +++ b/include/nuttx/sched_note.h @@ -51,6 +51,9 @@ * Pre-processor Definitions ****************************************************************************/ +#define NOTE_ALIGN(a) (((a) + sizeof(uintptr_t) - 1) & \ + ~(sizeof(uintptr_t) - 1)) + /* Provide defaults for some configuration settings (could be undefined with * old configuration files) */