drivers/media/v4l2-core/v4l2-ctrls-api.c
Source file repositories/reference/linux-study-clean/drivers/media/v4l2-core/v4l2-ctrls-api.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/media/v4l2-core/v4l2-ctrls-api.c- Extension
.c- Size
- 36320 bytes
- Lines
- 1360
- Domain
- Driver Families
- Bucket
- drivers/media
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration 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.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- 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/export.hlinux/mm.hlinux/slab.hmedia/v4l2-ctrls.hmedia/v4l2-dev.hmedia/v4l2-device.hmedia/v4l2-event.hmedia/v4l2-ioctl.hv4l2-ctrls-priv.h
Detected Declarations
struct v4l2_ctrl_helperfunction ptr_to_userfunction cur_to_userfunction new_to_userfunction req_to_userfunction def_to_userfunction min_to_userfunction max_to_userfunction user_to_newfunction writesfunction class_checkfunction v4l2_g_ext_ctrls_commonfunction v4l2_ctrl_request_completefunction v4l2_g_ext_ctrlsfunction validate_newfunction validate_ctrlsfunction try_set_control_clusterfunction try_set_ext_ctrls_commonfunction valuesfunction try_set_ext_ctrlsfunction v4l2_try_ext_ctrlsfunction v4l2_s_ext_ctrlsfunction get_ctrlfunction v4l2_g_ctrlfunction set_ctrlfunction set_ctrl_lockfunction v4l2_s_ctrlfunction v4l2_ctrl_g_ctrlfunction v4l2_ctrl_g_ctrl_int64function __v4l2_ctrl_s_ctrlfunction __v4l2_ctrl_s_ctrl_int64function __v4l2_ctrl_s_ctrl_stringfunction __v4l2_ctrl_s_ctrl_compoundfunction __v4l2_ctrl_modify_rangefunction __v4l2_ctrl_modify_dimensionsfunction v4l2_query_ext_ctrlfunction list_for_each_entry_continuefunction list_for_each_entryfunction v4l2_query_ext_ctrl_to_v4l2_queryctrlfunction v4l2_queryctrlfunction v4l2_querymenufunction v4l2_ctrl_log_statusfunction v4l2_ctrl_subdev_log_statusfunction VIDIOC_function v4l2_ctrl_del_eventfunction v4l2_ctrl_replacefunction v4l2_ctrl_mergefunction v4l2_ctrl_subscribe_event
Annotated Snippet
struct v4l2_ctrl_helper {
/* Pointer to the control reference of the master control */
struct v4l2_ctrl_ref *mref;
/* The control ref corresponding to the v4l2_ext_control ID field. */
struct v4l2_ctrl_ref *ref;
/*
* v4l2_ext_control index of the next control belonging to the
* same cluster, or 0 if there isn't any.
*/
u32 next;
};
/*
* Helper functions to copy control payload data from kernel space to
* user space and vice versa.
*/
/* Helper function: copy the given control value back to the caller */
static int ptr_to_user(struct v4l2_ext_control *c,
struct v4l2_ctrl *ctrl,
union v4l2_ctrl_ptr ptr)
{
u32 len;
if (ctrl->is_ptr && !ctrl->is_string)
return copy_to_user(c->ptr, ptr.p_const, c->size) ?
-EFAULT : 0;
switch (ctrl->type) {
case V4L2_CTRL_TYPE_STRING:
len = strlen(ptr.p_char);
if (c->size < len + 1) {
c->size = ctrl->elem_size;
return -ENOSPC;
}
return copy_to_user(c->string, ptr.p_char, len + 1) ?
-EFAULT : 0;
case V4L2_CTRL_TYPE_INTEGER64:
c->value64 = *ptr.p_s64;
break;
default:
c->value = *ptr.p_s32;
break;
}
return 0;
}
/* Helper function: copy the current control value back to the caller */
static int cur_to_user(struct v4l2_ext_control *c, struct v4l2_ctrl *ctrl)
{
return ptr_to_user(c, ctrl, ctrl->p_cur);
}
/* Helper function: copy the new control value back to the caller */
static int new_to_user(struct v4l2_ext_control *c,
struct v4l2_ctrl *ctrl)
{
return ptr_to_user(c, ctrl, ctrl->p_new);
}
/* Helper function: copy the request value back to the caller */
static int req_to_user(struct v4l2_ext_control *c,
struct v4l2_ctrl_ref *ref)
{
return ptr_to_user(c, ref->ctrl, ref->p_req);
}
/* Helper function: copy the initial control value back to the caller */
static int def_to_user(struct v4l2_ext_control *c, struct v4l2_ctrl *ctrl)
{
ctrl->type_ops->init(ctrl, 0, ctrl->p_new);
return ptr_to_user(c, ctrl, ctrl->p_new);
}
/* Helper function: copy the minimum control value back to the caller */
static int min_to_user(struct v4l2_ext_control *c, struct v4l2_ctrl *ctrl)
{
ctrl->type_ops->minimum(ctrl, 0, ctrl->p_new);
return ptr_to_user(c, ctrl, ctrl->p_new);
}
/* Helper function: copy the maximum control value back to the caller */
static int max_to_user(struct v4l2_ext_control *c, struct v4l2_ctrl *ctrl)
{
ctrl->type_ops->maximum(ctrl, 0, ctrl->p_new);
return ptr_to_user(c, ctrl, ctrl->p_new);
}
Annotation
- Immediate include surface: `linux/export.h`, `linux/mm.h`, `linux/slab.h`, `media/v4l2-ctrls.h`, `media/v4l2-dev.h`, `media/v4l2-device.h`, `media/v4l2-event.h`, `media/v4l2-ioctl.h`.
- Detected declarations: `struct v4l2_ctrl_helper`, `function ptr_to_user`, `function cur_to_user`, `function new_to_user`, `function req_to_user`, `function def_to_user`, `function min_to_user`, `function max_to_user`, `function user_to_new`, `function writes`.
- Atlas domain: Driver Families / drivers/media.
- Implementation status: integration implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
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.