sound/usb/helper.c
Source file repositories/reference/linux-study-clean/sound/usb/helper.c
File Facts
- System
- Linux kernel
- Corpus path
sound/usb/helper.c- Extension
.c- Size
- 3770 bytes
- Lines
- 168
- Domain
- Driver Families
- Bucket
- sound/usb
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/init.hlinux/slab.hlinux/usb.husbaudio.hhelper.hquirks.h
Detected Declarations
function snd_usb_combine_bytesfunction usb_control_msgfunction snd_usb_parse_dataintervalfunction snd_usb_get_host_interfacefunction snd_usb_add_ctrl_interface_linkexport snd_usb_find_csint_desc
Annotated Snippet
if (p[1] == dtype && (!after || (void *)p > after)) {
return p;
}
p = next;
}
return NULL;
}
/*
* find a class-specified interface descriptor with the given subtype.
*/
void *snd_usb_find_csint_desc(void *buffer, int buflen, void *after, u8 dsubtype)
{
unsigned char *p = after;
while ((p = snd_usb_find_desc(buffer, buflen, p,
USB_DT_CS_INTERFACE)) != NULL) {
if (p[0] >= 3 && p[2] == dsubtype)
return p;
}
return NULL;
}
EXPORT_SYMBOL_GPL(snd_usb_find_csint_desc);
/*
* Wrapper for usb_control_msg().
* Allocates a temp buffer to prevent dmaing from/to the stack.
*/
int snd_usb_ctl_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
__u8 requesttype, __u16 value, __u16 index, void *data,
__u16 size)
{
int err;
void *buf = NULL;
int timeout;
if (usb_pipe_type_check(dev, pipe))
return -EINVAL;
if (size > 0) {
buf = kmemdup(data, size, GFP_KERNEL);
if (!buf)
return -ENOMEM;
}
if (requesttype & USB_DIR_IN)
timeout = USB_CTRL_GET_TIMEOUT;
else
timeout = USB_CTRL_SET_TIMEOUT;
err = usb_control_msg(dev, pipe, request, requesttype,
value, index, buf, size, timeout);
if (size > 0) {
memcpy(data, buf, size);
kfree(buf);
}
snd_usb_ctl_msg_quirk(dev, pipe, request, requesttype,
value, index, data, size);
return err;
}
unsigned char snd_usb_parse_datainterval(struct snd_usb_audio *chip,
struct usb_host_interface *alts)
{
switch (snd_usb_get_speed(chip->dev)) {
case USB_SPEED_HIGH:
case USB_SPEED_SUPER:
case USB_SPEED_SUPER_PLUS:
if (get_endpoint(alts, 0)->bInterval >= 1 &&
get_endpoint(alts, 0)->bInterval <= 4)
return get_endpoint(alts, 0)->bInterval - 1;
break;
default:
break;
}
return 0;
}
struct usb_host_interface *
snd_usb_get_host_interface(struct snd_usb_audio *chip, int ifnum, int altsetting)
{
struct usb_interface *iface;
iface = usb_ifnum_to_if(chip->dev, ifnum);
if (!iface)
return NULL;
return usb_altnum_to_altsetting(iface, altsetting);
Annotation
- Immediate include surface: `linux/init.h`, `linux/slab.h`, `linux/usb.h`, `usbaudio.h`, `helper.h`, `quirks.h`.
- Detected declarations: `function snd_usb_combine_bytes`, `function usb_control_msg`, `function snd_usb_parse_datainterval`, `function snd_usb_get_host_interface`, `function snd_usb_add_ctrl_interface_link`, `export snd_usb_find_csint_desc`.
- Atlas domain: Driver Families / sound/usb.
- 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.