drivers/dma-buf/sync_file.c
Source file repositories/reference/linux-study-clean/drivers/dma-buf/sync_file.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/dma-buf/sync_file.c- Extension
.c- Size
- 9280 bytes
- Lines
- 408
- Domain
- Driver Families
- Bucket
- drivers/dma-buf
- 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.
- 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/dma-fence-unwrap.hlinux/export.hlinux/file.hlinux/fs.hlinux/kernel.hlinux/poll.hlinux/sched.hlinux/slab.hlinux/uaccess.hlinux/anon_inodes.hlinux/sync_file.huapi/linux/sync_file.h
Detected Declarations
function fence_check_cb_funcfunction sync_file_createfunction userfunction sync_file_mergefunction sync_file_releasefunction sync_file_pollfunction sync_file_ioctl_mergefunction sync_fill_fence_infofunction sync_file_ioctl_fence_infofunction sync_file_ioctl_set_deadlinefunction sync_file_ioctlexport sync_file_createexport sync_file_get_fence
Annotated Snippet
static const struct file_operations sync_file_fops;
static struct sync_file *sync_file_alloc(void)
{
struct sync_file *sync_file;
sync_file = kzalloc_obj(*sync_file);
if (!sync_file)
return NULL;
sync_file->file = anon_inode_getfile("sync_file", &sync_file_fops,
sync_file, 0);
if (IS_ERR(sync_file->file))
goto err;
init_waitqueue_head(&sync_file->wq);
INIT_LIST_HEAD(&sync_file->cb.node);
return sync_file;
err:
kfree(sync_file);
return NULL;
}
static void fence_check_cb_func(struct dma_fence *f, struct dma_fence_cb *cb)
{
struct sync_file *sync_file;
sync_file = container_of(cb, struct sync_file, cb);
wake_up_all(&sync_file->wq);
}
/**
* sync_file_create() - creates a sync file
* @fence: fence to add to the sync_fence
*
* Creates a sync_file containg @fence. This function acquires and additional
* reference of @fence for the newly-created &sync_file, if it succeeds. The
* sync_file can be released with fput(sync_file->file). Returns the
* sync_file or NULL in case of error.
*/
struct sync_file *sync_file_create(struct dma_fence *fence)
{
struct sync_file *sync_file;
sync_file = sync_file_alloc();
if (!sync_file)
return NULL;
sync_file->fence = dma_fence_get(fence);
return sync_file;
}
EXPORT_SYMBOL(sync_file_create);
static struct sync_file *sync_file_fdget(int fd)
{
struct file *file = fget(fd);
if (!file)
return NULL;
if (file->f_op != &sync_file_fops)
goto err;
return file->private_data;
err:
fput(file);
return NULL;
}
/**
* sync_file_get_fence - get the fence related to the sync_file fd
* @fd: sync_file fd to get the fence from
*
* Ensures @fd references a valid sync_file and returns a fence that
* represents all fence in the sync_file. On error NULL is returned.
*/
struct dma_fence *sync_file_get_fence(int fd)
{
struct sync_file *sync_file;
struct dma_fence *fence;
sync_file = sync_file_fdget(fd);
if (!sync_file)
return NULL;
Annotation
- Immediate include surface: `linux/dma-fence-unwrap.h`, `linux/export.h`, `linux/file.h`, `linux/fs.h`, `linux/kernel.h`, `linux/poll.h`, `linux/sched.h`, `linux/slab.h`.
- Detected declarations: `function fence_check_cb_func`, `function sync_file_create`, `function user`, `function sync_file_merge`, `function sync_file_release`, `function sync_file_poll`, `function sync_file_ioctl_merge`, `function sync_fill_fence_info`, `function sync_file_ioctl_fence_info`, `function sync_file_ioctl_set_deadline`.
- Atlas domain: Driver Families / drivers/dma-buf.
- Implementation status: pattern 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.