sound/virtio/virtio_ctl_msg.c
Source file repositories/reference/linux-study-clean/sound/virtio/virtio_ctl_msg.c
File Facts
- System
- Linux kernel
- Corpus path
sound/virtio/virtio_ctl_msg.c- Extension
.c- Size
- 7865 bytes
- Lines
- 304
- 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.
- 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
linux/moduleparam.hlinux/virtio_config.hvirtio_card.h
Detected Declarations
struct virtio_snd_msgfunction virtsnd_ctl_msg_reffunction virtsnd_ctl_msg_unreffunction virtsnd_ctl_msg_requestfunction virtsnd_ctl_msg_responsefunction virtsnd_ctl_msg_allocfunction virtsnd_ctl_msg_sendfunction scoped_guardfunction virtsnd_ctl_msg_completefunction virtsnd_ctl_msg_cancel_allfunction virtsnd_ctl_query_infofunction virtsnd_ctl_notify_cb
Annotated Snippet
struct virtio_snd_msg {
struct scatterlist sg_request;
struct scatterlist sg_response;
struct list_head list;
struct completion notify;
refcount_t ref_count;
};
/**
* virtsnd_ctl_msg_ref() - Increment reference counter for the message.
* @msg: Control message.
*
* Context: Any context.
*/
void virtsnd_ctl_msg_ref(struct virtio_snd_msg *msg)
{
refcount_inc(&msg->ref_count);
}
/**
* virtsnd_ctl_msg_unref() - Decrement reference counter for the message.
* @msg: Control message.
*
* The message will be freed when the ref_count value is 0.
*
* Context: Any context.
*/
void virtsnd_ctl_msg_unref(struct virtio_snd_msg *msg)
{
if (refcount_dec_and_test(&msg->ref_count))
kfree(msg);
}
/**
* virtsnd_ctl_msg_request() - Get a pointer to the request header.
* @msg: Control message.
*
* Context: Any context.
*/
void *virtsnd_ctl_msg_request(struct virtio_snd_msg *msg)
{
return sg_virt(&msg->sg_request);
}
/**
* virtsnd_ctl_msg_response() - Get a pointer to the response header.
* @msg: Control message.
*
* Context: Any context.
*/
void *virtsnd_ctl_msg_response(struct virtio_snd_msg *msg)
{
return sg_virt(&msg->sg_response);
}
/**
* virtsnd_ctl_msg_alloc() - Allocate and initialize a control message.
* @request_size: Size of request header.
* @response_size: Size of response header.
* @gfp: Kernel flags for memory allocation.
*
* The message will be automatically freed when the ref_count value is 0.
*
* Context: Any context. May sleep if @gfp flags permit.
* Return: Allocated message on success, NULL on failure.
*/
struct virtio_snd_msg *virtsnd_ctl_msg_alloc(size_t request_size,
size_t response_size, gfp_t gfp)
{
struct virtio_snd_msg *msg;
if (!request_size || !response_size)
return NULL;
msg = kzalloc(sizeof(*msg) + request_size + response_size, gfp);
if (!msg)
return NULL;
sg_init_one(&msg->sg_request, (u8 *)msg + sizeof(*msg), request_size);
sg_init_one(&msg->sg_response, (u8 *)msg + sizeof(*msg) + request_size,
response_size);
INIT_LIST_HEAD(&msg->list);
init_completion(&msg->notify);
/* This reference is dropped in virtsnd_ctl_msg_complete(). */
refcount_set(&msg->ref_count, 1);
return msg;
}
Annotation
- Immediate include surface: `linux/moduleparam.h`, `linux/virtio_config.h`, `virtio_card.h`.
- Detected declarations: `struct virtio_snd_msg`, `function virtsnd_ctl_msg_ref`, `function virtsnd_ctl_msg_unref`, `function virtsnd_ctl_msg_request`, `function virtsnd_ctl_msg_response`, `function virtsnd_ctl_msg_alloc`, `function virtsnd_ctl_msg_send`, `function scoped_guard`, `function virtsnd_ctl_msg_complete`, `function virtsnd_ctl_msg_cancel_all`.
- Atlas domain: Driver Families / sound/virtio.
- Implementation status: source implementation candidate.
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.