drivers/char/xillybus/xillybus_class.c
Source file repositories/reference/linux-study-clean/drivers/char/xillybus/xillybus_class.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/char/xillybus/xillybus_class.c- Extension
.c- Size
- 5397 bytes
- Lines
- 257
- 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.
- 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/types.hlinux/module.hlinux/device.hlinux/fs.hlinux/cdev.hlinux/slab.hlinux/list.hlinux/mutex.hxillybus_class.h
Detected Declarations
struct xilly_unitfunction xillybus_init_chrdevfunction list_for_each_entryfunction xillybus_cleanup_chrdevfunction list_for_each_entryfunction xillybus_find_inodefunction list_for_each_entryfunction xillybus_class_initfunction xillybus_class_exitmodule init xillybus_class_initexport xillybus_init_chrdevexport xillybus_cleanup_chrdevexport xillybus_find_inode
Annotated Snippet
const struct file_operations *fops,
struct module *owner,
void *private_data,
unsigned char *idt, unsigned int len,
int num_nodes,
const char *prefix, bool enumerate)
{
int rc;
dev_t mdev;
int i;
char devname[48];
struct device *device;
size_t namelen;
struct xilly_unit *unit, *u;
unit = kzalloc_obj(*unit);
if (!unit)
return -ENOMEM;
mutex_lock(&unit_mutex);
if (!enumerate)
snprintf(unit->name, UNITNAMELEN, "%s", prefix);
for (i = 0; enumerate; i++) {
snprintf(unit->name, UNITNAMELEN, "%s_%02d",
prefix, i);
enumerate = false;
list_for_each_entry(u, &unit_list, list_entry)
if (!strcmp(unit->name, u->name)) {
enumerate = true;
break;
}
}
rc = alloc_chrdev_region(&mdev, 0, num_nodes, unit->name);
if (rc) {
dev_warn(dev, "Failed to obtain major/minors");
goto fail_obtain;
}
unit->major = MAJOR(mdev);
unit->lowest_minor = MINOR(mdev);
unit->num_nodes = num_nodes;
unit->private_data = private_data;
unit->cdev = cdev_alloc();
if (!unit->cdev) {
rc = -ENOMEM;
goto unregister_chrdev;
}
unit->cdev->ops = fops;
unit->cdev->owner = owner;
rc = cdev_add(unit->cdev, MKDEV(unit->major, unit->lowest_minor),
unit->num_nodes);
if (rc) {
dev_err(dev, "Failed to add cdev.\n");
/* kobject_put() is normally done by cdev_del() */
kobject_put(&unit->cdev->kobj);
goto unregister_chrdev;
}
for (i = 0; i < num_nodes; i++) {
namelen = strnlen(idt, len);
if (namelen == len) {
dev_err(dev, "IDT's list of names is too short. This is exceptionally weird, because its CRC is OK\n");
rc = -ENODEV;
goto unroll_device_create;
}
snprintf(devname, sizeof(devname), "%s_%s",
unit->name, idt);
len -= namelen + 1;
idt += namelen + 1;
device = device_create(&xillybus_class,
NULL,
MKDEV(unit->major,
i + unit->lowest_minor),
NULL,
"%s", devname);
if (IS_ERR(device)) {
Annotation
- Immediate include surface: `linux/types.h`, `linux/module.h`, `linux/device.h`, `linux/fs.h`, `linux/cdev.h`, `linux/slab.h`, `linux/list.h`, `linux/mutex.h`.
- Detected declarations: `struct xilly_unit`, `function xillybus_init_chrdev`, `function list_for_each_entry`, `function xillybus_cleanup_chrdev`, `function list_for_each_entry`, `function xillybus_find_inode`, `function list_for_each_entry`, `function xillybus_class_init`, `function xillybus_class_exit`, `module init xillybus_class_init`.
- Atlas domain: Driver Families / drivers/char.
- Implementation status: pattern 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.