Skip to content

virtio-snd: implement queue function lookup table - #120

Merged
jserv merged 1 commit into
sysprog21:masterfrom
Cuda-Chen:add-q-func-tbl
Jan 3, 2026
Merged

jserv merged 1 commit into
sysprog21:masterfrom
Cuda-Chen:add-q-func-tbl

Conversation

@Cuda-Chen

@Cuda-Chen Cuda-Chen commented Jan 2, 2026

Copy link
Copy Markdown
Collaborator

Introduce a function lookup table to handle virtio-snd queues. This
prepares the device for upcoming PCM I/O receive and event features
by allowing queue ID indexing for callbacks.

  • Set unimplemented PCM I/O receive and event entries to trigger a
    failed null check.
  • Set control and event queue flush entries to trigger a failed null
    check as flushing is not required for these queues.

Summary by cubic

Added a queue operation lookup table for virtio-snd. Notify events now use the queue ID with an optional flush flag to select handlers, paving the way for PCM RX and event support.

  • Refactors

    • Centralized virtio_queue_notify_handler to index handlers; removed the callback parameter.
    • Replaced macro-generated TX handlers with a shared body and two explicit handlers (normal, flush).
    • Uses index & 0x03 for queue selection; operations picked from a small table (0–3 normal, 4–7 flush).
  • New Features

    • Flush routing via bit 0x04 in the index.
    • RX and event ops set to NULL to trigger a failed null check until implemented.
    • Control and event flush entries set to NULL to trigger a failed null check (flushing not required).

Written for commit 7afe818. Summary will update on new commits.

@Cuda-Chen
Cuda-Chen marked this pull request as ready for review January 2, 2026 09:13

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3 issues found across 1 file

Prompt for AI agents (all issues)

Check if these issues are valid — if so, understand the root cause of each and fix them.


<file name="virtio-snd.c">

<violation number="1" location="virtio-snd.c:935">
P3: Typo in comment: &#39;opration&#39; should be &#39;operation&#39;.</violation>

<violation number="2" location="virtio-snd.c:949">
P3: Typos in comment: &#39;whcih&#39; should be &#39;which&#39; and &#39;net&#39; should be &#39;not&#39;.</violation>

<violation number="3" location="virtio-snd.c:1026">
P1: Potential out-of-bounds array access: `index` is masked with `&amp; 0x03` for queue selection but used directly for table lookup. If `index &gt;= 8`, this causes undefined behavior. Consider adding bounds checking: `__virtio_snd_queue_op_tbl[index &amp; 0x07]` to match the design pattern.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Comment thread virtio-snd.c Outdated
Comment thread virtio-snd.c Outdated
Comment thread virtio-snd.c Outdated
Comment thread virtio-snd.c Outdated
Comment thread virtio-snd.c Outdated
Comment thread virtio-snd.c Outdated
Comment thread virtio-snd.c Outdated
@Cuda-Chen
Cuda-Chen force-pushed the add-q-func-tbl branch 2 times, most recently from 615220e to 329037e Compare January 3, 2026 06:07
@Cuda-Chen
Cuda-Chen requested a review from jserv January 3, 2026 06:30
@sysprog21 sysprog21 deleted a comment from cubic-dev-ai Bot Jan 3, 2026
cubic-dev-ai[bot]

This comment was marked as resolved.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 1 file

Prompt for AI agents (all issues)

Check if these issues are valid — if so, understand the root cause of each and fix them.


<file name="virtio-snd.c">

<violation number="1" location="virtio-snd.c:1014">
P1: Potential NULL pointer dereference: the lookup table contains NULL entries but there&#39;s no NULL check before calling the function pointer. If `index &amp; 0x07` evaluates to 1, 3, 4, 5, or 7, this will crash. The comment about &#39;trigger a compilation error&#39; is incorrect - NULL entries compile fine but crash at runtime.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Comment thread virtio-snd.c Outdated
@sysprog21 sysprog21 deleted a comment from cubic-dev-ai Bot Jan 3, 2026
Introduce a function lookup table to handle virtio-snd queues. This
prepares the device for upcoming PCM I/O receive and event features
by allowing queue ID indexing for callbacks.

- Set unimplemented PCM I/O receive and event entries to trigger a
  failed null check.
- Set control and event queue flush entries to trigger a failed null
  check as flushing is not required for these queues.
@jserv
jserv merged commit 2d6ca4e into sysprog21:master Jan 3, 2026
5 checks passed
@jserv

jserv commented Jan 3, 2026

Copy link
Copy Markdown
Collaborator

Thank @Cuda-Chen for contributing!

@Cuda-Chen
Cuda-Chen deleted the add-q-func-tbl branch January 4, 2026 00:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants