sound/hda/common/codec.c
Source file repositories/reference/linux-study-clean/sound/hda/common/codec.c
File Facts
- System
- Linux kernel
- Corpus path
sound/hda/common/codec.c- Extension
.c- Size
- 113010 bytes
- Lines
- 4102
- Domain
- Driver Families
- Bucket
- sound/hda
- 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.
- 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/init.hlinux/delay.hlinux/slab.hlinux/minmax.hlinux/mutex.hlinux/module.hlinux/pm.hlinux/pm_runtime.hsound/core.hsound/hda_codec.hsound/asoundef.hsound/tlv.hsound/initval.hsound/jack.hhda_local.hhda_beep.hhda_jack.hsound/hda_hwdep.hsound/hda_component.h
Detected Declarations
struct hda_conn_liststruct hda_cvt_setupstruct follower_init_argfunction Copyrightfunction codec_exec_verbfunction snd_hda_sequence_writefunction lookup_conn_listfunction add_conn_listfunction remove_conn_listfunction read_and_add_raw_connsfunction snd_hda_get_conn_listfunction snd_hda_get_connectionsfunction snd_hda_override_conn_listfunction snd_hda_get_conn_indexfunction snd_hda_get_num_devicesfunction snd_hda_get_devicesfunction snd_hda_get_dev_selectfunction snd_hda_set_dev_selectfunction read_widget_capsfunction read_pin_defaultsfunction for_each_hda_codec_nodefunction snd_array_for_eachfunction snd_hda_add_pincfgfunction snd_hda_codec_get_pincfgfunction snd_hda_codec_get_pincfgfunction scoped_guardfunction snd_hda_codec_get_pin_targetfunction snd_hda_codec_get_pin_targetfunction snd_hda_shutup_pinsfunction restore_shutup_pinsfunction hda_jackpoll_workfunction free_init_pincfgsfunction get_hda_cvt_setupfunction snd_array_for_eachfunction snd_hda_codec_disconnect_pcmsfunction list_for_each_entryfunction codec_release_pcmsfunction list_for_each_entry_safefunction snd_hda_codec_cleanup_for_unbindfunction snd_hda_codec_display_powerfunction snd_hda_codec_registerfunction snd_hda_codec_dev_registerfunction snd_hda_codec_unregisterfunction snd_hda_codec_dev_freefunction snd_hda_codec_dev_releasefunction ERR_PTRfunction snd_hda_codec_newfunction snd_hda_codec_device_new
Annotated Snippet
struct hda_conn_list {
struct list_head list;
int len;
hda_nid_t nid;
hda_nid_t conns[] __counted_by(len);
};
/* look up the cached results */
static struct hda_conn_list *
lookup_conn_list(struct hda_codec *codec, hda_nid_t nid)
{
struct hda_conn_list *p;
list_for_each_entry(p, &codec->conn_list, list) {
if (p->nid == nid)
return p;
}
return NULL;
}
static int add_conn_list(struct hda_codec *codec, hda_nid_t nid, int len,
const hda_nid_t *list)
{
struct hda_conn_list *p;
p = kmalloc_flex(*p, conns, len);
if (!p)
return -ENOMEM;
p->len = len;
p->nid = nid;
memcpy(p->conns, list, len * sizeof(hda_nid_t));
list_add(&p->list, &codec->conn_list);
return 0;
}
static void remove_conn_list(struct hda_codec *codec)
{
while (!list_empty(&codec->conn_list)) {
struct hda_conn_list *p;
p = list_first_entry(&codec->conn_list, typeof(*p), list);
list_del(&p->list);
kfree(p);
}
}
/* read the connection and add to the cache */
static int read_and_add_raw_conns(struct hda_codec *codec, hda_nid_t nid)
{
hda_nid_t list[32];
hda_nid_t *result = list;
int len;
len = snd_hda_get_raw_connections(codec, nid, list, ARRAY_SIZE(list));
if (len == -ENOSPC) {
len = snd_hda_get_num_raw_conns(codec, nid);
result = kmalloc_objs(hda_nid_t, len);
if (!result)
return -ENOMEM;
len = snd_hda_get_raw_connections(codec, nid, result, len);
}
if (len >= 0)
len = snd_hda_override_conn_list(codec, nid, len, result);
if (result != list)
kfree(result);
return len;
}
/**
* snd_hda_get_conn_list - get connection list
* @codec: the HDA codec
* @nid: NID to parse
* @listp: the pointer to store NID list
*
* Parses the connection list of the given widget and stores the pointer
* to the list of NIDs.
*
* Returns the number of connections, or a negative error code.
*
* Note that the returned pointer isn't protected against the list
* modification. If snd_hda_override_conn_list() might be called
* concurrently, protect with a mutex appropriately.
*/
int snd_hda_get_conn_list(struct hda_codec *codec, hda_nid_t nid,
const hda_nid_t **listp)
{
bool added = false;
for (;;) {
int err;
const struct hda_conn_list *p;
Annotation
- Immediate include surface: `linux/init.h`, `linux/delay.h`, `linux/slab.h`, `linux/minmax.h`, `linux/mutex.h`, `linux/module.h`, `linux/pm.h`, `linux/pm_runtime.h`.
- Detected declarations: `struct hda_conn_list`, `struct hda_cvt_setup`, `struct follower_init_arg`, `function Copyright`, `function codec_exec_verb`, `function snd_hda_sequence_write`, `function lookup_conn_list`, `function add_conn_list`, `function remove_conn_list`, `function read_and_add_raw_conns`.
- Atlas domain: Driver Families / sound/hda.
- Implementation status: integration 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.