Skip to content

Commit 5f31876

Browse files
committed
Fixing wrong descriptor reading precedence
1 parent 6017721 commit 5f31876

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

virtio-snd.c

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ typedef struct {
146146
uint32_t chmaps;
147147
} virtio_snd_config_t;
148148

149+
/* VirtIO sound common header */
149150
typedef struct {
150151
uint32_t code;
151152
} virtio_snd_hdr_t;
@@ -400,12 +401,11 @@ static int virtio_snd_desc_handler(virtio_snd_state_t *vsnd,
400401
* maybe wrong. */
401402
/* A full virtio_snd_query_info is composed of 3 descriptors, where
402403
* the first descriptor contains:
403-
* struct virtio_snd_hdr hdr
404+
* struct virtio_snd_hdr hdr (for request)
404405
* the second descriptors contains:
405-
* le32 start_id
406-
* le32 count
406+
* struct virtio_snd_hdr hdr (for response)
407407
* the third descriptors contains:
408-
* le32 size
408+
* (payload)
409409
*/
410410
struct virtq_desc vq_desc[VSND_DESC_CNT];
411411

@@ -434,10 +434,13 @@ static int virtio_snd_desc_handler(virtio_snd_state_t *vsnd,
434434
}
435435

436436
/* Process the header */
437+
const virtio_snd_hdr_t *request =
438+
(virtio_snd_hdr_t *) ((uintptr_t) vsnd->ram + vq_desc[0].addr);
439+
uint32_t type = request->code;
440+
virtio_snd_hdr_t *response =
441+
(virtio_snd_hdr_t *) ((uintptr_t) vsnd->ram + vq_desc[1].addr);
437442
const virtio_snd_query_info_t *query =
438443
(virtio_snd_query_info_t *) ((uintptr_t) vsnd->ram + vq_desc[0].addr);
439-
uint32_t type = query->hdr.code;
440-
uint32_t *status = (uint32_t *) ((uintptr_t) vsnd->ram + vq_desc[2].addr);
441444

442445
/* Process the data */
443446
switch (type) {
@@ -467,14 +470,14 @@ static int virtio_snd_desc_handler(virtio_snd_state_t *vsnd,
467470
break;
468471
default:
469472
fprintf(stderr, "unsupported virtio-snd operation!\n");
470-
*status = VIRTIO_SND_S_NOT_SUPP;
473+
response->code = VIRTIO_SND_S_NOT_SUPP;
471474
*plen = 0;
472475
return -1;
473476
}
474477

475478
/* Return the device status */
476-
*status = VIRTIO_SND_S_OK;
477-
*plen = vq_desc[1].len;
479+
response->code = VIRTIO_SND_S_OK;
480+
*plen = vq_desc[2].len;
478481

479482
return 0;
480483
}

0 commit comments

Comments
 (0)