drivers/char/ppdev.c
Source file repositories/reference/linux-study-clean/drivers/char/ppdev.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/char/ppdev.c- Extension
.c- Size
- 20825 bytes
- Lines
- 886
- Domain
- Driver Families
- Bucket
- drivers/char
- 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/init.hlinux/sched/signal.hlinux/device.hlinux/ioctl.hlinux/parport.hlinux/ctype.hlinux/poll.hlinux/slab.hlinux/major.hlinux/ppdev.hlinux/mutex.hlinux/uaccess.hlinux/compat.h
Detected Declarations
struct pp_structfunction pp_enable_irqfunction pp_readfunction pp_writefunction pp_irqfunction register_devicefunction init_phasefunction pp_set_timeoutfunction pp_do_ioctlfunction pp_ioctlfunction pp_openfunction pp_releasefunction pp_pollfunction pp_attachfunction pp_detachfunction pp_probefunction ppdev_initfunction ppdev_cleanupmodule init ppdev_init
Annotated Snippet
static const struct file_operations pp_fops = {
.owner = THIS_MODULE,
.read = pp_read,
.write = pp_write,
.poll = pp_poll,
.unlocked_ioctl = pp_ioctl,
.compat_ioctl = compat_ptr_ioctl,
.open = pp_open,
.release = pp_release,
};
static void pp_attach(struct parport *port)
{
struct device *ret;
if (devices[port->number])
return;
ret = device_create(&ppdev_class, port->dev,
MKDEV(PP_MAJOR, port->number), NULL,
"parport%d", port->number);
if (IS_ERR(ret)) {
pr_err("Failed to create device parport%d\n",
port->number);
return;
}
devices[port->number] = ret;
}
static void pp_detach(struct parport *port)
{
if (!devices[port->number])
return;
device_destroy(&ppdev_class, MKDEV(PP_MAJOR, port->number));
devices[port->number] = NULL;
}
static int pp_probe(struct pardevice *par_dev)
{
struct device_driver *drv = par_dev->dev.driver;
int len = strlen(drv->name);
if (strncmp(par_dev->name, drv->name, len))
return -ENODEV;
return 0;
}
static struct parport_driver pp_driver = {
.name = CHRDEV,
.probe = pp_probe,
.match_port = pp_attach,
.detach = pp_detach,
};
static int __init ppdev_init(void)
{
int err = 0;
if (register_chrdev(PP_MAJOR, CHRDEV, &pp_fops)) {
pr_warn(CHRDEV ": unable to get major %d\n", PP_MAJOR);
return -EIO;
}
err = class_register(&ppdev_class);
if (err)
goto out_chrdev;
err = parport_register_driver(&pp_driver);
if (err < 0) {
pr_warn(CHRDEV ": unable to register with parport\n");
goto out_class;
}
pr_info(PP_VERSION "\n");
goto out;
out_class:
class_unregister(&ppdev_class);
out_chrdev:
unregister_chrdev(PP_MAJOR, CHRDEV);
out:
return err;
}
static void __exit ppdev_cleanup(void)
{
/* Clean up all parport stuff */
parport_unregister_driver(&pp_driver);
class_unregister(&ppdev_class);
Annotation
- Immediate include surface: `linux/module.h`, `linux/init.h`, `linux/sched/signal.h`, `linux/device.h`, `linux/ioctl.h`, `linux/parport.h`, `linux/ctype.h`, `linux/poll.h`.
- Detected declarations: `struct pp_struct`, `function pp_enable_irq`, `function pp_read`, `function pp_write`, `function pp_irq`, `function register_device`, `function init_phase`, `function pp_set_timeout`, `function pp_do_ioctl`, `function pp_ioctl`.
- Atlas domain: Driver Families / drivers/char.
- 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.