sound/core/hwdep.c
Source file repositories/reference/linux-study-clean/sound/core/hwdep.c
File Facts
- System
- Linux kernel
- Corpus path
sound/core/hwdep.c- Extension
.c- Size
- 12602 bytes
- Lines
- 540
- 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.
- 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/major.hlinux/init.hlinux/slab.hlinux/time.hlinux/mutex.hlinux/module.hlinux/sched/signal.hsound/core.hsound/control.hsound/minors.hsound/hwdep.hsound/info.hhwdep_compat.c
Detected Declarations
function snd_hwdep_llseekfunction snd_hwdep_readfunction snd_hwdep_writefunction snd_hwdep_openfunction snd_hwdep_releasefunction scoped_guardfunction snd_hwdep_pollfunction snd_hwdep_infofunction snd_hwdep_dsp_statusfunction snd_hwdep_dsp_loadfunction snd_hwdep_dsp_load_userfunction snd_hwdep_ioctlfunction snd_hwdep_mmapfunction snd_hwdep_control_ioctlfunction scoped_guardfunction scoped_guardfunction snd_hwdep_freefunction callbacksfunction snd_hwdep_dev_freefunction snd_hwdep_dev_registerfunction snd_hwdep_dev_disconnectfunction snd_hwdep_proc_readfunction snd_hwdep_proc_initfunction snd_hwdep_proc_donefunction alsa_hwdep_initfunction alsa_hwdep_exitmodule init alsa_hwdep_initexport snd_hwdep_new
Annotated Snippet
static const struct file_operations snd_hwdep_f_ops =
{
.owner = THIS_MODULE,
.llseek = snd_hwdep_llseek,
.read = snd_hwdep_read,
.write = snd_hwdep_write,
.open = snd_hwdep_open,
.release = snd_hwdep_release,
.poll = snd_hwdep_poll,
.unlocked_ioctl = snd_hwdep_ioctl,
.compat_ioctl = snd_hwdep_ioctl_compat,
.mmap = snd_hwdep_mmap,
};
static void snd_hwdep_free(struct snd_hwdep *hwdep)
{
if (!hwdep)
return;
if (hwdep->private_free)
hwdep->private_free(hwdep);
put_device(hwdep->dev);
kfree(hwdep);
}
/**
* snd_hwdep_new - create a new hwdep instance
* @card: the card instance
* @id: the id string
* @device: the device index (zero-based)
* @rhwdep: the pointer to store the new hwdep instance
*
* Creates a new hwdep instance with the given index on the card.
* The callbacks (hwdep->ops) must be set on the returned instance
* after this call manually by the caller.
*
* Return: Zero if successful, or a negative error code on failure.
*/
int snd_hwdep_new(struct snd_card *card, char *id, int device,
struct snd_hwdep **rhwdep)
{
struct snd_hwdep *hwdep;
int err;
static const struct snd_device_ops ops = {
.dev_free = snd_hwdep_dev_free,
.dev_register = snd_hwdep_dev_register,
.dev_disconnect = snd_hwdep_dev_disconnect,
};
if (snd_BUG_ON(!card))
return -ENXIO;
if (rhwdep)
*rhwdep = NULL;
hwdep = kzalloc_obj(*hwdep);
if (!hwdep)
return -ENOMEM;
init_waitqueue_head(&hwdep->open_wait);
mutex_init(&hwdep->open_mutex);
hwdep->card = card;
hwdep->device = device;
if (id)
strscpy(hwdep->id, id, sizeof(hwdep->id));
err = snd_device_alloc(&hwdep->dev, card);
if (err < 0) {
snd_hwdep_free(hwdep);
return err;
}
dev_set_name(hwdep->dev, "hwC%iD%i", card->number, device);
#ifdef CONFIG_SND_OSSEMUL
hwdep->oss_type = -1;
#endif
err = snd_device_new(card, SNDRV_DEV_HWDEP, hwdep, &ops);
if (err < 0) {
snd_hwdep_free(hwdep);
return err;
}
if (rhwdep)
*rhwdep = hwdep;
return 0;
}
EXPORT_SYMBOL(snd_hwdep_new);
static int snd_hwdep_dev_free(struct snd_device *device)
{
snd_hwdep_free(device->device_data);
return 0;
Annotation
- Immediate include surface: `linux/major.h`, `linux/init.h`, `linux/slab.h`, `linux/time.h`, `linux/mutex.h`, `linux/module.h`, `linux/sched/signal.h`, `sound/core.h`.
- Detected declarations: `function snd_hwdep_llseek`, `function snd_hwdep_read`, `function snd_hwdep_write`, `function snd_hwdep_open`, `function snd_hwdep_release`, `function scoped_guard`, `function snd_hwdep_poll`, `function snd_hwdep_info`, `function snd_hwdep_dsp_status`, `function snd_hwdep_dsp_load`.
- Atlas domain: Driver Families / sound/core.
- Implementation status: pattern 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.