drivers/usb/gadget/function/f_uac1_legacy.c
Source file repositories/reference/linux-study-clean/drivers/usb/gadget/function/f_uac1_legacy.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/usb/gadget/function/f_uac1_legacy.c- Extension
.c- Size
- 27301 bytes
- Lines
- 1047
- Domain
- Driver Families
- Bucket
- drivers/usb
- 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.
- 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/slab.hlinux/kernel.hlinux/module.hlinux/device.hlinux/atomic.hu_uac1_legacy.h
Detected Declarations
struct f_audio_bufstruct f_audiofunction f_audio_buffer_freefunction f_audio_playback_workfunction f_audio_out_ep_completefunction f_audio_completefunction audio_set_intf_reqfunction list_for_each_entryfunction audio_get_intf_reqfunction list_for_each_entryfunction audio_set_endpoint_reqfunction audio_get_endpoint_reqfunction f_audio_setupfunction set_altfunction f_audio_set_altfunction f_audio_get_altfunction f_audio_disablefunction f_audio_build_descfunction f_audio_bindfunction generic_set_cmdfunction generic_get_cmdfunction control_selector_initfunction f_uac1_attr_releasefunction f_audio_free_instfunction f_audio_freefunction f_audio_unbind
Annotated Snippet
struct f_audio_buf {
u8 *buf;
int actual;
struct list_head list;
};
static struct f_audio_buf *f_audio_buffer_alloc(int buf_size)
{
struct f_audio_buf *copy_buf;
copy_buf = kzalloc_obj(*copy_buf, GFP_ATOMIC);
if (!copy_buf)
return ERR_PTR(-ENOMEM);
copy_buf->buf = kzalloc(buf_size, GFP_ATOMIC);
if (!copy_buf->buf) {
kfree(copy_buf);
return ERR_PTR(-ENOMEM);
}
return copy_buf;
}
static void f_audio_buffer_free(struct f_audio_buf *audio_buf)
{
kfree(audio_buf->buf);
kfree(audio_buf);
}
/*-------------------------------------------------------------------------*/
struct f_audio {
struct gaudio card;
u8 ac_intf, ac_alt;
u8 as_intf, as_alt;
/* endpoints handle full and/or high speeds */
struct usb_ep *out_ep;
spinlock_t lock;
struct f_audio_buf *copy_buf;
struct work_struct playback_work;
struct list_head play_queue;
/* Control Set command */
struct list_head cs;
u8 set_cmd;
struct usb_audio_control *set_con;
};
static inline struct f_audio *func_to_audio(struct usb_function *f)
{
return container_of(f, struct f_audio, card.func);
}
/*-------------------------------------------------------------------------*/
static void f_audio_playback_work(struct work_struct *data)
{
struct f_audio *audio = container_of(data, struct f_audio,
playback_work);
struct f_audio_buf *play_buf;
spin_lock_irq(&audio->lock);
if (list_empty(&audio->play_queue)) {
spin_unlock_irq(&audio->lock);
return;
}
play_buf = list_first_entry(&audio->play_queue,
struct f_audio_buf, list);
list_del(&play_buf->list);
spin_unlock_irq(&audio->lock);
u_audio_playback(&audio->card, play_buf->buf, play_buf->actual);
f_audio_buffer_free(play_buf);
}
static int f_audio_out_ep_complete(struct usb_ep *ep, struct usb_request *req)
{
struct f_audio *audio = req->context;
struct usb_composite_dev *cdev = audio->card.func.config->cdev;
struct f_audio_buf *copy_buf = audio->copy_buf;
struct f_uac1_legacy_opts *opts;
int audio_buf_size;
int err;
opts = container_of(audio->card.func.fi, struct f_uac1_legacy_opts,
func_inst);
audio_buf_size = opts->audio_buf_size;
Annotation
- Immediate include surface: `linux/slab.h`, `linux/kernel.h`, `linux/module.h`, `linux/device.h`, `linux/atomic.h`, `u_uac1_legacy.h`.
- Detected declarations: `struct f_audio_buf`, `struct f_audio`, `function f_audio_buffer_free`, `function f_audio_playback_work`, `function f_audio_out_ep_complete`, `function f_audio_complete`, `function audio_set_intf_req`, `function list_for_each_entry`, `function audio_get_intf_req`, `function list_for_each_entry`.
- Atlas domain: Driver Families / drivers/usb.
- Implementation status: source implementation candidate.
- 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.