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

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

commit 28e628f0b4053c887dbe1c72fa2986b8d839dbcc
Author: fangyibo <[email protected]>
AuthorDate: Tue Aug 4 14:08:29 2026 +0800

    audio: limit the buffer count guard to shared ring requests
    
    The upper->periods >= upper->nbuffers check sat at the top of
    audio_allocbuffer(), but upper->periods is only incremented for shared
    ring requests (u.pbuffer == NULL), so for private buffer callers the
    check degenerated into "nbuffers == 0" and rejected every allocation
    when the lower half does not implement AUDIOIOC_GETBUFFERINFO, which is
    the only place nbuffers is ever assigned.
    
    Move the guard inside the shared ring branch so private buffers, which
    never enter upper->apbs[] and are unrelated to the ring depth, stay
    allocatable. The zero return value is kept as-is because a second
    application attaching to the same device relies on it to skip
    allocation and go straight to AUDIOIOC_ENQUEUEBUFFER.
    
    Signed-off-by: fangyibo <[email protected]>
---
 audio/audio.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/audio/audio.c b/audio/audio.c
index 8ae1a1764c9..74229873b59 100644
--- a/audio/audio.c
+++ b/audio/audio.c
@@ -769,13 +769,13 @@ static int audio_allocbuffer(FAR struct audio_upperhalf_s 
*upper,
   FAR void *newaddr;
   int ret;
 
-  if (upper->periods >= upper->nbuffers)
-    {
-      return 0;
-    }
-
   if (bufdesc->u.pbuffer == NULL)
     {
+      if (upper->periods >= upper->nbuffers)
+        {
+          return 0;
+        }
+
       bufdesc->u.pbuffer = &apb;
       share = true;
     }

Reply via email to