drivers/media/usb/uvc/uvc_v4l2.c
Source file repositories/reference/linux-study-clean/drivers/media/usb/uvc/uvc_v4l2.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/media/usb/uvc/uvc_v4l2.c- Extension
.c- Size
- 32991 bytes
- Lines
- 1299
- Domain
- Driver Families
- Bucket
- drivers/media
- 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.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- 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/bits.hlinux/compat.hlinux/kernel.hlinux/list.hlinux/module.hlinux/slab.hlinux/usb.hlinux/videodev2.hlinux/vmalloc.hlinux/mm.hlinux/wait.hlinux/atomic.hmedia/v4l2-common.hmedia/v4l2-ctrls.hmedia/v4l2-event.hmedia/v4l2-ioctl.huvcvideo.h
Detected Declarations
struct uvc_xu_control_mapping32struct uvc_xu_control_query32function Copyrightfunction uvc_pm_putfunction uvc_control_add_xu_mappingfunction uvc_ioctl_xu_ctrl_mapfunction uvc_try_frame_intervalfunction uvc_v4l2_get_bytesperlinefunction uvc_v4l2_try_formatfunction uvc_ioctl_g_fmtfunction uvc_ioctl_s_fmtfunction uvc_ioctl_g_parmfunction uvc_ioctl_s_parmfunction uvc_v4l2_openfunction uvc_v4l2_releasefunction uvc_ioctl_querycapfunction uvc_ioctl_enum_fmtfunction uvc_ioctl_try_fmtfunction uvc_ioctl_enum_inputfunction list_for_each_entryfunction list_for_each_entryfunction uvc_ioctl_g_inputfunction uvc_ioctl_s_inputfunction uvc_ioctl_query_ext_ctrlfunction uvc_ctrl_check_accessfunction uvc_ioctl_g_ext_ctrlsfunction uvc_ioctl_s_try_ext_ctrlsfunction uvc_ioctl_s_ext_ctrlsfunction uvc_ioctl_try_ext_ctrlsfunction uvc_ioctl_querymenufunction uvc_ioctl_g_selectionfunction uvc_ioctl_enum_framesizesfunction uvc_ioctl_enum_frameintervalsfunction uvc_ioctl_subscribe_eventfunction uvc_ioctl_defaultfunction uvc_v4l2_get_xu_mappingfunction uvc_v4l2_put_xu_mappingfunction uvc_v4l2_get_xu_queryfunction uvc_v4l2_put_xu_queryfunction uvc_v4l2_compat_ioctl32function uvc_v4l2_unlocked_ioctl
Annotated Snippet
struct uvc_xu_control_mapping32 {
u32 id;
u8 name[32];
u8 entity[16];
u8 selector;
u8 size;
u8 offset;
u32 v4l2_type;
u32 data_type;
compat_caddr_t menu_info;
u32 menu_count;
u32 reserved[4];
};
static int uvc_v4l2_get_xu_mapping(struct uvc_xu_control_mapping *kp,
const struct uvc_xu_control_mapping32 __user *up)
{
struct uvc_xu_control_mapping32 *p = (void *)kp;
compat_caddr_t info;
u32 count;
if (copy_from_user(p, up, sizeof(*p)))
return -EFAULT;
count = p->menu_count;
info = p->menu_info;
memset(kp->reserved, 0, sizeof(kp->reserved));
kp->menu_info = count ? compat_ptr(info) : NULL;
kp->menu_count = count;
return 0;
}
static int uvc_v4l2_put_xu_mapping(const struct uvc_xu_control_mapping *kp,
struct uvc_xu_control_mapping32 __user *up)
{
if (copy_to_user(up, kp, offsetof(typeof(*up), menu_info)) ||
put_user(kp->menu_count, &up->menu_count))
return -EFAULT;
if (clear_user(up->reserved, sizeof(up->reserved)))
return -EFAULT;
return 0;
}
struct uvc_xu_control_query32 {
u8 unit;
u8 selector;
u8 query;
u16 size;
compat_caddr_t data;
};
static int uvc_v4l2_get_xu_query(struct uvc_xu_control_query *kp,
const struct uvc_xu_control_query32 __user *up)
{
struct uvc_xu_control_query32 v;
if (copy_from_user(&v, up, sizeof(v)))
return -EFAULT;
*kp = (struct uvc_xu_control_query){
.unit = v.unit,
.selector = v.selector,
.query = v.query,
.size = v.size,
.data = v.size ? compat_ptr(v.data) : NULL
};
return 0;
}
static int uvc_v4l2_put_xu_query(const struct uvc_xu_control_query *kp,
struct uvc_xu_control_query32 __user *up)
{
if (copy_to_user(up, kp, offsetof(typeof(*up), data)))
return -EFAULT;
return 0;
}
#define UVCIOC_CTRL_MAP32 _IOWR('u', 0x20, struct uvc_xu_control_mapping32)
#define UVCIOC_CTRL_QUERY32 _IOWR('u', 0x21, struct uvc_xu_control_query32)
static long uvc_v4l2_compat_ioctl32(struct file *file,
unsigned int cmd, unsigned long arg)
{
struct uvc_fh *handle = to_uvc_fh(file);
Annotation
- Immediate include surface: `linux/bits.h`, `linux/compat.h`, `linux/kernel.h`, `linux/list.h`, `linux/module.h`, `linux/slab.h`, `linux/usb.h`, `linux/videodev2.h`.
- Detected declarations: `struct uvc_xu_control_mapping32`, `struct uvc_xu_control_query32`, `function Copyright`, `function uvc_pm_put`, `function uvc_control_add_xu_mapping`, `function uvc_ioctl_xu_ctrl_map`, `function uvc_try_frame_interval`, `function uvc_v4l2_get_bytesperline`, `function uvc_v4l2_try_format`, `function uvc_ioctl_g_fmt`.
- Atlas domain: Driver Families / drivers/media.
- Implementation status: source implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
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.