sound/core/sound.c
Source file repositories/reference/linux-study-clean/sound/core/sound.c
File Facts
- System
- Linux kernel
- Corpus path
sound/core/sound.c- Extension
.c- Size
- 10516 bytes
- Lines
- 429
- Domain
- Driver Families
- Bucket
- sound/core
- 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/init.hlinux/slab.hlinux/time.hlinux/device.hlinux/module.hlinux/debugfs.hsound/core.hsound/minors.hsound/info.hsound/control.hsound/initval.hlinux/kmod.hlinux/mutex.h
Detected Declarations
function snd_request_cardfunction snd_request_otherfunction snd_card_unreffunction snd_openfunction snd_find_free_minorfunction snd_find_free_minorfunction snd_register_devicefunction snd_register_devicefunction snd_minor_info_readfunction snd_minor_info_initfunction alsa_sound_initfunction alsa_sound_exitmodule init alsa_sound_initexport snd_majorexport snd_ecards_limitexport sound_debugfs_rootexport snd_request_cardexport snd_lookup_minor_dataexport snd_register_deviceexport snd_unregister_device
Annotated Snippet
const struct file_operations *new_fops;
int err = 0;
if (minor >= ARRAY_SIZE(snd_minors))
return -ENODEV;
scoped_guard(mutex, &sound_mutex) {
mptr = snd_minors[minor];
if (mptr == NULL) {
mptr = autoload_device(minor);
if (!mptr)
return -ENODEV;
}
new_fops = fops_get(mptr->f_ops);
}
if (!new_fops)
return -ENODEV;
replace_fops(file, new_fops);
if (file->f_op->open)
err = file->f_op->open(inode, file);
return err;
}
static const struct file_operations snd_fops =
{
.owner = THIS_MODULE,
.open = snd_open,
.llseek = noop_llseek,
};
#ifdef CONFIG_SND_DYNAMIC_MINORS
static int snd_find_free_minor(int type, struct snd_card *card, int dev)
{
int minor;
/* static minors for module auto loading */
if (type == SNDRV_DEVICE_TYPE_SEQUENCER)
return SNDRV_MINOR_SEQUENCER;
if (type == SNDRV_DEVICE_TYPE_TIMER)
return SNDRV_MINOR_TIMER;
for (minor = 0; minor < ARRAY_SIZE(snd_minors); ++minor) {
/* skip static minors still used for module auto loading */
if (SNDRV_MINOR_DEVICE(minor) == SNDRV_MINOR_CONTROL)
continue;
if (minor == SNDRV_MINOR_SEQUENCER ||
minor == SNDRV_MINOR_TIMER)
continue;
if (!snd_minors[minor])
return minor;
}
return -EBUSY;
}
#else
static int snd_find_free_minor(int type, struct snd_card *card, int dev)
{
int minor;
switch (type) {
case SNDRV_DEVICE_TYPE_SEQUENCER:
case SNDRV_DEVICE_TYPE_TIMER:
minor = type;
break;
case SNDRV_DEVICE_TYPE_CONTROL:
if (snd_BUG_ON(!card))
return -EINVAL;
minor = SNDRV_MINOR(card->number, type);
break;
case SNDRV_DEVICE_TYPE_HWDEP:
case SNDRV_DEVICE_TYPE_RAWMIDI:
case SNDRV_DEVICE_TYPE_PCM_PLAYBACK:
case SNDRV_DEVICE_TYPE_PCM_CAPTURE:
if (snd_BUG_ON(!card))
return -EINVAL;
minor = SNDRV_MINOR(card->number, type + dev);
break;
case SNDRV_DEVICE_TYPE_COMPRESS:
if (snd_BUG_ON(!card))
return -EINVAL;
if (dev < 0 ||
dev >= SNDRV_MINOR_HWDEP - SNDRV_MINOR_COMPRESS)
return -EINVAL;
minor = SNDRV_MINOR(card->number, type + dev);
break;
default:
return -EINVAL;
}
if (snd_BUG_ON(minor < 0 || minor >= SNDRV_OS_MINORS))
return -EINVAL;
if (snd_minors[minor])
Annotation
- Immediate include surface: `linux/init.h`, `linux/slab.h`, `linux/time.h`, `linux/device.h`, `linux/module.h`, `linux/debugfs.h`, `sound/core.h`, `sound/minors.h`.
- Detected declarations: `function snd_request_card`, `function snd_request_other`, `function snd_card_unref`, `function snd_open`, `function snd_find_free_minor`, `function snd_find_free_minor`, `function snd_register_device`, `function snd_register_device`, `function snd_minor_info_read`, `function snd_minor_info_init`.
- Atlas domain: Driver Families / sound/core.
- 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.