Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 7e7af59

Browse files
authored
Merge pull request #73 from Cuda-Chen/rectify-vsnd-desc
Rectify accessing virtq struct members
2 parents b42df15 + d4a3e30 commit 7e7af59

File tree

1 file changed

+18
-16
lines changed

1 file changed

+18
-16
lines changed

‎virtio-snd.c

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -696,10 +696,10 @@ static void virtio_snd_cb(struct CNFADriver *dev,
696696
}
697697

698698
#define VSND_DESC_CNT 3
699-
static int virtio_snd_desc_handler(virtio_snd_state_t *vsnd,
700-
const virtio_snd_queue_t *queue,
701-
uint32_t desc_idx,
702-
uint32_t *plen)
699+
static int virtio_snd_ctrl_desc_handler(virtio_snd_state_t *vsnd,
700+
const virtio_snd_queue_t *queue,
701+
uint32_t desc_idx,
702+
uint32_t *plen)
703703
{
704704
/* A control message uses at most 3 virtqueue descriptors, where
705705
* the first descriptor contains:
@@ -713,13 +713,14 @@ static int virtio_snd_desc_handler(virtio_snd_state_t *vsnd,
713713
/* Collect the descriptors */
714714
for (int i = 0; i < VSND_DESC_CNT; i++) {
715715
/* The size of the `struct virtq_desc` is 4 words */
716-
const uint32_t *desc = &vsnd->ram[queue->QueueDesc + desc_idx * 4];
716+
const struct virtq_desc *desc =
717+
(struct virtq_desc *) &vsnd->ram[queue->QueueDesc + desc_idx * 4];
717718

718719
/* Retrieve the fields of current descriptor */
719-
vq_desc[i].addr = desc[0];
720-
vq_desc[i].len = desc[2];
721-
vq_desc[i].flags = desc[3];
722-
desc_idx = desc[3] >> 16; /* vq_desc[desc_cnt].next */
720+
vq_desc[i].addr = desc->addr;
721+
vq_desc[i].len = desc->len;
722+
vq_desc[i].flags = desc->flags;
723+
desc_idx = desc->next;
723724

724725
/* Leave the loop if next-flag is not set */
725726
if (!(vq_desc[i].flags & VIRTIO_DESC_F_NEXT))
@@ -836,20 +837,21 @@ static int virtio_snd_tx_desc_handler(virtio_snd_state_t *vsnd,
836837
int cnt = 0;
837838
for (;;) {
838839
/* The size of the `struct virtq_desc` is 4 words */
839-
const uint32_t *desc = &vsnd->ram[queue->QueueDesc + desc_idx * 4];
840+
const struct virtq_desc *desc =
841+
(struct virtq_desc *) &vsnd->ram[queue->QueueDesc + desc_idx * 4];
840842

841843
/* Retrieve the fields of current descriptor */
842844
node = (virtq_desc_queue_node_t *) malloc(sizeof(*node));
843-
node->vq_desc.addr = desc[0];
844-
node->vq_desc.len = desc[2];
845-
node->vq_desc.flags = desc[3];
845+
node->vq_desc.addr = desc->addr;
846+
node->vq_desc.len = desc->len;
847+
node->vq_desc.flags = desc->flags;
846848
list_push(&node->q, &q);
847-
desc_idx = desc[3] >> 16; /* vq_desc[desc_cnt].next */
849+
desc_idx = desc->next;
848850

849851
cnt++;
850852

851853
/* Leave the loop if next-flag is not set */
852-
if (!(desc[3] & VIRTIO_DESC_F_NEXT))
854+
if (!(desc->flags & VIRTIO_DESC_F_NEXT))
853855
break;
854856
}
855857

@@ -1088,7 +1090,7 @@ static bool virtio_snd_reg_write(virtio_snd_state_t *vsnd,
10881090
switch (value) {
10891091
case VSND_QUEUE_CTRL:
10901092
virtio_queue_notify_handler(vsnd, value,
1091-
virtio_snd_desc_handler);
1093+
virtio_snd_ctrl_desc_handler);
10921094
break;
10931095
case VSND_QUEUE_TX:
10941096
tx_ev_notify++;

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /