tools/testing/selftests/alsa/conf.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/alsa/conf.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/alsa/conf.c- Extension
.c- Size
- 11539 bytes
- Lines
- 476
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- Inferred role
- Support Tooling And Documentation: implementation source
- Status
- source implementation candidate
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
stdio.hstdlib.hstdbool.herrno.hassert.hdirent.hregex.hsys/stat.hkselftest.halsa-local.h
Detected Declarations
function snd_config_load_stringfunction dump_config_treefunction sysfs_matchfunction snd_config_for_eachfunction assign_card_configfunction assign_card_configsfunction filename_filterfunction match_configfunction conf_loadfunction conf_freefunction conf_get_by_keysfunction conf_get_countfunction conf_get_longfunction conf_get_boolfunction conf_get_string_array
Annotated Snippet
if (conf->card == card) {
if (msg)
ksft_print_msg("using hw card config %s for card %d\n",
conf->filename, card);
return conf;
}
}
return NULL;
}
static void dump_config_tree(snd_config_t *top)
{
snd_output_t *out;
int err;
err = snd_output_stdio_attach(&out, stdout, 0);
if (err < 0)
ksft_exit_fail_msg("stdout attach\n");
if (snd_config_save(top, out))
ksft_exit_fail_msg("config save\n");
snd_output_close(out);
}
snd_config_t *conf_load_from_file(const char *filename)
{
snd_config_t *dst;
snd_input_t *input;
int err;
err = snd_input_stdio_open(&input, filename, "r");
if (err < 0)
ksft_exit_fail_msg("Unable to parse filename %s\n", filename);
err = snd_config_top(&dst);
if (err < 0)
ksft_exit_fail_msg("Out of memory\n");
err = snd_config_load(dst, input);
snd_input_close(input);
if (err < 0)
ksft_exit_fail_msg("Unable to parse filename %s\n", filename);
return dst;
}
static char *sysfs_get(const char *sysfs_root, const char *id)
{
char path[PATH_MAX], link[PATH_MAX + 1];
struct stat sb;
ssize_t len;
char *e;
int fd;
if (id[0] == '/')
id++;
snprintf(path, sizeof(path), "%s/%s", sysfs_root, id);
if (lstat(path, &sb) != 0)
return NULL;
if (S_ISLNK(sb.st_mode)) {
len = readlink(path, link, sizeof(link) - 1);
if (len <= 0) {
ksft_exit_fail_msg("sysfs: cannot read link '%s': %s\n",
path, strerror(errno));
return NULL;
}
link[len] = '\0';
e = strrchr(link, '/');
if (e)
return strdup(e + 1);
return NULL;
}
if (S_ISDIR(sb.st_mode))
return NULL;
if ((sb.st_mode & S_IRUSR) == 0)
return NULL;
fd = open(path, O_RDONLY);
if (fd < 0) {
if (errno == ENOENT)
return NULL;
ksft_exit_fail_msg("sysfs: open failed for '%s': %s\n",
path, strerror(errno));
}
len = read(fd, path, sizeof(path)-1);
close(fd);
if (len < 0)
ksft_exit_fail_msg("sysfs: unable to read value '%s': %s\n",
path, strerror(errno));
while (len > 0 && path[len-1] == '\n')
len--;
path[len] = '\0';
e = strdup(path);
if (e == NULL)
Annotation
- Immediate include surface: `stdio.h`, `stdlib.h`, `stdbool.h`, `errno.h`, `assert.h`, `dirent.h`, `regex.h`, `sys/stat.h`.
- Detected declarations: `function snd_config_load_string`, `function dump_config_tree`, `function sysfs_match`, `function snd_config_for_each`, `function assign_card_config`, `function assign_card_configs`, `function filename_filter`, `function match_config`, `function conf_load`, `function conf_free`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source 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.