split-ring: fix inverted empty-ring checks in receiving used buffers note
PATCH 1/1 split-ring: fix inverted empty-ring checks in receiving used buffers note
In the Receiving Used Buffers From The Device polling example, both comparisons check vq->last_seen_used != le16_to_cpu(virtq->used.idx) instead of ==. When unconsumed used buffers are present (last_seen_used != used->idx), the loop immediately enables notifications and breaks without processing any buffer; when the used ring is empty (last_seen_used == used->idx), the loop skips the re-enable/break block and reads past used->idx. The snippet also mixes virtq->used.idx with virtq.used->ring[...] and omits the & address-of operator when initializing struct virtq_used_elem *e.
Replace both != checks with ==, use consistent virtq->used-> member access, and take the address &virtq->used->ring[...].
--- split-ring.tex | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
split-ring.tex +3 -3
@@ -718,17 +718,17 @@ \subsection{Receiving Used Buffers From The Device}\label{sec:Basic Facilities o virtq_disable_used_buffer_notifications(vq); for (;;) { - if (vq->last_seen_used != le16_to_cpu(virtq->used.idx)) { + if (vq->last_seen_used == le16_to_cpu(virtq->used->idx)) { virtq_enable_used_buffer_notifications(vq); mb(); - if (vq->last_seen_used != le16_to_cpu(virtq->used.idx)) + if (vq->last_seen_used == le16_to_cpu(virtq->used->idx)) break; virtq_disable_used_buffer_notifications(vq); } - struct virtq_used_elem *e = virtq.used->ring[vq->last_seen_used%vsz]; + struct virtq_used_elem *e = &virtq->used->ring[vq->last_seen_used%vsz]; process_buffer(e); vq->last_seen_used++; }
Signature · 1 line
2.56.1.809.ga0b61035b5-goog