sound/sound_core.c
Source file repositories/reference/linux-study-clean/sound/sound_core.c
File Facts
- System
- Linux kernel
- Corpus path
sound/sound_core.c- Extension
.c- Size
- 14519 bytes
- Lines
- 618
- Domain
- Driver Families
- Bucket
- sound/sound_core.c
- 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/module.hlinux/device.hlinux/err.hlinux/kdev_t.hlinux/major.hsound/core.hlinux/init.hlinux/slab.hlinux/types.hlinux/kernel.hlinux/sound.hlinux/kmod.h
Detected Declarations
struct sound_unitfunction init_oss_soundcorefunction cleanup_oss_soundcorefunction init_soundcorefunction cleanup_soundcorefunction __sound_insert_unitfunction sound_insert_unitfunction sound_remove_unitfunction register_sound_special_devicefunction register_sound_specialfunction register_sound_mixerfunction register_sound_dspfunction register_sound_specialfunction register_sound_mixerfunction register_sound_dspfunction soundcore_openfunction cleanup_oss_soundcorefunction init_oss_soundcoremodule init init_soundcoreexport sound_classexport register_sound_special_deviceexport register_sound_specialexport register_sound_mixerexport register_sound_dspexport unregister_sound_specialexport unregister_sound_mixerexport unregister_sound_dsp
Annotated Snippet
const struct file_operations *unit_fops;
struct sound_unit *next;
char name[32];
};
/*
* By default, OSS sound_core claims full legacy minor range (0-255)
* of SOUND_MAJOR to trap open attempts to any sound minor and
* requests modules using custom sound-slot/service-* module aliases.
* The only benefit of doing this is allowing use of custom module
* aliases instead of the standard char-major-* ones. This behavior
* prevents alternative OSS implementation and is scheduled to be
* removed.
*
* CONFIG_SOUND_OSS_CORE_PRECLAIM and soundcore.preclaim_oss kernel
* parameter are added to allow distros and developers to try and
* switch to alternative implementations without needing to rebuild
* the kernel in the meantime. If preclaim_oss is non-zero, the
* kernel will behave the same as before. All SOUND_MAJOR minors are
* preclaimed and the custom module aliases along with standard chrdev
* ones are emitted if a missing device is opened. If preclaim_oss is
* zero, sound_core only grabs what's actually in use and for missing
* devices only the standard chrdev aliases are requested.
*
* All these clutters are scheduled to be removed along with
* sound-slot/service-* module aliases.
*/
static int preclaim_oss = IS_ENABLED(CONFIG_SOUND_OSS_CORE_PRECLAIM);
module_param(preclaim_oss, int, 0444);
static int soundcore_open(struct inode *, struct file *);
static const struct file_operations soundcore_fops =
{
/* We must have an owner or the module locking fails */
.owner = THIS_MODULE,
.open = soundcore_open,
.llseek = noop_llseek,
};
/*
* Low level list operator. Scan the ordered list, find a hole and
* join into it. Called with the lock asserted
*/
static int __sound_insert_unit(struct sound_unit * s, struct sound_unit **list, const struct file_operations *fops, int index, int low, int top)
{
int n=low;
if (index < 0) { /* first free */
while (*list && (*list)->unit_minor<n)
list=&((*list)->next);
while(n<top)
{
/* Found a hole ? */
if(*list==NULL || (*list)->unit_minor>n)
break;
list=&((*list)->next);
n+=SOUND_STEP;
}
if(n>=top)
return -ENOENT;
} else {
n = low+(index*16);
while (*list) {
if ((*list)->unit_minor==n)
return -EBUSY;
if ((*list)->unit_minor>n)
break;
list=&((*list)->next);
}
}
/*
* Fill it in
*/
s->unit_minor=n;
s->unit_fops=fops;
/*
* Link it
*/
s->next=*list;
*list=s;
Annotation
- Immediate include surface: `linux/module.h`, `linux/device.h`, `linux/err.h`, `linux/kdev_t.h`, `linux/major.h`, `sound/core.h`, `linux/init.h`, `linux/slab.h`.
- Detected declarations: `struct sound_unit`, `function init_oss_soundcore`, `function cleanup_oss_soundcore`, `function init_soundcore`, `function cleanup_soundcore`, `function __sound_insert_unit`, `function sound_insert_unit`, `function sound_remove_unit`, `function register_sound_special_device`, `function register_sound_special`.
- Atlas domain: Driver Families / sound/sound_core.c.
- 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.