drivers/gpib/lpvo_usb_gpib/lpvo_usb_gpib.c
Source file repositories/reference/linux-study-clean/drivers/gpib/lpvo_usb_gpib/lpvo_usb_gpib.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/gpib/lpvo_usb_gpib/lpvo_usb_gpib.c- Extension
.c- Size
- 50290 bytes
- Lines
- 2023
- Domain
- Driver Families
- Bucket
- drivers/gpib
- 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/module.hlinux/sched.hlinux/init.hlinux/kernel.hlinux/tty.hlinux/types.hlinux/slab.hlinux/mm.hlinux/vmalloc.hlinux/spinlock.hlinux/file.hlinux/timer.hlinux/delay.hlinux/sched/signal.hlinux/usb.hgpibP.hlinux/errno.hlinux/kref.hlinux/uaccess.hlinux/mutex.h
Detected Declarations
struct char_bufstruct usb_gpib_privstruct lpvostruct lpvofunction show_statusfunction usec_difffunction write_loopfunction send_commandfunction set_control_linefunction one_charfunction set_timeoutfunction usb_gpib_attachfunction usb_gpib_detachfunction usb_gpib_commandfunction usb_gpib_disable_eosfunction usb_gpib_enable_eosfunction usb_gpib_go_to_standbyfunction usb_gpib_interface_clearfunction usb_gpib_line_statusfunction usb_gpib_parallel_pollfunction usb_gpib_readfunction usb_gpib_remote_enablefunction usb_gpib_request_system_controlfunction usb_gpib_take_controlfunction usb_gpib_update_statusfunction usb_gpib_writefunction usb_gpib_parallel_poll_configurefunction usb_gpib_return_to_localfunction usb_gpib_serial_poll_responsefunction usb_gpib_t1_delayfunction usb_gpib_init_modulefunction usb_gpib_exit_modulefunction write_latency_timerfunction lpvo_deletefunction lpvo_do_openfunction lpvo_do_releasefunction lpvo_read_bulk_callbackfunction lpvo_do_read_iofunction lpvo_do_readfunction lpvo_write_bulk_callbackfunction lpvo_do_writefunction lpvo_flushfunction lpvo_openfunction lpvo_releasefunction lpvo_readfunction lpvo_writefunction lpvo_probefunction lpvo_disconnect
Annotated Snippet
static const struct file_operations lpvo_fops = {
.owner = THIS_MODULE,
#if USER_DEVICE
.read = lpvo_read,
.write = lpvo_write,
.open = lpvo_open,
.release = lpvo_release,
.flush = lpvo_flush,
.llseek = noop_llseek,
#endif
};
/*
* usb class driver info in order to get a minor number from the usb core,
* and to have the device registered with the driver core
*/
#if USER_DEVICE
static struct usb_class_driver lpvo_class = {
.name = "lpvo_raw%d",
.fops = &lpvo_fops,
.minor_base = USB_LPVO_MINOR_BASE,
};
#endif
static int lpvo_probe(struct usb_interface *interface,
const struct usb_device_id *id)
{
struct lpvo *dev;
struct usb_endpoint_descriptor *bulk_in, *bulk_out;
int retval;
char *device_path;
mutex_init(&minors_lock); /* required for handling minor numbers table */
/* allocate memory for our device state and initialize it */
dev = kzalloc_obj(*dev);
if (!dev)
return -ENOMEM;
kref_init(&dev->kref);
sema_init(&dev->limit_sem, WRITES_IN_FLIGHT);
mutex_init(&dev->io_mutex);
spin_lock_init(&dev->err_lock);
init_usb_anchor(&dev->submitted);
init_waitqueue_head(&dev->bulk_in_wait);
dev->udev = usb_get_dev(interface_to_usbdev(interface));
dev->interface = interface;
/* set up the endpoint information */
/* use only the first bulk-in and bulk-out endpoints */
retval = usb_find_common_endpoints(interface->cur_altsetting,
&bulk_in, &bulk_out, NULL, NULL);
if (retval) {
dev_err(&interface->dev,
"Could not find both bulk-in and bulk-out endpoints\n");
goto error;
}
dev->bulk_in_size = usb_endpoint_maxp(bulk_in);
dev->bulk_in_endpoint_addr = bulk_in->bEndpointAddress;
dev->bulk_in_buffer = kmalloc(dev->bulk_in_size, GFP_KERNEL);
if (!dev->bulk_in_buffer) {
retval = -ENOMEM;
goto error;
}
dev->bulk_in_urb = usb_alloc_urb(0, GFP_KERNEL);
if (!dev->bulk_in_urb) {
retval = -ENOMEM;
goto error;
}
dev->bulk_out_endpoint_addr = bulk_out->bEndpointAddress;
/* save our data pointer in this interface device */
usb_set_intfdata(interface, dev);
/* let the world know */
device_path = kobject_get_path(&dev->udev->dev.kobj, GFP_KERNEL);
dev_dbg(&interface->dev, "New lpvo_usb_device -> bus: %d dev: %d path: %s\n",
dev->udev->bus->busnum, dev->udev->devnum, device_path);
kfree(device_path);
#if USER_DEVICE
/* we can register the device now, as it is ready */
retval = usb_register_dev(interface, &lpvo_class);
if (retval) {
/* something prevented us from registering this driver */
dev_err(&interface->dev,
Annotation
- Immediate include surface: `linux/module.h`, `linux/sched.h`, `linux/init.h`, `linux/kernel.h`, `linux/tty.h`, `linux/types.h`, `linux/slab.h`, `linux/mm.h`.
- Detected declarations: `struct char_buf`, `struct usb_gpib_priv`, `struct lpvo`, `struct lpvo`, `function show_status`, `function usec_diff`, `function write_loop`, `function send_command`, `function set_control_line`, `function one_char`.
- Atlas domain: Driver Families / drivers/gpib.
- 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.