drivers/media/mc/mc-request.c
Source file repositories/reference/linux-study-clean/drivers/media/mc/mc-request.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/media/mc/mc-request.c- Extension
.c- Size
- 13913 bytes
- Lines
- 540
- Domain
- Driver Families
- Bucket
- drivers/media
- Inferred role
- Driver Families: operation-table or driver-model contract
- Status
- pattern 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.
- Defines an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- 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/anon_inodes.hlinux/file.hlinux/refcount.hmedia/media-device.hmedia/media-request.h
Detected Declarations
function media_request_state_strfunction media_request_cleanfunction list_for_each_entry_safefunction media_request_releasefunction media_request_putfunction media_request_closefunction media_request_pollfunction media_request_ioctl_queuefunction media_request_ioctl_reinitfunction media_request_ioctlfunction media_request_get_by_fdfunction media_request_allocfunction media_request_object_releasefunction media_request_object_findfunction media_request_object_putfunction media_request_object_initfunction media_request_object_bindfunction media_request_object_unbindfunction media_request_object_completefunction media_request_manual_completeexport media_request_putexport media_request_get_by_fdexport media_request_object_findexport media_request_object_putexport media_request_object_initexport media_request_object_bindexport media_request_object_unbindexport media_request_object_completeexport media_request_manual_complete
Annotated Snippet
static const struct file_operations request_fops = {
.owner = THIS_MODULE,
.poll = media_request_poll,
.unlocked_ioctl = media_request_ioctl,
#ifdef CONFIG_COMPAT
.compat_ioctl = media_request_ioctl,
#endif /* CONFIG_COMPAT */
.release = media_request_close,
};
struct media_request *
media_request_get_by_fd(struct media_device *mdev, int request_fd)
{
struct media_request *req;
if (!mdev || !mdev->ops ||
!mdev->ops->req_validate || !mdev->ops->req_queue)
return ERR_PTR(-EBADR);
CLASS(fd, f)(request_fd);
if (fd_empty(f))
goto err;
if (fd_file(f)->f_op != &request_fops)
goto err;
req = fd_file(f)->private_data;
if (req->mdev != mdev)
goto err;
/*
* Note: as long as someone has an open filehandle of the request,
* the request can never be released. The fdget() above ensures that
* even if userspace closes the request filehandle, the release()
* fop won't be called, so the media_request_get() always succeeds
* and there is no race condition where the request was released
* before media_request_get() is called.
*/
media_request_get(req);
return req;
err:
dev_dbg(mdev->dev, "cannot find request_fd %d\n", request_fd);
return ERR_PTR(-EINVAL);
}
EXPORT_SYMBOL_GPL(media_request_get_by_fd);
int media_request_alloc(struct media_device *mdev, int *alloc_fd)
{
struct media_request *req;
int ret;
/* Either both are NULL or both are non-NULL */
if (WARN_ON(!mdev->ops->req_alloc ^ !mdev->ops->req_free))
return -ENOMEM;
if (mdev->ops->req_alloc)
req = mdev->ops->req_alloc(mdev);
else
req = kzalloc_obj(*req);
if (!req)
return -ENOMEM;
req->mdev = mdev;
req->state = MEDIA_REQUEST_STATE_IDLE;
req->num_incomplete_objects = 0;
req->manual_completion = false;
kref_init(&req->kref);
INIT_LIST_HEAD(&req->objects);
spin_lock_init(&req->lock);
init_waitqueue_head(&req->poll_wait);
req->updating_count = 0;
req->access_count = 0;
FD_PREPARE(fdf, O_CLOEXEC,
anon_inode_getfile("request", &request_fops, NULL,
O_CLOEXEC));
if (fdf.err) {
ret = fdf.err;
goto err_free_req;
}
fd_prepare_file(fdf)->private_data = req;
snprintf(req->debug_str, sizeof(req->debug_str), "%u:%d",
atomic_inc_return(&mdev->request_id), fd_prepare_fd(fdf));
atomic_inc(&mdev->num_requests);
dev_dbg(mdev->dev, "request: allocated %s\n", req->debug_str);
*alloc_fd = fd_publish(fdf);
Annotation
- Immediate include surface: `linux/anon_inodes.h`, `linux/file.h`, `linux/refcount.h`, `media/media-device.h`, `media/media-request.h`.
- Detected declarations: `function media_request_state_str`, `function media_request_clean`, `function list_for_each_entry_safe`, `function media_request_release`, `function media_request_put`, `function media_request_close`, `function media_request_poll`, `function media_request_ioctl_queue`, `function media_request_ioctl_reinit`, `function media_request_ioctl`.
- Atlas domain: Driver Families / drivers/media.
- Implementation status: pattern implementation candidate.
- 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.