+ for (i = 0; i < nr; i++) {
+ /* Detach the ith request from the vq */
+ req = virtqueue_get_buf(vq, &len);
+
+ /*
+ * Condition (req && req == &reqs[i]) should always meet since
+ * we have total nr requests in the vq.
So this assumes the requests are completed in order. Is this mandated in the spec?
We have discussed this before in v6. https://lists.linuxfoundation.org/pipermail/virtualization/2021-March/053093.html.+ */
+ if (!failed && (WARN_ON(!(req && req == &reqs[i])) ||
+ (req->in_hdr.status != VIRTIO_I2C_MSG_OK)))
+ failed = true;
+
+ i2c_put_dma_safe_msg_buf(reqs[i].buf, &msgs[i], !failed);
+ if (!failed)
+ ++j;
+ }
+
+ return (timeout ? -ETIMEDOUT : j);
Checking timeout is fragile, what happens if the request are completed after wait_for_completion() but before virtio_i2c_complete_reqs()?