Skip to content

rp1-pio ; head_idx++ is missing. #6919

Closed

Description

@pa3gsb

Title: DMA buffer ring handling broken: head_idx not incremented in rp1_pio_sm_xfer_data()

Description:

There is a critical issue in the rp1_pio_sm_xfer_data() function related to DMA buffer management.

Currently, the function allocates and uses a buffer from the internal DMA ring via:

dbi = &dma->bufs[dma->head_idx % dma->buf_count];

However, after submitting the DMA transfer, the head_idx is never incremented. As a result:

  • Every transfer reuses the same buffer (typically bufs[0]).
  • Only the first transfer works correctly.
  • Subsequent DMA transfers appear to fail silently (or overwrite data in-flight).
  • The buf_sem semaphore eventually blocks further transfers, since the ring never advances.

This breaks multi-buffer DMA handling and causes subtle data loss and transfer hangs.


Suggested Fix:

Increment head_idx after a successful DMA submission:

ret = dmaengine_submit(desc);
if (ret < 0) {
    dev_err(dev, "dmaengine_submit failed (%d)\n", ret);
    return ret;
}

dma_async_issue_pending(dma->chan);

/* Add this line to advance the ring */
dma->head_idx++;

return 0;

The corresponding tail_idx++ already occurs in the DMA completion callback, so this fix restores proper ring behavior.


Impact:

This bug causes:

  • DMA transfers after the first one to fail silently.
  • Potential data corruption due to buffer reuse.
  • System hangs if the ring fills and buffers never recycle.

Steps to reproduce the behaviour

just analyze the code ; the callback is doing the tail_idx++ but for the head no increase is done.

i tried to use my driver wich includes the rp1-pio driver with a ping pong buffer scenario and reading data from the second buffer results in 0 reads.

Device (s)

Raspberry Pi 5

System

latest

Logs

no logs

Additional context

No response

Activity

  1. pelwell commented on Jun 23, 2025

    @pelwell
    Contributor

    Hmm, yes. The in-kernel API has been barely used, so I'm disappointed but not hugely surprised. I'll take a look at the rest of the code in this area, but a fix will be merged ASAP.

  2. pa3gsb commented on Jun 23, 2025

    @pa3gsb
    Author

    I understand; no problem. I did the change and my ping-pong dma transfer started to work.

    Nice you are so quick in responding and willing to update the code.

    Really appreciated.

  3. pelwell commented on Jun 23, 2025

    @pelwell
    Contributor

    There - I think that should be fixed now. If you wait about 40 minutes for these autobuilds (https://github.com/raspberrypi/linux/actions/runs/15826180099) to complete, you should be able to install a trial build using sudo rpi-update rpi-6.12.y.

    Thanks for the clear bug report - I'll take a look at your piolib API issue next.

  4. pa3gsb commented on Jun 23, 2025

    @pa3gsb
    Author

    This works for me. Tnx.

  5. 160 remaining items

  6. added a commit that references this issue on Nov 1, 2026
  7. added a commit that references this issue on Nov 4, 2026
  8. added a commit that references this issue on Nov 13, 2026
  9. added a commit that references this issue on Nov 16, 2026
  10. added a commit that references this issue on Nov 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions