drivers/usb/class/cdc-wdm.c
Source file repositories/reference/linux-study-clean/drivers/usb/class/cdc-wdm.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/usb/class/cdc-wdm.c- Extension
.c- Size
- 33884 bytes
- Lines
- 1381
- Domain
- Driver Families
- Bucket
- drivers/usb
- Inferred role
- Driver Families: operation-table or driver-model contract
- Status
- pattern 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.
- Defines an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- 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/kernel.hlinux/errno.hlinux/ioctl.hlinux/slab.hlinux/module.hlinux/mutex.hlinux/uaccess.hlinux/bitops.hlinux/poll.hlinux/skbuff.hlinux/usb.hlinux/usb/cdc.hlinux/wwan.hasm/byteorder.hlinux/unaligned.hlinux/usb/cdc-wdm.h
Detected Declarations
struct wdm_devicefunction wdm_out_callbackfunction wdm_in_callbackfunction wdm_int_callbackfunction poison_urbsfunction unpoison_urbsfunction free_urbsfunction cleanupfunction wdm_writefunction service_outstanding_interruptfunction wdm_readfunction wdm_wait_for_responsefunction wdm_flushfunction wdm_fsyncfunction wdm_pollfunction wdm_openfunction wdm_releasefunction wdm_ioctlfunction wdm_wwan_port_startfunction wdm_wwan_port_stopfunction wdm_wwan_port_tx_completefunction wdm_wwan_port_txfunction wdm_wwan_initfunction wdm_wwan_deinitfunction wdm_wwan_rxfunction wdm_wwan_initfunction service_interrupt_workfunction wdm_createfunction wdm_manage_powerfunction wdm_probefunction intfunction wdm_disconnectfunction wdm_suspendfunction recover_from_urb_lossfunction wdm_resumefunction wdm_pre_resetfunction wdm_post_resetexport usb_cdc_wdm_register
Annotated Snippet
static const struct file_operations wdm_fops = {
.owner = THIS_MODULE,
.read = wdm_read,
.write = wdm_write,
.fsync = wdm_fsync,
.open = wdm_open,
.flush = wdm_flush,
.release = wdm_release,
.poll = wdm_poll,
.unlocked_ioctl = wdm_ioctl,
.compat_ioctl = compat_ptr_ioctl,
.llseek = noop_llseek,
};
static struct usb_class_driver wdm_class = {
.name = "cdc-wdm%d",
.fops = &wdm_fops,
.minor_base = WDM_MINOR_BASE,
};
/* --- WWAN framework integration --- */
#ifdef CONFIG_WWAN
static int wdm_wwan_port_start(struct wwan_port *port)
{
struct wdm_device *desc = wwan_port_get_drvdata(port);
int rv;
/* The interface is both exposed via the WWAN framework and as a
* legacy usbmisc chardev. If chardev is already open, just fail
* to prevent concurrent usage. Otherwise, switch to WWAN mode.
*/
mutex_lock(&wdm_mutex);
if (desc->count) {
mutex_unlock(&wdm_mutex);
return -EBUSY;
}
set_bit(WDM_WWAN_IN_USE, &desc->flags);
mutex_unlock(&wdm_mutex);
desc->manage_power(desc->intf, 1);
/* tx is allowed */
wwan_port_txon(port);
/* Start getting events */
rv = usb_submit_urb(desc->validity, GFP_KERNEL);
if (rv < 0) {
wwan_port_txoff(port);
desc->manage_power(desc->intf, 0);
/* this must be last lest we race with chardev open */
clear_bit(WDM_WWAN_IN_USE, &desc->flags);
}
return rv;
}
static void wdm_wwan_port_stop(struct wwan_port *port)
{
struct wdm_device *desc = wwan_port_get_drvdata(port);
/* Stop all transfers and disable WWAN mode */
poison_urbs(desc);
desc->manage_power(desc->intf, 0);
clear_bit(WDM_READ, &desc->flags);
unpoison_urbs(desc);
smp_wmb(); /* ordered against wdm_open() */
/* this must be last lest we open a poisoned device */
clear_bit(WDM_WWAN_IN_USE, &desc->flags);
}
static void wdm_wwan_port_tx_complete(struct urb *urb)
{
struct sk_buff *skb = urb->context;
struct wdm_device *desc = skb_shinfo(skb)->destructor_arg;
usb_autopm_put_interface_async(desc->intf);
wwan_port_txon(desc->wwanp);
kfree_skb(skb);
}
static int wdm_wwan_port_tx(struct wwan_port *port, struct sk_buff *skb)
{
struct wdm_device *desc = wwan_port_get_drvdata(port);
struct usb_interface *intf = desc->intf;
struct usb_ctrlrequest *req = desc->orq;
int rv;
rv = usb_autopm_get_interface(intf);
if (rv)
return rv;
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/errno.h`, `linux/ioctl.h`, `linux/slab.h`, `linux/module.h`, `linux/mutex.h`, `linux/uaccess.h`, `linux/bitops.h`.
- Detected declarations: `struct wdm_device`, `function wdm_out_callback`, `function wdm_in_callback`, `function wdm_int_callback`, `function poison_urbs`, `function unpoison_urbs`, `function free_urbs`, `function cleanup`, `function wdm_write`, `function service_outstanding_interrupt`.
- Atlas domain: Driver Families / drivers/usb.
- Implementation status: pattern implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
- 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.