drivers/media/mc/mc-device.c
Source file repositories/reference/linux-study-clean/drivers/media/mc/mc-device.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/media/mc/mc-device.c- Extension
.c- Size
- 23990 bytes
- Lines
- 916
- 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/compat.hlinux/export.hlinux/idr.hlinux/ioctl.hlinux/media.hlinux/slab.hlinux/types.hlinux/pci.hlinux/usb.hlinux/version.hmedia/media-device.hmedia/media-devnode.hmedia/media-entity.hmedia/media-request.h
Detected Declarations
struct media_ioctl_infostruct media_links_enum32function Copyrightfunction media_device_openfunction media_device_closefunction media_device_get_infofunction media_device_for_each_entityfunction media_device_enum_entitiesfunction media_device_kpad_to_upadfunction media_device_enum_linksfunction list_for_each_entryfunction media_device_setup_linkfunction media_device_get_topologyfunction media_device_request_allocfunction copy_arg_from_userfunction copy_arg_to_userfunction media_device_ioctlfunction media_device_enum_links32function media_device_compat_ioctlfunction model_showfunction media_device_releasefunction __media_device_unregister_entityfunction list_for_each_entry_safefunction media_device_register_entityfunction media_device_unregister_entityfunction media_device_requestsfunction media_device_initfunction media_device_cleanupfunction __media_device_registerfunction media_device_register_entity_notifyfunction __media_device_unregister_entity_notifyfunction media_device_unregister_entity_notifyfunction media_device_unregisterfunction media_device_pci_initfunction __media_device_usb_initexport media_device_register_entityexport media_device_unregister_entityexport media_device_initexport media_device_cleanupexport __media_device_registerexport media_device_register_entity_notifyexport media_device_unregister_entity_notifyexport media_device_unregisterexport media_device_pci_initexport __media_device_usb_init
Annotated Snippet
struct media_ioctl_info {
unsigned int cmd;
unsigned short flags;
long (*fn)(struct media_device *dev, void *arg);
long (*arg_from_user)(void *karg, void __user *uarg, unsigned int cmd);
long (*arg_to_user)(void __user *uarg, void *karg, unsigned int cmd);
};
static const struct media_ioctl_info ioctl_info[] = {
MEDIA_IOC(DEVICE_INFO, media_device_get_info, MEDIA_IOC_FL_GRAPH_MUTEX),
MEDIA_IOC(ENUM_ENTITIES, media_device_enum_entities, MEDIA_IOC_FL_GRAPH_MUTEX),
MEDIA_IOC(ENUM_LINKS, media_device_enum_links, MEDIA_IOC_FL_GRAPH_MUTEX),
MEDIA_IOC(SETUP_LINK, media_device_setup_link, MEDIA_IOC_FL_GRAPH_MUTEX),
MEDIA_IOC(G_TOPOLOGY, media_device_get_topology, MEDIA_IOC_FL_GRAPH_MUTEX),
MEDIA_IOC(REQUEST_ALLOC, media_device_request_alloc, 0),
};
static long media_device_ioctl(struct file *filp, unsigned int cmd,
unsigned long __arg)
{
struct media_devnode *devnode = media_devnode_data(filp);
struct media_device *dev = devnode->media_dev;
const struct media_ioctl_info *info;
void __user *arg = (void __user *)__arg;
char __karg[256], *karg = __karg;
long ret;
if (_IOC_NR(cmd) >= ARRAY_SIZE(ioctl_info)
|| ioctl_info[_IOC_NR(cmd)].cmd != cmd)
return -ENOIOCTLCMD;
info = &ioctl_info[_IOC_NR(cmd)];
if (_IOC_SIZE(info->cmd) > sizeof(__karg)) {
karg = kmalloc(_IOC_SIZE(info->cmd), GFP_KERNEL);
if (!karg)
return -ENOMEM;
}
if (info->arg_from_user) {
ret = info->arg_from_user(karg, arg, cmd);
if (ret)
goto out_free;
}
if (info->flags & MEDIA_IOC_FL_GRAPH_MUTEX)
mutex_lock(&dev->graph_mutex);
ret = info->fn(dev, karg);
if (info->flags & MEDIA_IOC_FL_GRAPH_MUTEX)
mutex_unlock(&dev->graph_mutex);
if (!ret && info->arg_to_user)
ret = info->arg_to_user(arg, karg, cmd);
out_free:
if (karg != __karg)
kfree(karg);
return ret;
}
#ifdef CONFIG_COMPAT
struct media_links_enum32 {
__u32 entity;
compat_uptr_t pads; /* struct media_pad_desc * */
compat_uptr_t links; /* struct media_link_desc * */
__u32 reserved[4];
};
static long media_device_enum_links32(struct media_device *mdev,
struct media_links_enum32 __user *ulinks)
{
struct media_links_enum links;
compat_uptr_t pads_ptr, links_ptr;
int ret;
memset(&links, 0, sizeof(links));
if (get_user(links.entity, &ulinks->entity)
|| get_user(pads_ptr, &ulinks->pads)
|| get_user(links_ptr, &ulinks->links))
return -EFAULT;
links.pads = compat_ptr(pads_ptr);
links.links = compat_ptr(links_ptr);
ret = media_device_enum_links(mdev, &links);
Annotation
- Immediate include surface: `linux/compat.h`, `linux/export.h`, `linux/idr.h`, `linux/ioctl.h`, `linux/media.h`, `linux/slab.h`, `linux/types.h`, `linux/pci.h`.
- Detected declarations: `struct media_ioctl_info`, `struct media_links_enum32`, `function Copyright`, `function media_device_open`, `function media_device_close`, `function media_device_get_info`, `function media_device_for_each_entity`, `function media_device_enum_entities`, `function media_device_kpad_to_upad`, `function media_device_enum_links`.
- 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.