sound/virtio/virtio_kctl.c
Source file repositories/reference/linux-study-clean/sound/virtio/virtio_kctl.c
File Facts
- System
- Linux kernel
- Corpus path
sound/virtio/virtio_kctl.c- Extension
.c- Size
- 14911 bytes
- Lines
- 528
- Domain
- Driver Families
- Bucket
- sound/virtio
- Inferred role
- Driver Families: implementation source
- Status
- source implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
sound/control.hlinux/virtio_config.hvirtio_card.h
Detected Declarations
function virtsnd_kctl_validate_infofunction virtsnd_kctl_infofunction virtsnd_kctl_getfunction virtsnd_kctl_putfunction virtsnd_kctl_tlv_opfunction virtsnd_kctl_get_enum_itemsfunction virtsnd_kctl_parse_cfgfunction virtsnd_kctl_build_devsfunction virtsnd_kctl_event
Annotated Snippet
if (!rc) {
if (copy_to_user(utlv, tlv, size))
rc = -EFAULT;
}
break;
case SNDRV_CTL_TLV_OP_WRITE:
case SNDRV_CTL_TLV_OP_CMD:
if (op_flag == SNDRV_CTL_TLV_OP_WRITE)
hdr->hdr.code = cpu_to_le32(VIRTIO_SND_R_CTL_TLV_WRITE);
else
hdr->hdr.code =
cpu_to_le32(VIRTIO_SND_R_CTL_TLV_COMMAND);
if (copy_from_user(tlv, utlv, size)) {
rc = -EFAULT;
goto on_msg_unref;
} else {
rc = virtsnd_ctl_msg_send(snd, msg, &sg, NULL, false);
}
break;
default:
rc = -EINVAL;
/* We never get here - we listed all values for op_flag */
WARN_ON(1);
goto on_msg_unref;
}
kfree(tlv);
return rc;
on_msg_unref:
virtsnd_ctl_msg_unref(msg);
kfree(tlv);
return rc;
}
/**
* virtsnd_kctl_get_enum_items() - Query items for the ENUMERATED element type.
* @snd: VirtIO sound device.
* @cid: Control element ID.
*
* This function is called during initial device initialization.
*
* Context: Any context that permits to sleep.
* Return: 0 on success, -errno on failure.
*/
static int virtsnd_kctl_get_enum_items(struct virtio_snd *snd, unsigned int cid)
{
struct virtio_device *vdev = snd->vdev;
struct virtio_snd_ctl_info *kinfo = &snd->kctl_infos[cid];
struct virtio_kctl *kctl = &snd->kctls[cid];
struct virtio_snd_msg *msg;
struct virtio_snd_ctl_hdr *hdr;
unsigned int n = le32_to_cpu(kinfo->value.enumerated.items);
struct scatterlist sg;
msg = virtsnd_ctl_msg_alloc(sizeof(*hdr),
sizeof(struct virtio_snd_hdr), GFP_KERNEL);
if (!msg)
return -ENOMEM;
kctl->items = devm_kcalloc(&vdev->dev, n, sizeof(*kctl->items),
GFP_KERNEL);
if (!kctl->items) {
virtsnd_ctl_msg_unref(msg);
return -ENOMEM;
}
sg_init_one(&sg, kctl->items, n * sizeof(*kctl->items));
hdr = virtsnd_ctl_msg_request(msg);
hdr->hdr.code = cpu_to_le32(VIRTIO_SND_R_CTL_ENUM_ITEMS);
hdr->control_id = cpu_to_le32(cid);
return virtsnd_ctl_msg_send(snd, msg, NULL, &sg, false);
}
/**
* virtsnd_kctl_parse_cfg() - Parse the control element configuration.
* @snd: VirtIO sound device.
*
* This function is called during initial device initialization.
*
* Context: Any context that permits to sleep.
* Return: 0 on success, -errno on failure.
*/
int virtsnd_kctl_parse_cfg(struct virtio_snd *snd)
{
Annotation
- Immediate include surface: `sound/control.h`, `linux/virtio_config.h`, `virtio_card.h`.
- Detected declarations: `function virtsnd_kctl_validate_info`, `function virtsnd_kctl_info`, `function virtsnd_kctl_get`, `function virtsnd_kctl_put`, `function virtsnd_kctl_tlv_op`, `function virtsnd_kctl_get_enum_items`, `function virtsnd_kctl_parse_cfg`, `function virtsnd_kctl_build_devs`, `function virtsnd_kctl_event`.
- Atlas domain: Driver Families / sound/virtio.
- Implementation status: source implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.