sound/hda/common/hwdep.c
Source file repositories/reference/linux-study-clean/sound/hda/common/hwdep.c
File Facts
- System
- Linux kernel
- Corpus path
sound/hda/common/hwdep.c- Extension
.c- Size
- 2769 bytes
- Lines
- 120
- Domain
- Driver Families
- Bucket
- sound/hda
- Inferred role
- Driver Families: implementation source
- Status
- source 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.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/init.hlinux/slab.hlinux/compat.hlinux/nospec.hsound/core.hsound/hda_codec.hhda_local.hsound/hda_hwdep.hsound/minors.h
Detected Declarations
function Copyrightfunction get_wcap_ioctlfunction hda_hwdep_ioctlfunction hda_hwdep_ioctl_compatfunction hda_hwdep_openfunction snd_hda_create_hwdep
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* HWDEP Interface for HD-audio codec
*
* Copyright (c) 2007 Takashi Iwai <tiwai@suse.de>
*/
#include <linux/init.h>
#include <linux/slab.h>
#include <linux/compat.h>
#include <linux/nospec.h>
#include <sound/core.h>
#include <sound/hda_codec.h>
#include "hda_local.h"
#include <sound/hda_hwdep.h>
#include <sound/minors.h>
/*
* write/read an out-of-bound verb
*/
static int verb_write_ioctl(struct hda_codec *codec,
struct hda_verb_ioctl __user *arg)
{
u32 verb, res;
if (get_user(verb, &arg->verb))
return -EFAULT;
res = snd_hda_codec_read(codec, verb >> 24, 0,
(verb >> 8) & 0xffff, verb & 0xff);
if (put_user(res, &arg->res))
return -EFAULT;
return 0;
}
static int get_wcap_ioctl(struct hda_codec *codec,
struct hda_verb_ioctl __user *arg)
{
u32 verb, res;
if (get_user(verb, &arg->verb))
return -EFAULT;
/* open-code get_wcaps(verb>>24) with nospec */
verb >>= 24;
if (verb < codec->core.start_nid ||
verb >= codec->core.start_nid + codec->core.num_nodes) {
res = 0;
} else {
verb -= codec->core.start_nid;
verb = array_index_nospec(verb, codec->core.num_nodes);
res = codec->wcaps[verb];
}
if (put_user(res, &arg->res))
return -EFAULT;
return 0;
}
/*
*/
static int hda_hwdep_ioctl(struct snd_hwdep *hw, struct file *file,
unsigned int cmd, unsigned long arg)
{
struct hda_codec *codec = hw->private_data;
void __user *argp = (void __user *)arg;
switch (cmd) {
case HDA_IOCTL_PVERSION:
return put_user(HDA_HWDEP_VERSION, (int __user *)argp);
case HDA_IOCTL_VERB_WRITE:
return verb_write_ioctl(codec, argp);
case HDA_IOCTL_GET_WCAP:
return get_wcap_ioctl(codec, argp);
}
return -ENOIOCTLCMD;
}
#ifdef CONFIG_COMPAT
static int hda_hwdep_ioctl_compat(struct snd_hwdep *hw, struct file *file,
unsigned int cmd, unsigned long arg)
{
return hda_hwdep_ioctl(hw, file, cmd, (unsigned long)compat_ptr(arg));
}
#endif
static int hda_hwdep_open(struct snd_hwdep *hw, struct file *file)
{
if (!capable(CAP_SYS_RAWIO))
return -EACCES;
return 0;
}
Annotation
- Immediate include surface: `linux/init.h`, `linux/slab.h`, `linux/compat.h`, `linux/nospec.h`, `sound/core.h`, `sound/hda_codec.h`, `hda_local.h`, `sound/hda_hwdep.h`.
- Detected declarations: `function Copyright`, `function get_wcap_ioctl`, `function hda_hwdep_ioctl`, `function hda_hwdep_ioctl_compat`, `function hda_hwdep_open`, `function snd_hda_create_hwdep`.
- Atlas domain: Driver Families / sound/hda.
- Implementation status: source 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.