drivers/dma-buf/dma-fence-unwrap.c
Source file repositories/reference/linux-study-clean/drivers/dma-buf/dma-fence-unwrap.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/dma-buf/dma-fence-unwrap.c- Extension
.c- Size
- 5191 bytes
- Lines
- 204
- Domain
- Driver Families
- Bucket
- drivers/dma-buf
- 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.
- 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.hlinux/dma-fence-array.hlinux/dma-fence-chain.hlinux/dma-fence-unwrap.hlinux/slab.hlinux/sort.h
Detected Declarations
function Copyrightfunction fence_cmpfunction dma_fence_putfunction dma_fence_unwrap_for_eachfunction dma_fence_unwrap_for_eachexport dma_fence_unwrap_firstexport dma_fence_unwrap_nextexport dma_fence_dedup_arrayexport __dma_fence_unwrap_merge
Annotated Snippet
dma_fence_unwrap_for_each(tmp, &iter[i], fences[i]) {
if (!dma_fence_is_signaled(tmp)) {
dma_fence_put(unsignaled);
unsignaled = dma_fence_get(tmp);
++count;
} else {
ktime_t t = dma_fence_timestamp(tmp);
if (ktime_after(t, timestamp))
timestamp = t;
}
}
}
/*
* If we couldn't find a pending fence just return a private signaled
* fence with the timestamp of the last signaled one.
*
* Or if there was a single unsignaled fence left we can return it
* directly and early since that is a major path on many workloads.
*/
if (count == 0)
return dma_fence_allocate_private_stub(timestamp);
else if (count == 1)
return unsignaled;
dma_fence_put(unsignaled);
array = kmalloc_objs(*array, count);
if (!array)
return NULL;
count = 0;
for (i = 0; i < num_fences; ++i) {
dma_fence_unwrap_for_each(tmp, &iter[i], fences[i]) {
if (!dma_fence_is_signaled(tmp)) {
array[count++] = dma_fence_get(tmp);
} else {
ktime_t t = dma_fence_timestamp(tmp);
if (ktime_after(t, timestamp))
timestamp = t;
}
}
}
if (count == 0 || count == 1)
goto return_fastpath;
count = dma_fence_dedup_array(array, count);
if (count > 1) {
result = dma_fence_array_create(count, array,
dma_fence_context_alloc(1), 1);
if (!result) {
for (i = 0; i < count; i++)
dma_fence_put(array[i]);
tmp = NULL;
goto return_tmp;
}
return &result->base;
}
return_fastpath:
if (count == 0)
tmp = dma_fence_allocate_private_stub(timestamp);
else
tmp = array[0];
return_tmp:
kfree(array);
return tmp;
}
EXPORT_SYMBOL_GPL(__dma_fence_unwrap_merge);
Annotation
- Immediate include surface: `linux/dma-fence.h`, `linux/dma-fence-array.h`, `linux/dma-fence-chain.h`, `linux/dma-fence-unwrap.h`, `linux/slab.h`, `linux/sort.h`.
- Detected declarations: `function Copyright`, `function fence_cmp`, `function dma_fence_put`, `function dma_fence_unwrap_for_each`, `function dma_fence_unwrap_for_each`, `export dma_fence_unwrap_first`, `export dma_fence_unwrap_next`, `export dma_fence_dedup_array`, `export __dma_fence_unwrap_merge`.
- Atlas domain: Driver Families / drivers/dma-buf.
- Implementation status: integration implementation candidate.
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.