Skip to content

Commit 1ad9a48

Browse files
committed
Set response length for VirtIO notification
1 parent 60b6362 commit 1ad9a48

File tree

1 file changed

+23
-13
lines changed

1 file changed

+23
-13
lines changed

virtio-snd.c

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -307,10 +307,12 @@ static void virtio_snd_update_status(virtio_snd_state_t *vsnd, uint32_t status)
307307

308308
static void virtio_snd_read_jack_info_handler(
309309
virtio_snd_jack_info_t *info,
310-
const virtio_snd_query_info_t *query)
310+
const virtio_snd_query_info_t *query,
311+
uint32_t *plen)
311312
{
312-
printf("jack info handler count %d\n", query->count);
313-
for (uint32_t i = 0; i < query->count; i++) {
313+
uint32_t cnt = query->count;
314+
printf("jack info handler count %d\n", cnt);
315+
for (uint32_t i = 0; i < cnt; i++) {
314316
info[i].hdr.hda_fn_nid = 0;
315317
info[i].features = 0;
316318
info[i].hda_reg_defconf = 0;
@@ -325,14 +327,18 @@ static void virtio_snd_read_jack_info_handler(
325327
vsnd_props[i].j.connected = 1;
326328
memset(&vsnd_props[i].j.padding, 0, sizeof(vsnd_props[i].j.padding));
327329
}
330+
331+
*plen = cnt * sizeof(*info);
328332
}
329333

330334
static void virtio_snd_read_pcm_info_handler(
331335
virtio_snd_pcm_info_t *info,
332-
const virtio_snd_query_info_t *query)
336+
const virtio_snd_query_info_t *query,
337+
uint32_t *plen)
333338
{
334-
printf("snd info handler count %d\n", query->count);
335-
for (uint32_t i = 0; i < query->count; i++) {
339+
uint32_t cnt = query->count;
340+
printf("snd info handler count %d\n", cnt);
341+
for (uint32_t i = 0; i < cnt; i++) {
336342
info[i].hdr.hda_fn_nid = 0;
337343
info[i].features = 0;
338344
info[i].formats = (1 << VIRTIO_SND_PCM_FMT_S16);
@@ -351,14 +357,17 @@ static void virtio_snd_read_pcm_info_handler(
351357
vsnd_props[i].p.channels_max = 1;
352358
memset(&vsnd_props[i].p.padding, 0, sizeof(vsnd_props[i].p.padding));
353359
}
360+
*plen = cnt * sizeof(*info);
354361
}
355362

356363
static void virtio_snd_read_chmap_info_handler(
357364
virtio_snd_chmap_info_t *info,
358-
const virtio_snd_query_info_t *query)
365+
const virtio_snd_query_info_t *query,
366+
uint32_t *plen)
359367
{
360-
printf("chmap info handler count %d\n", query->count);
361-
for (uint32_t i = 0; i < query->count; i++) {
368+
uint32_t cnt = query->count;
369+
printf("chmap info handler count %d\n", cnt);
370+
for (uint32_t i = 0; i < cnt; i++) {
362371
info[i].hdr.hda_fn_nid = 0;
363372
info[i].direction = VIRTIO_SND_D_OUTPUT;
364373
info[i].channels = 1;
@@ -369,6 +378,7 @@ static void virtio_snd_read_chmap_info_handler(
369378
vsnd_props[i].c.channels = 1;
370379
vsnd_props[i].c.positions[0] = VIRTIO_SND_CHMAP_MONO;
371380
}
381+
*plen = cnt * sizeof(info);
372382
}
373383

374384
static void virtio_snd_read_pcm_set_params(struct virtq_desc *vq_desc,
@@ -604,13 +614,13 @@ static int virtio_snd_desc_handler(virtio_snd_state_t *vsnd,
604614
/* Process the data */
605615
switch (type) {
606616
case VIRTIO_SND_R_JACK_INFO:
607-
virtio_snd_read_jack_info_handler(info, query);
617+
virtio_snd_read_jack_info_handler(info, query, plen);
608618
break;
609619
case VIRTIO_SND_R_PCM_INFO:
610-
virtio_snd_read_pcm_info_handler(info, query);
620+
virtio_snd_read_pcm_info_handler(info, query, plen);
611621
break;
612622
case VIRTIO_SND_R_CHMAP_INFO:
613-
virtio_snd_read_chmap_info_handler(info, query);
623+
virtio_snd_read_chmap_info_handler(info, query, plen);
614624
break;
615625
case VIRTIO_SND_R_PCM_SET_PARAMS:
616626
virtio_snd_read_pcm_set_params(vq_desc, query);
@@ -636,7 +646,7 @@ static int virtio_snd_desc_handler(virtio_snd_state_t *vsnd,
636646

637647
/* Return the device status */
638648
response->code = VIRTIO_SND_S_OK;
639-
*plen = vq_desc[2].len;
649+
//*plen = vq_desc[2].len;
640650

641651
return 0;
642652
}

0 commit comments

Comments
 (0)