sound/core/seq/seq_memory.c
Source file repositories/reference/linux-study-clean/sound/core/seq/seq_memory.c
File Facts
- System
- Linux kernel
- Corpus path
sound/core/seq/seq_memory.c- Extension
.c- Size
- 13102 bytes
- Lines
- 563
- Domain
- Driver Families
- Bucket
- sound/core
- 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/init.hlinux/export.hlinux/slab.hlinux/sched/signal.hlinux/mm.hsound/core.hsound/seq_kernel.hseq_memory.hseq_queue.hseq_info.hseq_lock.h
Detected Declarations
function Copyrightfunction snd_seq_output_okfunction readfunction dump_var_eventfunction snd_seq_dump_var_eventfunction seq_copy_in_kernelfunction seq_copy_in_userfunction expand_var_eventfunction snd_seq_expand_var_eventfunction snd_seq_expand_var_event_atfunction free_cellfunction snd_seq_cell_freefunction snd_seq_cell_allocfunction snd_seq_event_dupfunction snd_seq_pool_poll_waitfunction snd_seq_pool_initfunction snd_seq_pool_mark_closingfunction snd_seq_pool_donefunction snd_seq_pool_deletefunction snd_seq_info_poolexport snd_seq_dump_var_eventexport snd_seq_expand_var_eventexport snd_seq_expand_var_event_at
Annotated Snippet
while (len > 0) {
int size = sizeof(buf);
if (len < size)
size = len;
if (copy_from_user(buf, curptr, size))
return -EFAULT;
err = func(private_data, buf, size);
if (err < 0)
return err;
curptr += size;
len -= size;
}
return 0;
}
if (!(event->data.ext.len & SNDRV_SEQ_EXT_CHAINED))
return func(private_data, event->data.ext.ptr + offset,
len - offset);
cell = (struct snd_seq_event_cell *)event->data.ext.ptr;
for (; len > 0 && cell; cell = cell->next) {
int size = sizeof(struct snd_seq_event);
char *curptr = (char *)&cell->event;
if (offset >= size) {
offset -= size;
len -= size;
continue;
}
if (len < size)
size = len;
err = func(private_data, curptr + offset, size - offset);
if (err < 0)
return err;
offset = 0;
len -= size;
}
return 0;
}
int snd_seq_dump_var_event(const struct snd_seq_event *event,
snd_seq_dump_func_t func, void *private_data)
{
return dump_var_event(event, func, private_data, 0, 0);
}
EXPORT_SYMBOL(snd_seq_dump_var_event);
/*
* exported:
* expand the variable length event to linear buffer space.
*/
static int seq_copy_in_kernel(void *ptr, void *src, int size)
{
char **bufptr = ptr;
memcpy(*bufptr, src, size);
*bufptr += size;
return 0;
}
static int seq_copy_in_user(void *ptr, void *src, int size)
{
char __user **bufptr = ptr;
if (copy_to_user(*bufptr, src, size))
return -EFAULT;
*bufptr += size;
return 0;
}
static int expand_var_event(const struct snd_seq_event *event,
int offset, int size, char *buf, bool in_kernel)
{
if (event->data.ext.len & SNDRV_SEQ_EXT_USRPTR) {
if (! in_kernel)
return -EINVAL;
if (copy_from_user(buf,
(char __force __user *)event->data.ext.ptr + offset,
size))
return -EFAULT;
return 0;
}
return dump_var_event(event,
in_kernel ? seq_copy_in_kernel : seq_copy_in_user,
&buf, offset, size);
}
int snd_seq_expand_var_event(const struct snd_seq_event *event, int count, char *buf,
int in_kernel, int size_aligned)
Annotation
- Immediate include surface: `linux/init.h`, `linux/export.h`, `linux/slab.h`, `linux/sched/signal.h`, `linux/mm.h`, `sound/core.h`, `sound/seq_kernel.h`, `seq_memory.h`.
- Detected declarations: `function Copyright`, `function snd_seq_output_ok`, `function read`, `function dump_var_event`, `function snd_seq_dump_var_event`, `function seq_copy_in_kernel`, `function seq_copy_in_user`, `function expand_var_event`, `function snd_seq_expand_var_event`, `function snd_seq_expand_var_event_at`.
- Atlas domain: Driver Families / sound/core.
- 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.