sound/drivers/pcmtest.c
Source file repositories/reference/linux-study-clean/sound/drivers/pcmtest.c
File Facts
- System
- Linux kernel
- Corpus path
sound/drivers/pcmtest.c- Extension
.c- Size
- 22612 bytes
- Lines
- 790
- Domain
- Driver Families
- Bucket
- sound/drivers
- 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.
- 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/module.hlinux/init.hsound/pcm.hsound/core.hlinux/dma-mapping.hlinux/platform_device.hlinux/string.hlinux/timer.hlinux/random.hlinux/debugfs.hlinux/delay.h
Detected Declarations
struct pcmtststruct pcmtst_buf_iterstruct pattern_buffunction inc_buf_posfunction buf_pos_nfunction isfunction check_buf_block_ifunction check_buf_block_nifunction check_buf_blockfunction continuouslyfunction fill_block_pattern_ifunction fill_block_patternfunction fill_block_rand_nfunction fill_block_rand_ifunction fill_block_randomfunction fill_blockfunction byfunction snd_pcmtst_pcm_openfunction snd_pcmtst_pcm_closefunction reset_buf_iteratorfunction start_pcmtest_timerfunction snd_pcmtst_pcm_triggerfunction snd_pcmtst_pcm_pointerfunction snd_pcmtst_freefunction snd_pcmtst_dev_freefunction pcmtst_pdev_releasefunction snd_pcmtst_pcm_hw_paramsfunction snd_pcmtst_pcm_hw_freefunction snd_pcmtst_ioctlfunction snd_pcmtst_sync_stopfunction snd_pcmtst_new_pcmfunction snd_pcmtst_createfunction pcmtst_probefunction pdev_removefunction pattern_writefunction pattern_readfunction setup_patt_bufsfunction init_debug_filesfunction free_pattern_buffersfunction clear_debug_filesfunction mod_initfunction mod_exitmodule init mod_init
Annotated Snippet
static const struct file_operations fill_pattern_fops = {
.read = pattern_read,
.write = pattern_write,
};
static int setup_patt_bufs(void)
{
size_t i;
for (i = 0; i < ARRAY_SIZE(patt_bufs); i++) {
patt_bufs[i].buf = kmalloc(MAX_PATTERN_LEN, GFP_KERNEL);
if (!patt_bufs[i].buf)
break;
strscpy_pad(patt_bufs[i].buf, DEFAULT_PATTERN, MAX_PATTERN_LEN);
patt_bufs[i].len = DEFAULT_PATTERN_LEN;
}
return i;
}
static const char * const pattern_files[] = { "fill_pattern0", "fill_pattern1",
"fill_pattern2", "fill_pattern3"};
static int init_debug_files(int buf_count)
{
size_t i;
char len_file_name[32];
driver_debug_dir = debugfs_create_dir("pcmtest", NULL);
if (IS_ERR(driver_debug_dir))
return PTR_ERR(driver_debug_dir);
debugfs_create_u8("pc_test", 0444, driver_debug_dir, &playback_capture_test);
debugfs_create_u8("ioctl_test", 0444, driver_debug_dir, &ioctl_reset_test);
for (i = 0; i < buf_count; i++) {
debugfs_create_file(pattern_files[i], 0600, driver_debug_dir,
&patt_bufs[i], &fill_pattern_fops);
snprintf(len_file_name, sizeof(len_file_name), "%s_len", pattern_files[i]);
debugfs_create_u32(len_file_name, 0444, driver_debug_dir, &patt_bufs[i].len);
}
return 0;
}
static void free_pattern_buffers(void)
{
int i;
for (i = 0; i < buf_allocated; i++)
kfree(patt_bufs[i].buf);
}
static void clear_debug_files(void)
{
debugfs_remove_recursive(driver_debug_dir);
}
static int __init mod_init(void)
{
int err = 0;
buf_allocated = setup_patt_bufs();
if (!buf_allocated)
return -ENOMEM;
snd_pcmtst_hw.channels_max = buf_allocated;
err = init_debug_files(buf_allocated);
if (err)
goto err_free_patterns;
err = platform_device_register(&pcmtst_pdev);
if (err)
goto err_clear_debug;
err = platform_driver_register(&pcmtst_pdrv);
if (err) {
platform_device_unregister(&pcmtst_pdev);
goto err_clear_debug;
}
return 0;
err_clear_debug:
clear_debug_files();
err_free_patterns:
free_pattern_buffers();
return err;
}
static void __exit mod_exit(void)
{
clear_debug_files();
Annotation
- Immediate include surface: `linux/module.h`, `linux/init.h`, `sound/pcm.h`, `sound/core.h`, `linux/dma-mapping.h`, `linux/platform_device.h`, `linux/string.h`, `linux/timer.h`.
- Detected declarations: `struct pcmtst`, `struct pcmtst_buf_iter`, `struct pattern_buf`, `function inc_buf_pos`, `function buf_pos_n`, `function is`, `function check_buf_block_i`, `function check_buf_block_ni`, `function check_buf_block`, `function continuously`.
- Atlas domain: Driver Families / sound/drivers.
- Implementation status: pattern implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
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.