sound/core/device.c
Source file repositories/reference/linux-study-clean/sound/core/device.c
File Facts
- System
- Linux kernel
- Corpus path
sound/core/device.c- Extension
.c- Size
- 5970 bytes
- Lines
- 240
- 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.
- 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/slab.hlinux/time.hlinux/export.hlinux/errno.hsound/core.h
Detected Declarations
function Copyrightfunction __snd_device_disconnectfunction __snd_device_freefunction snd_card_disconnectfunction snd_device_freefunction __snd_device_registerfunction snd_device_newfunction snd_device_register_allfunction snd_device_disconnect_allfunction snd_device_free_allexport snd_device_newexport snd_device_disconnectexport snd_device_freeexport snd_device_register
Annotated Snippet
if (dev->ops->dev_register) {
int err = dev->ops->dev_register(dev);
if (err < 0)
return err;
}
dev->state = SNDRV_DEV_REGISTERED;
}
return 0;
}
/**
* snd_device_register - register the device
* @card: the card instance
* @device_data: the data pointer to register
*
* Registers the device which was already created via
* snd_device_new(). Usually this is called from snd_card_register(),
* but it can be called later if any new devices are created after
* invocation of snd_card_register().
*
* Return: Zero if successful, or a negative error code on failure or if the
* device not found.
*/
int snd_device_register(struct snd_card *card, void *device_data)
{
struct snd_device *dev;
if (snd_BUG_ON(!card || !device_data))
return -ENXIO;
dev = look_for_dev(card, device_data);
if (dev)
return __snd_device_register(dev);
snd_BUG();
return -ENXIO;
}
EXPORT_SYMBOL(snd_device_register);
/*
* register all the devices on the card.
* called from init.c
*/
int snd_device_register_all(struct snd_card *card)
{
struct snd_device *dev;
int err;
if (snd_BUG_ON(!card))
return -ENXIO;
list_for_each_entry(dev, &card->devices, list) {
err = __snd_device_register(dev);
if (err < 0)
return err;
}
return 0;
}
/*
* disconnect all the devices on the card.
* called from init.c
*/
void snd_device_disconnect_all(struct snd_card *card)
{
struct snd_device *dev;
if (snd_BUG_ON(!card))
return;
list_for_each_entry_reverse(dev, &card->devices, list)
__snd_device_disconnect(dev);
}
/*
* release all the devices on the card.
* called from init.c
*/
void snd_device_free_all(struct snd_card *card)
{
struct snd_device *dev, *next;
if (snd_BUG_ON(!card))
return;
list_for_each_entry_safe_reverse(dev, next, &card->devices, list) {
/* exception: free ctl and lowlevel stuff later */
if (dev->type == SNDRV_DEV_CONTROL ||
dev->type == SNDRV_DEV_LOWLEVEL)
continue;
__snd_device_free(dev);
}
/* free all */
list_for_each_entry_safe_reverse(dev, next, &card->devices, list)
Annotation
- Immediate include surface: `linux/slab.h`, `linux/time.h`, `linux/export.h`, `linux/errno.h`, `sound/core.h`.
- Detected declarations: `function Copyright`, `function __snd_device_disconnect`, `function __snd_device_free`, `function snd_card_disconnect`, `function snd_device_free`, `function __snd_device_register`, `function snd_device_new`, `function snd_device_register_all`, `function snd_device_disconnect_all`, `function snd_device_free_all`.
- Atlas domain: Driver Families / sound/core.
- 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.